diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index ae4c5675f08543f51f240cdde4b62e7319f5a9e6..eac5606bd62e2a3d4b1868359483d6e30caca90c 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -102,6 +102,10 @@ SNode* nodesMakeNode(ENodeType type) { } static EDealRes destroyNode(SNode** pNode, void* pContext) { + if (NULL == pNode || NULL == *pNode) { + return DEAL_RES_IGNORE_CHILD; + } + switch (nodeType(*pNode)) { case QUERY_NODE_VALUE: { SValueNode* pValue = (SValueNode*)*pNode; @@ -133,6 +137,10 @@ static EDealRes destroyNode(SNode** pNode, void* pContext) { } void nodesDestroyNode(SNode* pNode) { + if (NULL == pNode) { + return; + } + nodesRewriteNodePostOrder(&pNode, destroyNode, NULL); } diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 3473b624e307a3426c83ee76bf765926d15e2f93..0c7e7ba4f644f71b6af3688c8e9a08a7f074a72d 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -18,6 +18,7 @@ //#include "queryLog.h" #include "tcompare.h" #include "filterInt.h" +#include "sclInt.h" #include "filter.h" OptrStr gOptrStr[] = { @@ -1677,7 +1678,7 @@ void filterFreeInfo(SFilterInfo *info) { tfree(info->cunits); tfree(info->blkUnitRes); tfree(info->blkUnits); - + for (int32_t i = 0; i < FLD_TYPE_MAX; ++i) { for (uint32_t f = 0; f < info->fields[i].num; ++f) { filterFreeField(&info->fields[i].fields[f], i); @@ -2783,7 +2784,7 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, int8_t** p, //} else { uint8_t optr = cunit->optr; - if (isNull(colData, cunit->dataType)) { + if (colDataIsNull((SColumnInfoData *)(cunit->colData), 0, i, NULL)) { (*p)[i] = optr == OP_TYPE_IS_NULL ? true : false; } else { if (optr == OP_TYPE_IS_NOT_NULL) { @@ -2880,12 +2881,12 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, (*p)[i] = 1; }else if( *(char*)colData == TSDB_DATA_TYPE_JSON){ // for json is null colData = POINTER_SHIFT(colData, CHAR_BYTES); - (*p)[i] = isNull(colData, info->cunits[uidx].dataType); + (*p)[i] = colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL); }else{ (*p)[i] = 0; } }else{ - (*p)[i] = ((colData == NULL) || isNull(colData, info->cunits[uidx].dataType)); + (*p)[i] = ((colData == NULL) || colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL)); } if ((*p)[i] == 0) { all = false; @@ -2915,12 +2916,12 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows (*p)[i] = 0; }else if( *(char*)colData == TSDB_DATA_TYPE_JSON){ // for json is not null colData = POINTER_SHIFT(colData, CHAR_BYTES); - (*p)[i] = !isNull(colData, info->cunits[uidx].dataType); + (*p)[i] = !colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL); }else{ // for json->'key' is not null (*p)[i] = 1; } }else { - (*p)[i] = ((colData != NULL) && !isNull(colData, info->cunits[uidx].dataType)); + (*p)[i] = ((colData != NULL) && !colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL)); } if ((*p)[i] == 0) { @@ -2951,7 +2952,7 @@ bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, int8_t** p, SColumnD for (int32_t i = 0; i < numOfRows; ++i) { void *colData = colDataGet((SColumnInfoData *)info->cunits[0].colData, i); - if (colData == NULL || isNull(colData, info->cunits[0].dataType)) { + if (colData == NULL || colDataIsNull((SColumnInfoData *)info->cunits[0].colData, 0, i, NULL)) { all = false; continue; } @@ -2981,7 +2982,7 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDa for (int32_t i = 0; i < numOfRows; ++i) { uint32_t uidx = info->groups[0].unitIdxs[0]; void *colData = colDataGet((SColumnInfoData *)info->cunits[uidx].colData, i); - if (colData == NULL || isNull(colData, info->cunits[uidx].dataType)) { + if (colData == NULL || colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL)) { (*p)[i] = 0; all = false; continue; @@ -3038,7 +3039,7 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDataAg //} else { uint8_t optr = cunit->optr; - if (colData == NULL || isNull(colData, cunit->dataType)) { + if (colData == NULL || colDataIsNull((SColumnInfoData *)(cunit->colData), 0, i, NULL)) { (*p)[i] = optr == OP_TYPE_IS_NULL ? true : false; } else { if (optr == OP_TYPE_IS_NOT_NULL) { @@ -3675,7 +3676,10 @@ bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnData taosArrayDestroy(pList); - *p = output.data; + *p = output.orig.data; + output.orig.data = NULL; + + sclFreeParam(&output); int8_t *r = output.data; for (int32_t i = 0; i < output.num; ++i) { @@ -3692,4 +3696,3 @@ bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnData - \ No newline at end of file diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index b6ffbe5beb8794c6546cc9108114eb3b576c0414..1abb684cf6acd6938e1f833d96a7832c08c2b109 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -793,15 +793,16 @@ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) { SCL_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } - taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES); sclMoveParamListData(res, 1, 0); *pDst = *res; + + taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES); } _return: - nodesDestroyNode(pNode); + //nodesDestroyNode(pNode); sclFreeRes(ctx.pRes); return code; diff --git a/source/libs/scalar/test/filter/filterTests.cpp b/source/libs/scalar/test/filter/filterTests.cpp index 02dcfbd3a18dd01d8c448f396cd7e487defde4af..0366386ae15f61e57578b0ebbe70b17a499858fe 100644 --- a/source/libs/scalar/test/filter/filterTests.cpp +++ b/source/libs/scalar/test/filter/filterTests.cpp @@ -220,7 +220,7 @@ void flttMakeListNode(SNode **pNode, SNodeList *list, int32_t resType) { } TEST(timerangeTest, greater) { - SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL; + SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL; bool eRes[5] = {false, false, true, true, true}; SScalarParam res = {0}; int64_t tsmall = 222, tbig = 333; @@ -236,6 +236,8 @@ TEST(timerangeTest, greater) { ASSERT_EQ(code, 0); ASSERT_EQ(win.skey, tsmall); ASSERT_EQ(win.ekey, INT64_MAX); + filterFreeInfo(filter); + nodesDestroyNode(opNode1); } TEST(timerangeTest, greater_and_lower) { @@ -263,6 +265,8 @@ TEST(timerangeTest, greater_and_lower) { ASSERT_EQ(code, 0); ASSERT_EQ(win.skey, tsmall); ASSERT_EQ(win.ekey, tbig); + filterFreeInfo(filter); + nodesDestroyNode(logicNode); } @@ -315,6 +319,10 @@ TEST(columnTest, smallint_column_greater_double_value) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } + tfree(rowRes); + filterFreeInfo(filter); + blockDataDestroy(src); + nodesDestroyNode(opNode); } TEST(columnTest, int_column_greater_smallint_value) { @@ -366,6 +374,10 @@ TEST(columnTest, int_column_greater_smallint_value) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } + tfree(rowRes); + filterFreeInfo(filter); + nodesDestroyNode(opNode); + blockDataDestroy(src); } @@ -408,7 +420,10 @@ TEST(columnTest, int_column_in_double_list) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - + tfree(rowRes); + filterFreeInfo(filter); + nodesDestroyNode(opNode); + blockDataDestroy(src); } @@ -470,6 +485,10 @@ TEST(columnTest, binary_column_in_binary_list) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } + tfree(rowRes); + filterFreeInfo(filter); + nodesDestroyNode(opNode); + blockDataDestroy(src); } @@ -515,6 +534,10 @@ TEST(columnTest, binary_column_like_binary) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } + tfree(rowRes); + filterFreeInfo(filter); + nodesDestroyNode(opNode); + blockDataDestroy(src); } @@ -559,6 +582,10 @@ TEST(columnTest, binary_column_is_null) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } + tfree(rowRes); + filterFreeInfo(filter); + nodesDestroyNode(opNode); + blockDataDestroy(src); } TEST(columnTest, binary_column_is_not_null) { @@ -602,6 +629,10 @@ TEST(columnTest, binary_column_is_not_null) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } + tfree(rowRes); + filterFreeInfo(filter); + nodesDestroyNode(opNode); + blockDataDestroy(src); } @@ -637,6 +668,10 @@ TEST(opTest, smallint_column_greater_int_column) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } + tfree(rowRes); + filterFreeInfo(filter); + nodesDestroyNode(opNode); + blockDataDestroy(src); } @@ -672,6 +707,10 @@ TEST(opTest, smallint_value_add_int_column) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } + tfree(rowRes); + filterFreeInfo(filter); + nodesDestroyNode(opNode); + blockDataDestroy(src); } @@ -713,6 +752,10 @@ TEST(opTest, bigint_column_multi_binary_column) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } + tfree(rowRes); + filterFreeInfo(filter); + nodesDestroyNode(opNode); + blockDataDestroy(src); } TEST(opTest, smallint_column_and_binary_column) { @@ -752,6 +795,10 @@ TEST(opTest, smallint_column_and_binary_column) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } + tfree(rowRes); + filterFreeInfo(filter); + nodesDestroyNode(opNode); + blockDataDestroy(src); } TEST(opTest, smallint_column_or_float_column) { @@ -786,6 +833,10 @@ TEST(opTest, smallint_column_or_float_column) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } + tfree(rowRes); + filterFreeInfo(filter); + nodesDestroyNode(opNode); + blockDataDestroy(src); } @@ -822,6 +873,10 @@ TEST(opTest, smallint_column_or_double_value) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } + tfree(rowRes); + filterFreeInfo(filter); + nodesDestroyNode(opNode); + blockDataDestroy(src); } @@ -863,6 +918,10 @@ TEST(opTest, binary_column_is_true) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } + tfree(rowRes); + filterFreeInfo(filter); + nodesDestroyNode(opNode); + blockDataDestroy(src); } @@ -931,6 +990,10 @@ TEST(filterModelogicTest, diff_columns_and_or_and) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } + tfree(rowRes); + filterFreeInfo(filter); + nodesDestroyNode(logicNode1); + blockDataDestroy(src); } TEST(filterModelogicTest, same_column_and_or_and) { @@ -993,6 +1056,10 @@ TEST(filterModelogicTest, same_column_and_or_and) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } + tfree(rowRes); + filterFreeInfo(filter); + nodesDestroyNode(logicNode1); + blockDataDestroy(src); } @@ -1059,6 +1126,10 @@ TEST(filterModelogicTest, diff_columns_or_and_or) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } + tfree(rowRes); + filterFreeInfo(filter); + nodesDestroyNode(logicNode1); + blockDataDestroy(src); } TEST(filterModelogicTest, same_column_or_and_or) { @@ -1121,6 +1192,10 @@ TEST(filterModelogicTest, same_column_or_and_or) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } + tfree(rowRes); + filterFreeInfo(filter); + nodesDestroyNode(logicNode1); + blockDataDestroy(src); } @@ -1190,6 +1265,10 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } + tfree(rowRes); + filterFreeInfo(filter); + nodesDestroyNode(logicNode1); + blockDataDestroy(src); } diff --git a/source/libs/scalar/test/scalar/scalarTests.cpp b/source/libs/scalar/test/scalar/scalarTests.cpp index 56b646a89866e6ea8c1190058e613e4c2bb5eaa0..7e63ad4ed2d944665c926ce23afabefbe7e475af 100644 --- a/source/libs/scalar/test/scalar/scalarTests.cpp +++ b/source/libs/scalar/test/scalar/scalarTests.cpp @@ -378,7 +378,8 @@ TEST(constantTest, tinyint_lower_ubigint) { TEST(constantTest, usmallint_lower_equal_ubigint) { SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - int32_t leftv = 1, rightv = 1; + int32_t leftv = 1; + int64_t rightv = 1; scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_USMALLINT, &leftv); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_UBIGINT, &rightv); scltMakeOpNode(&opNode, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); @@ -395,7 +396,8 @@ TEST(constantTest, usmallint_lower_equal_ubigint) { TEST(constantTest, int_equal_smallint1) { SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - int32_t leftv = 1, rightv = 1; + int32_t leftv = 1; + int16_t rightv = 1; scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv); scltMakeOpNode(&opNode, OP_TYPE_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); @@ -930,6 +932,7 @@ TEST(columnTest, smallint_value_add_int_column) { } taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, bigint_column_multi_binary_column) { @@ -968,6 +971,7 @@ TEST(columnTest, bigint_column_multi_binary_column) { ASSERT_EQ(*((double *)colDataGet(column, i)), eRes[i]); } taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, smallint_column_and_binary_column) { @@ -1005,6 +1009,7 @@ TEST(columnTest, smallint_column_and_binary_column) { ASSERT_EQ(*((int64_t *)colDataGet(column, i)), eRes[i]); } taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, smallint_column_or_float_column) { @@ -1037,6 +1042,7 @@ TEST(columnTest, smallint_column_or_float_column) { ASSERT_EQ(*((int64_t *)colDataGet(column, i)), eRes[i]); } taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, smallint_column_or_double_value) { @@ -1069,6 +1075,7 @@ TEST(columnTest, smallint_column_or_double_value) { ASSERT_EQ(*((int64_t *)colDataGet(column, i)), eRes[i]); } taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, smallint_column_greater_double_value) { @@ -1101,6 +1108,7 @@ TEST(columnTest, smallint_column_greater_double_value) { ASSERT_EQ(*((bool *)colDataGet(column, i)), eRes[i]); } taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, int_column_in_double_list) { @@ -1140,6 +1148,7 @@ TEST(columnTest, int_column_in_double_list) { ASSERT_EQ(*((bool *)colDataGet(column, i)), eRes[i]); } taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, binary_column_in_binary_list) { @@ -1198,6 +1207,7 @@ TEST(columnTest, binary_column_in_binary_list) { ASSERT_EQ(*((bool *)colDataGet(column, i)), eRes[i]); } taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, binary_column_like_binary) { @@ -1242,6 +1252,7 @@ TEST(columnTest, binary_column_like_binary) { } taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } @@ -1282,6 +1293,7 @@ TEST(columnTest, binary_column_is_true) { ASSERT_EQ(*((bool *)colDataGet(column, i)), eRes[i]); } taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, binary_column_is_null) { @@ -1325,6 +1337,7 @@ TEST(columnTest, binary_column_is_null) { ASSERT_EQ(*((bool *)colDataGet(column, i)), eRes[i]); } taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, binary_column_is_not_null) { @@ -1367,6 +1380,7 @@ TEST(columnTest, binary_column_is_not_null) { ASSERT_EQ(*((bool *)colDataGet(column, i)), eRes[i]); } taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, greater_and_lower) { @@ -1408,6 +1422,7 @@ TEST(columnTest, greater_and_lower) { ASSERT_EQ(*((bool *)colDataGet(column, i)), eRes[i]); } taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(logicNode); }