提交 5e4148e1 编写于 作者: D dapan1121

feat: add more case when test cases

上级 a13f5538
......@@ -1252,15 +1252,15 @@ void createExprFromOneNode(SExprInfo* pExp, SNode* pNode, int16_t slotId) {
pExp->pExpr->_optrRoot.pRootNode = pNode;
} else if (type == QUERY_NODE_CASE_WHEN) {
pExp->pExpr->nodeType = QUERY_NODE_OPERATOR;
SCaseWhenNode* pNode = (SCaseWhenNode*)pTargetNode->pExpr;
SCaseWhenNode* pCaseNode = (SCaseWhenNode*)pNode;
pExp->base.pParam = taosMemoryCalloc(1, sizeof(SFunctParam));
pExp->base.numOfParams = 1;
SDataType* pType = &pNode->node.resType;
pExp->base.resSchema = createResSchema(pType->type, pType->bytes, pTargetNode->slotId, pType->scale,
pType->precision, pNode->node.aliasName);
pExp->pExpr->_optrRoot.pRootNode = pTargetNode->pExpr;
SDataType* pType = &pCaseNode->node.resType;
pExp->base.resSchema = createResSchema(pType->type, pType->bytes, slotId, pType->scale,
pType->precision, pCaseNode->node.aliasName);
pExp->pExpr->_optrRoot.pRootNode = pNode;
} else {
ASSERT(0);
}
......
......@@ -119,6 +119,17 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) {
return DEAL_RES_CONTINUE;
}
static int32_t rewriteExprForSelect(SNode* pExpr, SSelectStmt* pSelect, ESqlClause clause) {
nodesWalkExpr(pExpr, doNameExpr, NULL);
SRewriteExprCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pExprs = NULL};
cxt.errCode = nodesListMakeAppend(&cxt.pExprs, pExpr);
if (TSDB_CODE_SUCCESS == cxt.errCode) {
nodesRewriteSelectStmt(pSelect, clause, doRewriteExpr, &cxt);
nodesClearList(cxt.pExprs);
}
return cxt.errCode;
}
static int32_t rewriteExprsForSelect(SNodeList* pExprs, SSelectStmt* pSelect, ESqlClause clause) {
nodesWalkExprs(pExprs, doNameExpr, NULL);
SRewriteExprCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pExprs = pExprs};
......@@ -711,8 +722,13 @@ static int32_t createWindowLogicNodeByState(SLogicPlanContext* pCxt, SStateWindo
nodesDestroyNode((SNode*)pWindow);
return TSDB_CODE_OUT_OF_MEMORY;
}
return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode);
// rewrite the expression in subsequent clauses
int32_t code = rewriteExprForSelect(pWindow->pStateExpr, pSelect, SQL_CLAUSE_WINDOW);
if (TSDB_CODE_SUCCESS == code) {
code = createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode);
}
return code;
}
static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionWindowNode* pSession,
......
......@@ -352,6 +352,7 @@
./test.sh -f tsim/scalar/in.sim
./test.sh -f tsim/scalar/scalar.sim
./test.sh -f tsim/scalar/filter.sim
./test.sh -f tsim/scalar/caseWhen.sim
# ---- alter ----
./test.sh -f tsim/alter/cached_schema_after_alter.sim
......
......@@ -469,20 +469,20 @@ if $data00 != 5.000000000 then
return -1
endi
sql select case when sum(f1) then sum(f1)-abs(f1) end from tba1;
sql select case when sum(f1) then sum(f1)-abs(f1) end from tba1 group by f1 order by f1;
if $rows != 4 then
return -1
endi
if $data00 != NULL then
return -1
endi
if $data10 != 0.000000000 then
if $data10 != NULL then
return -1
endi
if $data20 != 0.000000000 then
return -1
endi
if $data30 != NULL then
if $data30 != 0.000000000 then
return -1
endi
......@@ -536,8 +536,7 @@ if $data11 != 1 then
return -1
endi
sql select case when f1 < 3 then 1 when f1 >= 3 then 2 else 3 end caseWhen, sum(f1),count(f1) from tba1 group by case when f1 < 3 then 1 when f1 >= 3 then 2 else 3 end
order by caseWhen;
sql select case when f1 < 3 then 1 when f1 >= 3 then 2 else 3 end caseWhen, sum(f1),count(f1) from tba1 group by case when f1 < 3 then 1 when f1 >= 3 then 2 else 3 end order by caseWhen;
if $rows != 3 then
return -1
endi
......@@ -586,7 +585,37 @@ if $data30 != NULL then
return -1
endi
#select case when f1 < 3 then 1 when f1 >= 3 then 2 else 3 end,sum(f1),count(f1) from tba1 state_window(case when f1 < 3 then 1 when f1 >= 3 then 2 else 3 end);
sql select case when f1 < 3 then 1 when f1 >= 3 then 2 else 3 end,sum(f1),count(f1) from tba1 state_window(case when f1 < 3 then 1 when f1 >= 3 then 2 else 3 end);
if $rows != 3 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != 1 then
return -1
endi
if $data02 != 2 then
return -1
endi
if $data10 != 2 then
return -1
endi
if $data11 != 5 then
return -1
endi
if $data12 != 1 then
return -1
endi
if $data20 != 3 then
return -1
endi
if $data21 != NULL then
return -1
endi
if $data22 != 0 then
return -1
endi
sql select f1 from tba1 where case when case when f1 <= 0 then 3 when f1 = 1 then 4 when f1 >= 3 then 2 else 1 end > 2 then 1 else 0 end > 0;
if $rows != 2 then
......@@ -776,16 +805,16 @@ sql select case cast(f2 as int) when 0 then f2 when f1 then 11 else ts end from
if $rows != 4 then
return -1
endi
if $data00 != 0 then
if $data00 != a then
return -1
endi
if $data10 != 1 then
if $data10 != 0 then
return -1
endi
if $data20 != 5 then
if $data20 != 11 then
return -1
endi
if $data30 != 99 then
if $data30 != 1664176504 then
return -1
endi
......@@ -806,6 +835,185 @@ if $data30 != 3 then
return -1
endi
sql select case f1 when sum(f1) then sum(f1)-abs(f1) end from tba1 group by f1 order by f1;
if $rows != 4 then
return -1
endi
if $data00 != NULL then
return -1
endi
if $data10 != 0.000000000 then
return -1
endi
if $data20 != 0.000000000 then
return -1
endi
if $data30 != 0.000000000 then
return -1
endi
sql select f1, case sum(f1) when 1 then f1 + 99 when f1 then f1 -99 else f1 end from tba1 group by f1 order by f1;
if $rows != 4 then
return -1
endi
if $data00 != NULL then
return -1
endi
if $data01 != NULL then
return -1
endi
if $data10 != 0 then
return -1
endi
if $data11 != -99.000000000 then
return -1
endi
if $data20 != 1 then
return -1
endi
if $data21 != 100.000000000 then
return -1
endi
if $data30 != 5 then
return -1
endi
if $data31 != -94.000000000 then
return -1
endi
sql select case when 3 then 4 end from sta;
if $rows != 20 then
return -1
endi
sql select case when 0 then 4 end from sta;
if $rows != 20 then
return -1
endi
sql select case when null then 4 end from sta;
if $rows != 20 then
return -1
endi
sql select case when 1 then 4+1 end from sta;
if $rows != 20 then
return -1
endi
sql select case when 1-1 then 0 end from sta;
if $rows != 20 then
return -1
endi
sql select case when 1+1 then 0 end from sta;
if $rows != 20 then
return -1
endi
sql select case when abs(3) then abs(-1) end from sta;
if $rows != 20 then
return -1
endi
sql select case when abs(1+1) then abs(-1)+abs(3) end from sta;
if $rows != 20 then
return -1
endi
sql select case when 0 then 1 else 3 end from sta;
if $rows != 20 then
return -1
endi
sql select case when 0 then 1 when 1 then 0 else 3 end from sta;
if $rows != 20 then
return -1
endi
sql select case when 0 then 1 when 1 then 0 when 2 then 3 end from sta;
if $rows != 20 then
return -1
endi
sql select case when 'a' then 'b' when null then 0 end from sta;
if $rows != 20 then
return -1
endi
sql select case when '2' then 'b' when null then 0 end from sta;
if $rows != 20 then
return -1
endi
sql select case when 0 then 'b' else null end from sta;
if $rows != 20 then
return -1
endi
sql select case when 0 then 'b' else 2+abs(-2) end from sta;
if $rows != 20 then
return -1
endi
sql select case 3 when 3 then 4 end from sta;
if $rows != 20 then
return -1
endi
sql select case 3 when 1 then 4 end from sta;
if $rows != 20 then
return -1
endi
sql select case 3 when 1 then 4 else 2 end from sta;
if $rows != 20 then
return -1
endi
sql select case 3 when null then 4 when '3' then 1 end from sta;
if $rows != 20 then
return -1
endi
sql select case null when null then 4 when 3 then 1 end from sta;
if $rows != 20 then
return -1
endi
sql select case 3.0 when null then 4 when '3' then 1 end from sta;
if $rows != 20 then
return -1
endi
sql select f2,case f2 when 'a' then 4 when '0' then 1 end from sta order by f2;
if $rows != 20 then
return -1
endi
sql select f2,f1,case f2 when f1 then f1 when f1 - 1 then f1 else 99 end from sta order by f2;
if $rows != 20 then
return -1
endi
sql select case cast(f2 as int) when 0 then f2 when f1 then 11 else ts end from sta;
if $rows != 20 then
return -1
endi
sql select f1, case f1 + 1 when 1 then 1 when 2 then 2 else 3 end from sta order by f1;
if $rows != 20 then
return -1
endi
sql select case f1 when sum(f1) then sum(f1)-abs(f1) end from sta group by f1 order by f1;
if $rows != 4 then
return -1
endi
if $data00 != NULL then
return -1
endi
if $data10 != 0.000000000 then
return -1
endi
if $data20 != NULL then
return -1
endi
if $data30 != NULL then
return -1
endi
sql select case sum(f1) when 1 then f1 + 99 when f1 then f1 -99 else f1 end from sta group by f1 order by f1;
if $rows != 4 then
return -1
endi
if $data00 != NULL then
return -1
endi
if $data10 != -99.000000000 then
return -1
endi
if $data20 != 1.000000000 then
return -1
endi
if $data30 != 5.000000000 then
return -1
endi
sql_error select case when sum(f1) then sum(f1)-abs(f1) end from tba1;
system sh/exec.sh -n dnode1 -s stop -x SIGINT
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册