提交 17dd6d6f 编写于 作者: X Xiaoyu Wang

feat: reserved aggregate function constant parameters

上级 6e1d926f
...@@ -132,6 +132,7 @@ typedef enum EOperatorType { ...@@ -132,6 +132,7 @@ typedef enum EOperatorType {
OP_TYPE_MOD, OP_TYPE_MOD,
// unary arithmetic operator // unary arithmetic operator
OP_TYPE_MINUS, OP_TYPE_MINUS,
OP_TYPE_ASSIGN,
// bit operator // bit operator
OP_TYPE_BIT_AND, OP_TYPE_BIT_AND,
......
...@@ -624,16 +624,36 @@ static EDealRes collectAndRewrite(SRewritePrecalcExprsCxt* pCxt, SNode** pNode) ...@@ -624,16 +624,36 @@ static EDealRes collectAndRewrite(SRewritePrecalcExprsCxt* pCxt, SNode** pNode)
return DEAL_RES_IGNORE_CHILD; return DEAL_RES_IGNORE_CHILD;
} }
static int32_t rewriteValueToOperator(SRewritePrecalcExprsCxt* pCxt, SNode** pNode) {
SOperatorNode* pOper = (SOperatorNode*)nodesMakeNode(QUERY_NODE_OPERATOR);
if (NULL == pOper) {
return TSDB_CODE_OUT_OF_MEMORY;
}
SValueNode* pVal = (SValueNode*)*pNode;
pOper->node.resType = pVal->node.resType;
strcpy(pOper->node.aliasName, pVal->node.aliasName);
pOper->opType = OP_TYPE_ASSIGN;
pOper->pLeft = *pNode;
*pNode = (SNode*)pOper;
return TSDB_CODE_SUCCESS;
}
static EDealRes doRewritePrecalcExprs(SNode** pNode, void* pContext) { static EDealRes doRewritePrecalcExprs(SNode** pNode, void* pContext) {
SRewritePrecalcExprsCxt* pCxt = (SRewritePrecalcExprsCxt*)pContext; SRewritePrecalcExprsCxt* pCxt = (SRewritePrecalcExprsCxt*)pContext;
switch (nodeType(*pNode)) { switch (nodeType(*pNode)) {
case QUERY_NODE_VALUE: {
if (TSDB_CODE_SUCCESS != rewriteValueToOperator(pCxt, pNode)) {
return DEAL_RES_ERROR;
}
return collectAndRewrite(pCxt, pNode);
}
case QUERY_NODE_OPERATOR: case QUERY_NODE_OPERATOR:
case QUERY_NODE_LOGIC_CONDITION: { case QUERY_NODE_LOGIC_CONDITION: {
return collectAndRewrite(pContext, pNode); return collectAndRewrite(pCxt, pNode);
} }
case QUERY_NODE_FUNCTION: { case QUERY_NODE_FUNCTION: {
if (fmIsScalarFunc(((SFunctionNode*)(*pNode))->funcId)) { if (fmIsScalarFunc(((SFunctionNode*)(*pNode))->funcId)) {
return collectAndRewrite(pContext, pNode); return collectAndRewrite(pCxt, pNode);
} }
} }
default: default:
......
...@@ -49,6 +49,8 @@ TEST_F(PlanGroupByTest, aggFunc) { ...@@ -49,6 +49,8 @@ TEST_F(PlanGroupByTest, aggFunc) {
run("SELECT LAST(*), FIRST(*) FROM t1"); run("SELECT LAST(*), FIRST(*) FROM t1");
run("SELECT LAST(*), FIRST(*) FROM t1 GROUP BY c1"); run("SELECT LAST(*), FIRST(*) FROM t1 GROUP BY c1");
run("SELECT SUM(10), COUNT(c1) FROM t1 GROUP BY c2");
} }
TEST_F(PlanGroupByTest, selectFunc) { TEST_F(PlanGroupByTest, selectFunc) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册