diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 6ddb61477fa53a366e7b085edf92038967e2289a..d36ecc54c58d14981b191cd4af17fefc38dbf30b 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -131,6 +131,7 @@ typedef struct SColumn { typedef struct SExprFilter { tSQLExpr *pExpr; //used for having parse + SSqlExpr *pSqlExpr; SArray *fp; SColumn *pFilters; //having filter info }SExprFilter; diff --git a/src/client/src/tscLocalMerge.c b/src/client/src/tscLocalMerge.c index 9d69e53566de8eb481405c2ea8e6cb68a4012a7d..9870830d2e17d1f6a5f1ec31d1473e68888f1597 100644 --- a/src/client/src/tscLocalMerge.c +++ b/src/client/src/tscLocalMerge.c @@ -1287,8 +1287,7 @@ int32_t doHavingFilter(SQueryInfo* pQueryInfo, tFilePage* pOutput, bool* notSkip int32_t type = pInterField->field.type; - SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i); - char* pInput = pOutput->data + pOutput->num* pExpr->offset; + char* pInput = pOutput->data + pOutput->num* pFieldFilters->pSqlExpr->offset; doFilterFieldData(pQueryInfo, pInput, pOutput, pFieldFilters, type, notSkipped); if (*notSkipped == false) { diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 57399a0590ea0516c6c7c0675bc67ff09ecb5e29..accfc01b0788c87d2f4e98671804d3f2158e0919 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -6708,6 +6708,9 @@ static int32_t checkQueryRangeForFill(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { ++pQueryInfo->havingFieldNum; + size_t n = tscSqlExprNumOfExprs(pQueryInfo); + SSqlExpr* pSqlExpr = tscSqlExprGet(pQueryInfo, n - 1); + int32_t slot = tscNumOfFields(pQueryInfo) - 1; SInternalField* pInfo = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, slot); pInfo->visible = false; @@ -6726,6 +6729,7 @@ static int32_t checkQueryRangeForFill(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { } pFieldFilters->pFilters = pFilters; + pFieldFilters->pSqlExpr = pSqlExpr; pInfo->pFieldFilters = pFieldFilters; } @@ -6740,7 +6744,7 @@ int32_t tscGetExprFilters(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr* pExpr SInternalField* pInfo = NULL; for (int32_t i = pQueryInfo->havingFieldNum - 1; i >= 0; --i) { - pInfo = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, i); + pInfo = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, pQueryInfo->fieldsInfo.numOfOutput - 1 - i); if (pInfo->pFieldFilters && 0 == tSqlExprCompare(pInfo->pFieldFilters->pExpr, pExpr)) { *pField = pInfo; @@ -6818,10 +6822,12 @@ static int32_t handleExprInHavingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t return TSDB_CODE_TSC_OUT_OF_MEMORY; } } else if (sqlOptr == TK_OR) { - int32_t ret = tscInsertExprFields(pCmd, pQueryInfo, pExpr->pLeft, &pInfo); + int32_t ret = tscGetExprFilters(pCmd, pQueryInfo, pExpr->pLeft, &pInfo); if (ret) { return ret; } + + pColumn = pInfo->pFieldFilters->pFilters; // TODO fixme: failed to invalid the filter expression: "col1 = 1 OR col2 = 2" pColFilter = addColumnFilterInfo(pColumn); diff --git a/src/query/src/qParserImpl.c b/src/query/src/qParserImpl.c index 551a55999b16a380965c73c2e05a544e03805b06..ccfe15a20b5e997cbf963ce70120b7f173e9ba35 100644 --- a/src/query/src/qParserImpl.c +++ b/src/query/src/qParserImpl.c @@ -324,13 +324,15 @@ int32_t tSqlExprCompare(tSQLExpr *left, tSQLExpr *right) { if (left->pParam && left->pParam->nExpr != right->pParam->nExpr) { return 1; } - - for (int32_t i = 0; i < right->pParam->nExpr; i++) { - tSQLExpr* pSubLeft = left->pParam->a[i].pNode; - tSQLExpr* pSubRight = right->pParam->a[i].pNode; - - if (tSqlExprCompare(pSubLeft, pSubRight)) { - return 1; + + if (right->pParam && left->pParam) { + for (int32_t i = 0; i < right->pParam->nExpr; i++) { + tSQLExpr* pSubLeft = left->pParam->a[i].pNode; + tSQLExpr* pSubRight = right->pParam->a[i].pNode; + + if (tSqlExprCompare(pSubLeft, pSubRight)) { + return 1; + } } }