fix: SColumnRefNode transfer to SelectFunction's param
This commit is contained in:
parent
8dc2a6bbd9
commit
8c3fe7cc70
|
@ -282,7 +282,7 @@ int32_t doAggregateImpl(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((&pCtx[k])->input.pData[0] == NULL) {
|
if ((&pCtx[k])->input.pData[0] == NULL) {
|
||||||
code = TSDB_CODE_TDB_INVALID_ACTION;
|
code = TSDB_CODE_PAR_NOT_SINGLE_GROUP;
|
||||||
qError("%s aggregate function error happens, input data is NULL.", GET_TASKID(pOperator->pTaskInfo));
|
qError("%s aggregate function error happens, input data is NULL.", GET_TASKID(pOperator->pTaskInfo));
|
||||||
} else {
|
} else {
|
||||||
code = pCtx[k].fpSet.process(&pCtx[k]);
|
code = pCtx[k].fpSet.process(&pCtx[k]);
|
||||||
|
@ -570,7 +570,7 @@ void applyAggFunctionOnPartialTuples(SExecTaskInfo* taskInfo, SqlFunctionCtx* pC
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
if (functionNeedToExecute(&pCtx[k]) && pCtx[k].fpSet.process != NULL) {
|
if (functionNeedToExecute(&pCtx[k]) && pCtx[k].fpSet.process != NULL) {
|
||||||
if ((&pCtx[k])->input.pData[0] == NULL) {
|
if ((&pCtx[k])->input.pData[0] == NULL) {
|
||||||
code = TSDB_CODE_TDB_INVALID_ACTION;
|
code = TSDB_CODE_PAR_NOT_SINGLE_GROUP;
|
||||||
qError("%s apply functions error, input data is NULL.", GET_TASKID(taskInfo));
|
qError("%s apply functions error, input data is NULL.", GET_TASKID(taskInfo));
|
||||||
} else {
|
} else {
|
||||||
code = pCtx[k].fpSet.process(&pCtx[k]);
|
code = pCtx[k].fpSet.process(&pCtx[k]);
|
||||||
|
|
|
@ -2757,7 +2757,7 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect)
|
||||||
if (!pSelect->isDistinct) {
|
if (!pSelect->isDistinct) {
|
||||||
nodesRewriteExprs(pSelect->pOrderByList, doCheckAggColCoexist, &cxt);
|
nodesRewriteExprs(pSelect->pOrderByList, doCheckAggColCoexist, &cxt);
|
||||||
}
|
}
|
||||||
if (1 == pSelect->selectFuncNum && !pSelect->hasOtherVectorFunc) {
|
if (0 < pSelect->selectFuncNum && !pSelect->hasOtherVectorFunc) {
|
||||||
return rewriteColsToSelectValFunc(pCxt, pSelect);
|
return rewriteColsToSelectValFunc(pCxt, pSelect);
|
||||||
}
|
}
|
||||||
if (cxt.existCol) {
|
if (cxt.existCol) {
|
||||||
|
@ -3436,6 +3436,12 @@ static int32_t checkOrderByAggForGroupBy(STranslateContext* pCxt, SSelectStmt* p
|
||||||
if (NULL != getGroupByList(pCxt) || NULL != pSelect->pWindow) {
|
if (NULL != getGroupByList(pCxt) || NULL != pSelect->pWindow) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
SNode* pProject = NULL;
|
||||||
|
FOREACH(pProject, pSelect->pProjectionList) {
|
||||||
|
if(isAggFunc(pProject)) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
SNode* pNode = NULL;
|
SNode* pNode = NULL;
|
||||||
WHERE_EACH(pNode, pOrderByList) {
|
WHERE_EACH(pNode, pOrderByList) {
|
||||||
SNode* pExpr = ((SOrderByExprNode*)pNode)->pExpr;
|
SNode* pExpr = ((SOrderByExprNode*)pNode)->pExpr;
|
||||||
|
@ -3501,9 +3507,9 @@ static int32_t translateOrderBy(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = checkExprListForGroupBy(pCxt, pSelect, pSelect->pOrderByList);
|
code = checkExprListForGroupBy(pCxt, pSelect, pSelect->pOrderByList);
|
||||||
}
|
}
|
||||||
// if (other && TSDB_CODE_SUCCESS == code) {
|
if (other && TSDB_CODE_SUCCESS == code) {
|
||||||
// code = checkOrderByAggForGroupBy(pCxt, pSelect, pSelect->pOrderByList);
|
code = checkOrderByAggForGroupBy(pCxt, pSelect, pSelect->pOrderByList);
|
||||||
// }
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4505,8 +4511,18 @@ static EDealRes replaceOrderByAliasImpl(SNode** pNode, void* pContext) {
|
||||||
SNode* pProject = NULL;
|
SNode* pProject = NULL;
|
||||||
FOREACH(pProject, pProjectionList) {
|
FOREACH(pProject, pProjectionList) {
|
||||||
SExprNode* pExpr = (SExprNode*)pProject;
|
SExprNode* pExpr = (SExprNode*)pProject;
|
||||||
|
SNode* activeNode = pProject;
|
||||||
if (0 == strcmp(((SColumnRefNode*)*pNode)->colName, pExpr->aliasName)) {
|
if (0 == strcmp(((SColumnRefNode*)*pNode)->colName, pExpr->aliasName)) {
|
||||||
SNode* pNew = nodesCloneNode(pProject);
|
if(QUERY_NODE_FUNCTION == pProject->type && strcmp(((SFunctionNode*)pProject)->functionName, "_select_value") == 0) {
|
||||||
|
SNode* paramNode = NULL;
|
||||||
|
FOREACH(paramNode, ((SFunctionNode*)pProject)->pParameterList) {
|
||||||
|
SExprNode* pExpr2 = (SExprNode*)pProject;
|
||||||
|
if (0 == strcmp(((SColumnRefNode*)*pNode)->colName, pExpr2->aliasName)) {
|
||||||
|
activeNode = paramNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SNode* pNew = nodesCloneNode(activeNode);
|
||||||
if (NULL == pNew) {
|
if (NULL == pNew) {
|
||||||
pCxt->pTranslateCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
|
pCxt->pTranslateCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return DEAL_RES_ERROR;
|
return DEAL_RES_ERROR;
|
||||||
|
|
|
@ -413,6 +413,28 @@ TEST_F(ParserSelectTest, semanticCheck) {
|
||||||
|
|
||||||
run("SELECT c1 FROM t1 order by COUNT(*)", TSDB_CODE_PAR_NOT_SINGLE_GROUP);
|
run("SELECT c1 FROM t1 order by COUNT(*)", TSDB_CODE_PAR_NOT_SINGLE_GROUP);
|
||||||
|
|
||||||
|
run("SELECT COUNT(*) FROM t1 order by COUNT(*)");
|
||||||
|
|
||||||
|
run("SELECT COUNT(*) FROM t1 order by last(c2)");
|
||||||
|
|
||||||
|
run("SELECT c1 FROM t1 order by last(ts)", TSDB_CODE_PAR_NOT_SINGLE_GROUP);
|
||||||
|
|
||||||
|
run("SELECT ts FROM t1 order by last(ts)", TSDB_CODE_PAR_NOT_SINGLE_GROUP);
|
||||||
|
|
||||||
|
run("SELECT c2 FROM t1 order by last(ts)", TSDB_CODE_PAR_NOT_SINGLE_GROUP);
|
||||||
|
|
||||||
|
run("SELECT * FROM t1 order by last(ts)", TSDB_CODE_PAR_NOT_SINGLE_GROUP);
|
||||||
|
|
||||||
|
run("SELECT last(ts) FROM t1 order by last(ts)");
|
||||||
|
|
||||||
|
run("SELECT last(ts), ts, c1 FROM t1 order by last(ts)");
|
||||||
|
|
||||||
|
run("SELECT ts, last(ts) FROM t1 order by last(ts)");
|
||||||
|
|
||||||
|
run("SELECT first(ts), c2 FROM t1 order by last(c1)");
|
||||||
|
|
||||||
|
run("SELECT c1 FROM t1 order by concat(c2, 'abc')");
|
||||||
|
|
||||||
// TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION
|
// TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION
|
||||||
run("SELECT distinct c1, c2 FROM t1 WHERE c1 > 0 order by ts", TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION);
|
run("SELECT distinct c1, c2 FROM t1 WHERE c1 > 0 order by ts", TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION);
|
||||||
|
|
||||||
|
|
|
@ -276,6 +276,14 @@ class TDTestCase:
|
||||||
sql2 = "select count(*) as a, count(c2) as b, max(c2) as c, min(c2) as d, sum(c2) as e from st;"
|
sql2 = "select count(*) as a, count(c2) as b, max(c2) as c, min(c2) as d, sum(c2) as e from st;"
|
||||||
self.queryResultSame(sql1, sql2)
|
self.queryResultSame(sql1, sql2)
|
||||||
|
|
||||||
|
def queryOrderByAgg(self):
|
||||||
|
|
||||||
|
tdSql.error(f"SELECT * FROM t1 order by last(ts)")
|
||||||
|
|
||||||
|
tdSql.query(f"SELECT last(ts) FROM t1 order by last(ts)")
|
||||||
|
|
||||||
|
tdSql.query(f"SELECT last(ts), ts FROM t1 order by last(ts)")
|
||||||
|
|
||||||
# run
|
# run
|
||||||
def run(self):
|
def run(self):
|
||||||
# prepare env
|
# prepare env
|
||||||
|
@ -287,6 +295,9 @@ class TDTestCase:
|
||||||
# advance
|
# advance
|
||||||
self.queryAdvance()
|
self.queryAdvance()
|
||||||
|
|
||||||
|
# agg
|
||||||
|
self.queryOrderByAgg()
|
||||||
|
|
||||||
|
|
||||||
# stop
|
# stop
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
|
Loading…
Reference in New Issue