From 375847cad65c8db0216da94ff0084f093052226e Mon Sep 17 00:00:00 2001 From: wpan Date: Fri, 16 Jul 2021 08:13:06 +0800 Subject: [PATCH] support nchar filter --- src/query/src/qFilter.c | 91 ++++++++++++++++++++++- tests/script/general/parser/condition.sim | 39 ++++++++++ 2 files changed, 127 insertions(+), 3 deletions(-) diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 8f1530551c..fa26d652fe 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -1470,7 +1470,7 @@ _err_return: return TSDB_CODE_SUCCESS; } -int32_t filterGenerateGroupFromArray(SFilterInfo *info, SArray* group) { +int32_t filterConvertGroupFromArray(SFilterInfo *info, SArray* group) { size_t groupSize = taosArrayGetSize(group); info->groupNum = (uint16_t)groupSize; @@ -1488,6 +1488,89 @@ int32_t filterGenerateGroupFromArray(SFilterInfo *info, SArray* group) { return TSDB_CODE_SUCCESS; } +int32_t filterCheckRangeCoverage(SFilterInfo *info, SFilterGroupCtx* gctx, SFilterGroupCtx** uctx) { + if (gctx->num == 0) { + return TSDB_CODE_SUCCESS; + } + + SFilterInfo oinfo = *info; + uint16_t gNum = 0; + SArray* group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup)); + + memset(info, 0, sizeof(*info)); + + filterInitUnitsFields(info); + + for (uint16_t i = 0; i < oinfo.groupNum; ++i) { + SFilterGroup* g = oinfo.groups + i; + SFilterGroup ng = {0}; + uint16_t unitNum = (uctx && uctx[i]) ? uctx[i]->num : g->unitNum; + + if (unitNum == 0) { + continue; + } + + ++gNum; + + if ((uctx == NULL) || (uctx[i] == NULL)) { + for (uint16_t n = 0; n < g->unitNum; ++n) { + SFilterUnit* u = FILTER_GROUP_UNIT(&oinfo, g, n); + filterAddUnitFromUnit(info, &oinfo, u); + filterAddUnitToGroup(&ng, info->unitNum - 1); + } + + taosArrayPush(group, &ng); + + continue; + } + + SFilterGroupCtx* ctx = uctx[i]; + for (uint16_t n = 0; n < g->unitNum; ++n) { + SFilterUnit* u = FILTER_GROUP_UNIT(&oinfo, g, n); + int32_t type = FILTER_UNIT_DATA_TYPE(u); + if (FILTER_NO_MERGE_DATA_TYPE(type)) { + filterAddUnitFromUnit(info, &oinfo, u); + filterAddUnitToGroup(&ng, info->unitNum - 1); + continue; + } + + uint16_t cidx = FILTER_UNIT_COL_IDX(u); + + assert(ctx->col[cidx] > 0 || ctx->col[cidx] == -1); + + if (ctx->col[cidx] != -1) { + filterAddUnitFromUnit(info, &oinfo, u); + filterAddUnitToGroup(&ng, info->unitNum - 1); + } + } + + if (ctx->colRange && taosArrayGetSize(ctx->colRange) > 0) { + int32_t size = (int32_t)taosArrayGetSize(ctx->colRange); + for (int32_t m = 0; m < size; ++m) { + SFilterColRange *cra = taosArrayGet(ctx->colRange, m); + filterAddGroupUnitFromRange(info, &oinfo, cra, &ng, TSDB_RELATION_AND, NULL); + } + } + + taosArrayPush(group, &ng); + } + + if (gctx->colRange && taosArrayGetSize(gctx->colRange) > 0) { + int32_t size = (int32_t)taosArrayGetSize(gctx->colRange); + for (int32_t i = 0; i < size; ++i) { + SFilterColRange *cra = taosArrayGet(gctx->colRange, i); + filterAddGroupUnitFromRange(info, &oinfo, cra, NULL, TSDB_RELATION_OR, group); + } + } + + filterConvertGroupFromArray(info, group); + + taosArrayDestroy(group); + + return TSDB_CODE_SUCCESS; +} + + int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx* gctx, SFilterGroupCtx** uctx) { if (gctx->num == 0) { @@ -1564,7 +1647,7 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx* gctx, SFilterGroupCtx* } } - filterGenerateGroupFromArray(info, group); + filterConvertGroupFromArray(info, group); taosArrayDestroy(group); @@ -1590,6 +1673,8 @@ int32_t filterPreprocess(SFilterInfo *info) { return TSDB_CODE_SUCCESS; } + filterCheckRangeCoverage(info, &groupRes, unitsRes); + //TODO GET COLUMN RANGE filterRewrite(info, &groupRes, unitsRes); @@ -1699,7 +1784,7 @@ int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo, uint32_t option ERR_JRET(code); - filterGenerateGroupFromArray(info, group); + filterConvertGroupFromArray(info, group); ERR_JRET(filterInitValFieldData(info)); diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index d414cb1554..8048ccc192 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -93,6 +93,12 @@ sql_error select ts,c1,c7 from stb1 where c7 > false sql_error select * from stb1 where c1 > NULL; sql_error select * from stb1 where c1 = NULL; sql_error select * from stb1 where c1 LIKE '%1'; +sql_error select * from stb1 where c2 LIKE '%1'; +sql_error select * from stb1 where c3 LIKE '%1'; +sql_error select * from stb1 where c4 LIKE '%1'; +sql_error select * from stb1 where c5 LIKE '%1'; +sql_error select * from stb1 where c6 LIKE '%1'; +sql_error select * from stb1 where c7 LIKE '%1'; sql_error select * from stb1 where c1 = 'NULL'; sql_error select * from stb1 where c2 > 'NULL'; sql_error select * from stb1 where c3 <> 'NULL'; @@ -1225,6 +1231,39 @@ if $data20 != @21-05-05 18:19:18.000@ then return -1 endi +sql select * from stb1 where c1 in (11,21,31,41) and c1 in (11,42); +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi + +sql select * from stb1 where c8 in ('11','21','31','41') and c8 in ('11','42'); +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi + +sql select * from stb1 where (c1 > 60 and c2 > 40) or (c1 > 62 and c2 > 50); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.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