From f3bf12c7116c404c33686c590c50e95478cd1b03 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 11 May 2022 23:20:01 +0800 Subject: [PATCH] enh(index): update index filter UT --- source/libs/executor/inc/indexoperator.h | 16 +++++++- source/libs/executor/src/indexoperator.c | 6 +-- .../libs/executor/test/indexexcutorTests.cpp | 41 ++++++++++++++++--- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/source/libs/executor/inc/indexoperator.h b/source/libs/executor/inc/indexoperator.h index 9e67ac7f41..d033c63ef8 100644 --- a/source/libs/executor/inc/indexoperator.h +++ b/source/libs/executor/inc/indexoperator.h @@ -13,11 +13,23 @@ * along with this program. If not, see . */ -#include "filter.h" +#ifndef _INDEX_OPERATOR_H +#define _INDEX_OPERATOR_H + +#ifdef __cplusplus +extern "C" { +#endif +#include "nodes.h" #include "tglobal.h" typedef enum { SFLT_NOT_INDEX, SFLT_COARSE_INDEX, SFLT_ACCURATE_INDEX } SIdxFltStatus; SIdxFltStatus idxGetFltStatus(SNode *pFilterNode); // construct tag filter operator later -int32_t doFilterTag(const SNode *pFilterNode, SArray *resutl); +int32_t doFilterTag(const SNode *pFilterNode, SArray *result); + +#ifdef __cplusplus +} +#endif + +#endif /*INDEX_OPERATOR_*/ diff --git a/source/libs/executor/src/indexoperator.c b/source/libs/executor/src/indexoperator.c index fe30ebb2ea..c17fcacf1f 100644 --- a/source/libs/executor/src/indexoperator.c +++ b/source/libs/executor/src/indexoperator.c @@ -583,7 +583,7 @@ int32_t doFilterTag(const SNode *pFilterNode, SArray *result) { SFilterInfo *filter = NULL; // todo move to the initialization function - SIF_ERR_RET(filterInitFromNode((SNode *)pFilterNode, &filter, 0)); + // SIF_ERR_RET(filterInitFromNode((SNode *)pFilterNode, &filter, 0)); SIFParam param = {0}; SIF_ERR_RET(sifCalculate((SNode *)pFilterNode, ¶m)); @@ -598,9 +598,9 @@ SIdxFltStatus idxGetFltStatus(SNode *pFilterNode) { if (pFilterNode == NULL) { return SFLT_NOT_INDEX; } - SFilterInfo *filter = NULL; + // SFilterInfo *filter = NULL; // todo move to the initialization function - SIF_ERR_RET(filterInitFromNode((SNode *)pFilterNode, &filter, 0)); + // SIF_ERR_RET(filterInitFromNode((SNode *)pFilterNode, &filter, 0)); SIF_ERR_RET(sifGetFltHint((SNode *)pFilterNode, &st)); return st; diff --git a/source/libs/executor/test/indexexcutorTests.cpp b/source/libs/executor/test/indexexcutorTests.cpp index a105509c26..5f1bff45a3 100644 --- a/source/libs/executor/test/indexexcutorTests.cpp +++ b/source/libs/executor/test/indexexcutorTests.cpp @@ -23,10 +23,12 @@ #pragma GCC diagnostic ignored "-Wunused-function" #pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wsign-compare" -#include "os.h" #include "executor.h" #include "executorimpl.h" +#include "indexoperator.h" +#include "os.h" + #include "stub.h" #include "taos.h" #include "tcompare.h" @@ -181,15 +183,24 @@ TEST(testCase, index_filter) { SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; sifMakeColumnNode(&pLeft, "test", "col", COLUMN_TYPE_TAG, TSDB_DATA_TYPE_INT); sifMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &sifRightV); - sifMakeOpNode(&opNode, OP_LESS_THAN, TSDB_DATA_TYPE_INT, pLeft, pRight); + sifMakeOpNode(&opNode, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_INT, pLeft, pRight); + SArray *result = taosArrayInit(4, sizeof(uint64_t)); + doFilterTag(opNode, result); + EXPECT_EQ(1, taosArrayGetSize(result)); + taosArrayDestroy(result); nodesDestroyNode(res); } { SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; sifMakeColumnNode(&pLeft, "test", "col", COLUMN_TYPE_TAG, TSDB_DATA_TYPE_INT); sifMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &sifRightV); - sifMakeOpNode(&opNode, OP_LESS_THAN, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); + sifMakeOpNode(&opNode, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); + SArray *result = taosArrayInit(4, sizeof(uint64_t)); + doFilterTag(opNode, result); + EXPECT_EQ(1, taosArrayGetSize(result)); + + taosArrayDestroy(result); nodesDestroyNode(res); } } @@ -199,7 +210,27 @@ TEST(testCase, index_filter_varify) { SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; sifMakeColumnNode(&pLeft, "test", "col", COLUMN_TYPE_TAG, TSDB_DATA_TYPE_INT); sifMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &sifRightV); - sifMakeOpNode(&opNode, OP_LESS_THAN, TSDB_DATA_TYPE_INT, pLeft, pRight); + sifMakeOpNode(&opNode, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_INT, pLeft, pRight); + nodesDestroyNode(res); + + SIdxFltStatus st = idxGetFltStatus(opNode); + EXPECT_EQ(st, SFLT_ACCURATE_INDEX); + } + { + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + sifMakeColumnNode(&pLeft, "test", "col", COLUMN_TYPE_TAG, TSDB_DATA_TYPE_INT); + sifMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &sifRightV); + sifMakeOpNode(&opNode, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); + + SIdxFltStatus st = idxGetFltStatus(opNode); + EXPECT_EQ(st, SFLT_COARSE_INDEX); + nodesDestroyNode(res); + } + { + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + sifMakeColumnNode(&pLeft, "test", "col", COLUMN_TYPE_TAG, TSDB_DATA_TYPE_INT); + sifMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &sifRightV); + sifMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_INT, pLeft, pRight); nodesDestroyNode(res); SIdxFltStatus st = idxGetFltStatus(opNode); @@ -209,7 +240,7 @@ TEST(testCase, index_filter_varify) { SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; sifMakeColumnNode(&pLeft, "test", "col", COLUMN_TYPE_TAG, TSDB_DATA_TYPE_INT); sifMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &sifRightV); - sifMakeOpNode(&opNode, OP_LESS_THAN, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); + sifMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); SIdxFltStatus st = idxGetFltStatus(opNode); EXPECT_EQ(st, SFLT_COARSE_INDEX); -- GitLab