From f49b48791ca1b1cced201b073d0012429f714c3c Mon Sep 17 00:00:00 2001 From: wpan Date: Tue, 14 Sep 2021 18:19:13 +0800 Subject: [PATCH] fix case issues --- src/kit/shell/src/shellEngine.c | 2 +- src/query/src/qFilter.c | 40 ++++++------------- tests/pytest/query/filterOtherTypes.py | 24 +++++++---- tests/script/general/parser/between_and.sim | 4 +- .../general/parser/condition_query2.sim | 26 ++++++++++++ .../script/general/parser/tbnameIn_query.sim | 9 ++--- 6 files changed, 61 insertions(+), 44 deletions(-) diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index efc37403b4..4dfe424b11 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -569,7 +569,7 @@ static void shellPrintNChar(const char *str, int length, int width) { while (pos < length) { wchar_t wc; int bytes = mbtowc(&wc, str + pos, MB_CUR_MAX); - if (bytes == 0) { + if (bytes <= 0) { break; } pos += bytes; diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 2737fdf250..4f2543030b 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -937,7 +937,7 @@ int32_t filterAddUnitToGroup(SFilterGroup *group, uint16_t unitIdx) { return TSDB_CODE_SUCCESS; } -int32_t filterConvertSetFromBinary(void **q, const char *buf, int32_t len, uint32_t tType) { +int32_t filterConvertSetFromBinary(void **q, const char *buf, int32_t len, uint32_t tType, bool tolower) { SBufferReader br = tbufInitReader(buf, len, false); uint32_t sType = tbufReadUint32(&br); SHashObj *pObj = taosHashInit(256, taosGetDefaultHashFunction(tType), true, false); @@ -1113,6 +1113,7 @@ int32_t filterConvertSetFromBinary(void **q, const char *buf, int32_t len, uint3 } t = varDataLen(tmp); pvar = varDataVal(tmp); + strntolower_s(pvar, pvar, t); break; } case TSDB_DATA_TYPE_NCHAR: { @@ -1157,7 +1158,7 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g if (tree->_node.optr == TSDB_RELATION_IN && (!IS_VAR_DATA_TYPE(type))) { void *data = NULL; - filterConvertSetFromBinary((void **)&data, var->pz, var->nLen, type); + filterConvertSetFromBinary((void **)&data, var->pz, var->nLen, type, false); CHK_LRET(data == NULL, TSDB_CODE_QRY_APP_ERROR, "failed to convert in param"); if (taosHashGetSize((SHashObj *)data) <= 0) { @@ -1798,7 +1799,10 @@ int32_t filterInitValFieldData(SFilterInfo *info) { } if (unit->compare.optr == TSDB_RELATION_IN) { - filterConvertSetFromBinary((void **)&fi->data, var->pz, var->nLen, type); + SSchema *sch = FILTER_UNIT_COL_DESC(info, unit); + bool tolower = (sch->colId == -1) ? true : false; + + filterConvertSetFromBinary((void **)&fi->data, var->pz, var->nLen, type, tolower); CHK_LRET(fi->data == NULL, TSDB_CODE_QRY_APP_ERROR, "failed to convert in param"); FILTER_SET_FLAG(fi->flag, FLD_DATA_IS_HASH); @@ -2531,8 +2535,6 @@ int32_t filterPostProcessRange(SFilterInfo *info) { int32_t filterGenerateComInfo(SFilterInfo *info) { - uint16_t n = 0; - info->cunits = malloc(info->unitNum * sizeof(*info->cunits)); info->blkUnitRes = malloc(sizeof(*info->blkUnitRes) * info->unitNum); info->blkUnits = malloc(sizeof(*info->blkUnits) * (info->unitNum + 1) * info->groupNum); @@ -2560,24 +2562,6 @@ int32_t filterGenerateComInfo(SFilterInfo *info) { info->cunits[i].dataSize = FILTER_UNIT_COL_SIZE(info, unit); info->cunits[i].dataType = FILTER_UNIT_DATA_TYPE(unit); } - - uint16_t cgroupNum = info->groupNum + 1; - - for (uint16_t i = 0; i < info->groupNum; ++i) { - cgroupNum += info->groups[i].unitNum; - } - - info->cgroups = malloc(cgroupNum * sizeof(*info->cgroups)); - - for (uint16_t i = 0; i < info->groupNum; ++i) { - info->cgroups[n++] = info->groups[i].unitNum; - - for (uint16_t m = 0; m < info->groups[i].unitNum; ++m) { - info->cgroups[n++] = info->groups[i].unitIdxs[m]; - } - } - - info->cgroups[n] = 0; return TSDB_CODE_SUCCESS; } @@ -2887,7 +2871,7 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, for (int32_t i = 0; i < numOfRows; ++i) { uint16_t uidx = info->groups[0].unitIdxs[0]; void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i; - (*p)[i] = isNull(colData, info->cunits[uidx].dataType); + (*p)[i] = ((colData == NULL) || isNull(colData, info->cunits[uidx].dataType)); if ((*p)[i] == 0) { all = false; } @@ -2910,7 +2894,7 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows for (int32_t i = 0; i < numOfRows; ++i) { uint16_t uidx = info->groups[0].unitIdxs[0]; void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i; - (*p)[i] = !isNull(colData, info->cunits[uidx].dataType); + (*p)[i] = ((colData != NULL) && !isNull(colData, info->cunits[uidx].dataType)); if ((*p)[i] == 0) { all = false; } @@ -2938,7 +2922,7 @@ bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, int8_t** p, SDataSta } for (int32_t i = 0; i < numOfRows; ++i) { - if (isNull(colData, info->cunits[0].dataType)) { + if (colData == NULL || isNull(colData, info->cunits[0].dataType)) { all = false; colData += dataSize; continue; @@ -2971,7 +2955,7 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SDataStat for (int32_t i = 0; i < numOfRows; ++i) { uint16_t uidx = info->groups[0].unitIdxs[0]; void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i; - if (isNull(colData, info->cunits[uidx].dataType)) { + if (colData == NULL || isNull(colData, info->cunits[uidx].dataType)) { (*p)[i] = 0; all = false; continue; @@ -3015,7 +2999,7 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SDataStatis * //} else { uint8_t optr = cunit->optr; - if (isNull(colData, cunit->dataType)) { + if (colData == NULL || isNull(colData, cunit->dataType)) { (*p)[i] = optr == TSDB_RELATION_ISNULL ? true : false; } else { if (optr == TSDB_RELATION_NOTNULL) { diff --git a/tests/pytest/query/filterOtherTypes.py b/tests/pytest/query/filterOtherTypes.py index f80552138d..7d62f2502e 100644 --- a/tests/pytest/query/filterOtherTypes.py +++ b/tests/pytest/query/filterOtherTypes.py @@ -80,10 +80,12 @@ class TDTestCase: tdSql.error("select * from st where tbcol1 like '____'") # > for nchar type on column - tdSql.error("select * from st where tbcol2 > 'taosdata'") + tdSql.query("select * from st where tbcol2 > 'taosdata'") + tdSql.checkRows(10) # >= for nchar type on column - tdSql.error("select * from st where tbcol2 >= 'taosdata'") + tdSql.query("select * from st where tbcol2 >= 'taosdata'") + tdSql.checkRows(10) # = for nchar type on column tdSql.query("select * from st where tbcol2 = 'taosdata1'") @@ -98,10 +100,12 @@ class TDTestCase: tdSql.checkRows(9) # > for nchar type on column - tdSql.error("select * from st where tbcol2 < 'taodata'") + tdSql.query("select * from st where tbcol2 < 'taodata'") + tdSql.checkRows(0) # >= for nchar type on column - tdSql.error("select * from st where tbcol2 <= 'taodata'") + tdSql.query("select * from st where tbcol2 <= 'taodata'") + tdSql.checkRows(0) # % for nchar type on column case 1 tdSql.query("select * from st where tbcol2 like '%'") @@ -140,10 +144,12 @@ class TDTestCase: tdSql.checkRows(10) # > for binary type on column - tdSql.error("select * from st where tbcol3 > '涛思数据'") + tdSql.query("select * from st where tbcol3 > '涛思数据'") + tdSql.checkRows(10) # >= for binary type on column - tdSql.error("select * from st where tbcol3 >= '涛思数据'") + tdSql.query("select * from st where tbcol3 >= '涛思数据'") + tdSql.checkRows(10) # = for binary type on column tdSql.query("select * from st where tbcol3 = '涛思数据1'") @@ -158,10 +164,12 @@ class TDTestCase: tdSql.checkRows(9) # > for binary type on column - tdSql.error("select * from st where tbcol3 < '涛思数据'") + tdSql.query("select * from st where tbcol3 < '涛思数据'") + tdSql.checkRows(0) # >= for binary type on column - tdSql.error("select * from st where tbcol3 <= '涛思数据'") + tdSql.query("select * from st where tbcol3 <= '涛思数据'") + tdSql.checkRows(0) # % for binary type on column case 1 tdSql.query("select * from st where tbcol3 like '%'") diff --git a/tests/script/general/parser/between_and.sim b/tests/script/general/parser/between_and.sim index cdced47cb6..5db40471d8 100644 --- a/tests/script/general/parser/between_and.sim +++ b/tests/script/general/parser/between_and.sim @@ -159,7 +159,7 @@ if $data11 != 3 then endi sql_error select * from st2 where f7 between 2.0 and 3.0; -sql_error select * from st2 where f8 between 2.0 and 3.0; -sql_error select * from st2 where f9 between 2.0 and 3.0; +sql select * from st2 where f8 between 2.0 and 3.0; +sql select * from st2 where f9 between 2.0 and 3.0; system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/condition_query2.sim b/tests/script/general/parser/condition_query2.sim index fddd770ea5..513bb9900b 100644 --- a/tests/script/general/parser/condition_query2.sim +++ b/tests/script/general/parser/condition_query2.sim @@ -655,6 +655,32 @@ if $data80 != @21-05-05 18:19:38.000@ then return -1 endi +sql select ts,c1,t9,t10,tbname from stb5 where tbname in ('tb5_1', 'TB5_2'); +if $rows != 12 then + return -1 +endi + +sql select ts,c1,t9,t10,tbname from stb5 where tbname in ('tb5_1', 'TB5_2') or tbname in ('tb5_3'); +if $rows != 16 then + return -1 +endi + +sql select ts,c1,t9,t10,tbname from stb5 where tbname in ('tb5_1', 'TB5_2') and tbname in ('tb5_2'); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:11.000@ then + return -1 +endi print "tag test" sql_error select * from stb5 where t1 match '.*'; sql_error select * from stb5 where t2 match '.*'; diff --git a/tests/script/general/parser/tbnameIn_query.sim b/tests/script/general/parser/tbnameIn_query.sim index db27886bbf..7fa579b9c2 100644 --- a/tests/script/general/parser/tbnameIn_query.sim +++ b/tests/script/general/parser/tbnameIn_query.sim @@ -125,11 +125,10 @@ if $data21 != 2 then return -1 endi -# multiple tbname in is not allowed NOW -sql_error select count(*) from $stb where tbname in ('ti_tb1', 'ti_tb300') and tbname in ('ti_tb5', 'ti_tb1000') group by t1 order by t1 asc -#if $rows != 4 then -# return -1 -#endi +sql select count(*) from $stb where tbname in ('ti_tb1', 'ti_tb300') and tbname in ('ti_tb5', 'ti_tb1000') group by t1 order by t1 asc +if $rows != 0 then + return -1 +endi #if $data00 != $rowNum then # return -1 #endi -- GitLab