From 2d6c4ebda8a65dad9387c8d31a54758983c032bf Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 8 Nov 2022 10:18:27 +0800 Subject: [PATCH 1/2] fix: state_window error --- source/libs/parser/src/parTranslater.c | 31 ++++++++++++-------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index d3ff787f50..d3f343764b 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -3021,20 +3021,17 @@ static int32_t translateIntervalWindow(STranslateContext* pCxt, SSelectStmt* pSe return code; } -static EDealRes checkStateExpr(SNode* pNode, void* pContext) { - if (QUERY_NODE_COLUMN == nodeType(pNode)) { - STranslateContext* pCxt = pContext; - SColumnNode* pCol = (SColumnNode*)pNode; - - int32_t type = pCol->node.resType.type; - if (!IS_INTEGER_TYPE(type) && type != TSDB_DATA_TYPE_BOOL && !IS_VAR_DATA_TYPE(type)) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_TYPE); - } - if (COLUMN_TYPE_TAG == pCol->colType) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_COL); - } +static int32_t checkStateExpr(STranslateContext* pCxt, SNode* pNode) { + int32_t type = ((SExprNode*)pNode)->resType.type; + if (!IS_INTEGER_TYPE(type) && type != TSDB_DATA_TYPE_BOOL && !IS_VAR_DATA_TYPE(type)) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STATE_WIN_TYPE); } - return DEAL_RES_CONTINUE; + + if (QUERY_NODE_COLUMN == nodeType(pNode) && COLUMN_TYPE_TAG == ((SColumnNode*)pNode)->colType) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STATE_WIN_COL); + } + + return TSDB_CODE_SUCCESS; } static bool hasPartitionByTbname(SNodeList* pPartitionByList) { @@ -3066,11 +3063,11 @@ static int32_t translateStateWindow(STranslateContext* pCxt, SSelectStmt* pSelec } SStateWindowNode* pState = (SStateWindowNode*)pSelect->pWindow; - nodesWalkExprPostOrder(pState->pExpr, checkStateExpr, pCxt); - if (TSDB_CODE_SUCCESS == pCxt->errCode) { - pCxt->errCode = checkStateWindowForStream(pCxt, pSelect); + int32_t code = checkStateExpr(pCxt, pState->pExpr); + if (TSDB_CODE_SUCCESS == code) { + code = checkStateWindowForStream(pCxt, pSelect); } - return pCxt->errCode; + return code; } static int32_t translateSessionWindow(STranslateContext* pCxt, SSelectStmt* pSelect) { From 8f7c0b8c60c468ea67672d906642b4ce10b11775 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 8 Nov 2022 11:35:12 +0800 Subject: [PATCH 2/2] fix: state_window error --- source/libs/planner/test/planStateTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/planner/test/planStateTest.cpp b/source/libs/planner/test/planStateTest.cpp index 6985bc8807..3dafaa8bf5 100644 --- a/source/libs/planner/test/planStateTest.cpp +++ b/source/libs/planner/test/planStateTest.cpp @@ -29,7 +29,7 @@ TEST_F(PlanStateTest, basic) { TEST_F(PlanStateTest, stateExpr) { useDb("root", "test"); - run("SELECT COUNT(*) FROM t1 STATE_WINDOW(c1 + 10)"); + run("SELECT COUNT(*) FROM t1 STATE_WINDOW(CASE WHEN c1 > 10 THEN 1 ELSE 0 END)"); } TEST_F(PlanStateTest, selectFunc) {