diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index 73f86f3ff3fda95d6707a5d4e05e6255e92a5af2..33a526fec54283e8e6c1884b1e1da7570ee1f29d 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -188,6 +188,7 @@ typedef struct SFilterInfo { #define FILTER_GET_FIELD(i, id) (&((i)->fields[(id).type].fields[(id).idx])) #define FILTER_GET_COL_FIELD(i, idx) (&((i)->fields[FLD_TYPE_COLUMN].fields[idx])) #define FILTER_GET_COL_FIELD_TYPE(fi) (((SSchema *)((fi)->desc))->type) +#define FILTER_GET_COL_FIELD_SIZE(fi) (((SSchema *)((fi)->desc))->bytes) #define FILTER_GET_COL_FIELD_DESC(fi) ((SSchema *)((fi)->desc)) #define FILTER_GET_COL_FIELD_DATA(fi, ri) ((fi)->data + ((SSchema *)((fi)->desc))->bytes * (ri)) #define FILTER_GET_VAL_FIELD_TYPE(fi) (((tVariant *)((fi)->desc))->nType) diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 8c55b7fd94805bc5b584178ce6c1490b619a459e..8f1530551c513e41347b01e81569704d89406426 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -1815,7 +1815,31 @@ _err_return: } -int32_t filterConverNcharColumns(SFilterInfo* pFilterInfo, int32_t rows, bool *gotNchar) { +int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar) { + for (uint16_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { + SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; + int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); + if (type == TSDB_DATA_TYPE_NCHAR) { + SFilterField nfi = {0}; + nfi.desc = fi->desc; + int32_t bytes = FILTER_GET_COL_FIELD_SIZE(fi); + nfi.data = malloc(rows * bytes); + int32_t bufSize = bytes - VARSTR_HEADER_SIZE; + for (int32_t j = 0; j < rows; ++j) { + char *src = FILTER_GET_COL_FIELD_DATA(fi, j); + char *dst = FILTER_GET_COL_FIELD_DATA(&nfi, j); + int32_t len = 0; + taosMbsToUcs4(varDataVal(src), varDataLen(src), varDataVal(dst), bufSize, &len); + varDataLen(dst) = len; + } + + fi->data = nfi.data; + + *gotNchar = true; + } + } + + #if 0 for (int32_t i = 0; i < numOfFilterCols; ++i) { if (pFilterInfo[i].info.type == TSDB_DATA_TYPE_NCHAR) { @@ -1837,7 +1861,7 @@ int32_t filterConverNcharColumns(SFilterInfo* pFilterInfo, int32_t rows, bool *g return TSDB_CODE_SUCCESS; } -int32_t filterFreeNcharColumns(SFilterInfo* pFilterInfo) { +int32_t filterFreeNcharColumns(SFilterInfo* info) { #if 0 for (int32_t i = 0; i < numOfFilterCols; ++i) { if (pFilterInfo[i].info.type == TSDB_DATA_TYPE_NCHAR) { @@ -1850,6 +1874,15 @@ int32_t filterFreeNcharColumns(SFilterInfo* pFilterInfo) { } #endif + for (uint16_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { + SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; + int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); + if (type == TSDB_DATA_TYPE_NCHAR) { + tfree(fi->data); + } + } + + return TSDB_CODE_SUCCESS; } diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index 54e64c01dce3906fb7856bd12ba00118dbabf942..d414cb15540e287cff3be4d67c1a52902eb6d4e6 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -1200,6 +1200,31 @@ sql select * from stb1 where c1 is null and c2 is null and ts > '2021-05-05 18:1 if $rows != 0 then return -1 endi + +sql select * from stb1 where c1 is null and c1 > 0; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c1 is null or c1 is not null or c1 > 1; +if $rows != 29 then + return -1 +endi + +sql select * from stb1 where (c1 is null or c1 > 40) and c1 < 44; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:16.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:17.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:18.000@ then + return -1 +endi + sql select * from stb1 where c1 = 3 or c1 = 5 or c1 >= 44 and c1 <= 52; if $rows != 4 then return -1 @@ -1738,6 +1763,20 @@ if $data20 != @21-05-05 18:19:03.000@ then return -1 endi +sql select * from (select * from stb1 where c2 > 10 and c6 < 40) where c9 in ('11','21','31'); +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:12.000@ then + return -1 +endi + print "ts test" sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27' @@ -2036,6 +2075,26 @@ if $data50 != @21-05-05 18:19:14.000@ then return -1 endi +sql select ts,c1,c2,c8 from (select * from stb1) where (ts <= '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:26.000' or ts = '2021-05-05 18:19:26.000') and ts != '2021-05-05 18:19:03.000' and ts != '2021-05-05 18:19:26.000'; +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:28.000@ then + return -1 +endi + print "tbname test" sql_error select * from stb1 where tbname like '%3' and tbname like '%4';