Merge pull request #17951 from taosdata/fix/3.0_bugfix_wxy

fix: state_window error
This commit is contained in:
Shengliang Guan 2022-11-08 14:48:24 +08:00 committed by GitHub
commit c016266989
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 18 deletions

View File

@ -3023,20 +3023,17 @@ static int32_t translateIntervalWindow(STranslateContext* pCxt, SSelectStmt* pSe
return code; return code;
} }
static EDealRes checkStateExpr(SNode* pNode, void* pContext) { static int32_t checkStateExpr(STranslateContext* pCxt, SNode* pNode) {
if (QUERY_NODE_COLUMN == nodeType(pNode)) { int32_t type = ((SExprNode*)pNode)->resType.type;
STranslateContext* pCxt = pContext; if (!IS_INTEGER_TYPE(type) && type != TSDB_DATA_TYPE_BOOL && !IS_VAR_DATA_TYPE(type)) {
SColumnNode* pCol = (SColumnNode*)pNode; return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STATE_WIN_TYPE);
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);
}
} }
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) { static bool hasPartitionByTbname(SNodeList* pPartitionByList) {
@ -3068,11 +3065,11 @@ static int32_t translateStateWindow(STranslateContext* pCxt, SSelectStmt* pSelec
} }
SStateWindowNode* pState = (SStateWindowNode*)pSelect->pWindow; SStateWindowNode* pState = (SStateWindowNode*)pSelect->pWindow;
nodesWalkExprPostOrder(pState->pExpr, checkStateExpr, pCxt); int32_t code = checkStateExpr(pCxt, pState->pExpr);
if (TSDB_CODE_SUCCESS == pCxt->errCode) { if (TSDB_CODE_SUCCESS == code) {
pCxt->errCode = checkStateWindowForStream(pCxt, pSelect); code = checkStateWindowForStream(pCxt, pSelect);
} }
return pCxt->errCode; return code;
} }
static int32_t translateSessionWindow(STranslateContext* pCxt, SSelectStmt* pSelect) { static int32_t translateSessionWindow(STranslateContext* pCxt, SSelectStmt* pSelect) {

View File

@ -29,7 +29,7 @@ TEST_F(PlanStateTest, basic) {
TEST_F(PlanStateTest, stateExpr) { TEST_F(PlanStateTest, stateExpr) {
useDb("root", "test"); 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) { TEST_F(PlanStateTest, selectFunc) {