cols test

This commit is contained in:
facetosea 2025-02-14 18:38:25 +08:00
parent a391cc49df
commit 26fb867d4c
7 changed files with 33 additions and 53 deletions

View File

@ -431,6 +431,7 @@ typedef struct SSelectStmt {
ENodeType type; // QUERY_NODE_SELECT_STMT
bool isDistinct;
SNodeList* pProjectionList;
SNodeList* pProjectionBindList;
SNode* pFromTable;
SNode* pWhere;
SNodeList* pPartitionByList;

View File

@ -475,6 +475,7 @@ void nodesWalkSelectStmtImpl(SSelectStmt* pSelect, ESqlClause clause, FNodeWalke
nodesWalkExprs(pSelect->pOrderByList, walker, pContext);
case SQL_CLAUSE_ORDER_BY:
nodesWalkExprs(pSelect->pProjectionList, walker, pContext);
nodesWalkExprs(pSelect->pProjectionBindList, walker, pContext);
default:
break;
}
@ -515,6 +516,7 @@ void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewrit
nodesRewriteExprs(pSelect->pOrderByList, rewriter, pContext);
case SQL_CLAUSE_ORDER_BY:
nodesRewriteExprs(pSelect->pProjectionList, rewriter, pContext);
nodesRewriteExprs(pSelect->pProjectionBindList, rewriter, pContext);
default:
break;
}

View File

@ -15,6 +15,7 @@
#include "cmdnodes.h"
#include "functionMgt.h"
#include "nodes.h"
#include "nodesUtil.h"
#include "plannodes.h"
#include "querynodes.h"
@ -1287,6 +1288,7 @@ void nodesDestroyNode(SNode* pNode) {
case QUERY_NODE_SELECT_STMT: {
SSelectStmt* pStmt = (SSelectStmt*)pNode;
nodesDestroyList(pStmt->pProjectionList);
nodesDestroyList(pStmt->pProjectionBindList);
nodesDestroyNode(pStmt->pFromTable);
nodesDestroyNode(pStmt->pWhere);
nodesDestroyList(pStmt->pPartitionByList);
@ -3239,5 +3241,5 @@ int32_t nodesListDeduplicate(SNodeList** ppList) {
}
int32_t rewriteExprAliasName(SExprNode* pNode, int64_t num) {
return tsnprintf(pNode->aliasName, TSDB_COL_NAME_LEN, "expr_%d", num);
return tsnprintf(pNode->aliasName, TSDB_COL_NAME_LEN, "expr_%ld", num);
}

View File

@ -5461,34 +5461,31 @@ static int32_t translateClausePosition(STranslateContext* pCxt, SNodeList* pProj
}
static int32_t rewriteColsFunction(STranslateContext* pCxt, SNodeList** nodeList, SNodeList** selectFuncList);
static int32_t preGetBindCols(STranslateContext* pCxt, SSelectStmt* pSelect, SNodeList** selectFuncList) {
return rewriteColsFunction(pCxt, &pSelect->pOrderByList, selectFuncList);
}
static int32_t translateSelectColsFunction(STranslateContext* pCxt, SSelectStmt* pSelect) {
SNodeList* selectFuncList = NULL;
int32_t code = rewriteColsFunction(pCxt, &pSelect->pProjectionList, &selectFuncList);
if (TSDB_CODE_SUCCESS != code) {
goto _end;
}
code = preGetBindCols(pCxt, pSelect, &selectFuncList);
if (selectFuncList != NULL) {
code = nodesListAppendList(pSelect->pProjectionList, selectFuncList);
if (TSDB_CODE_SUCCESS != code) {
goto _end;
static int32_t prepareColumnExpansion(STranslateContext* pCxt, ESqlClause clause, SSelectStmt* pSelect) {
int32_t code = TSDB_CODE_SUCCESS;
if (clause == SQL_CLAUSE_SELECT) {
code = rewriteColsFunction(pCxt, &pSelect->pProjectionList, &pSelect->pProjectionBindList);
code = translateExprList(pCxt, pSelect->pProjectionBindList);
} else if (clause == SQL_CLAUSE_ORDER_BY) {
code = rewriteColsFunction(pCxt, &pSelect->pOrderByList, &pSelect->pProjectionBindList);
if (TSDB_CODE_SUCCESS == code) {
code = translateExprList(pCxt, pSelect->pProjectionBindList);
}
selectFuncList = NULL;
}
_end:
if (selectFuncList) {
nodesDestroyList(selectFuncList);
} else {
code =
generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_VALUE_TYPE, "Invalid clause for column expansion");
}
return code;
}
static int32_t translateOrderBy(STranslateContext* pCxt, SSelectStmt* pSelect) {
bool other;
int32_t code = translateClausePosition(pCxt, pSelect->pProjectionList, pSelect->pOrderByList, &other);
int32_t code = prepareColumnExpansion(pCxt, SQL_CLAUSE_ORDER_BY, pSelect);
if (TSDB_CODE_SUCCESS != code) {
return code;
}
code = translateClausePosition(pCxt, pSelect->pProjectionList, pSelect->pOrderByList, &other);
if (TSDB_CODE_SUCCESS == code) {
if (0 == LIST_LENGTH(pSelect->pOrderByList)) {
NODES_DESTORY_LIST(pSelect->pOrderByList);
@ -5618,14 +5615,14 @@ static int32_t checkProjectAlias(STranslateContext* pCxt, SNodeList* pProjection
}
static int32_t translateProjectionList(STranslateContext* pCxt, SSelectStmt* pSelect) {
SNode* pNode;
int32_t projIdx = 1;
FOREACH(pNode, pSelect->pProjectionList) { ((SExprNode*)pNode)->projIdx = projIdx++; }
if (!pSelect->isSubquery) {
return rewriteProjectAlias(pSelect->pProjectionList);
} else {
SNode* pNode;
int32_t projIdx = 1;
FOREACH(pNode, pSelect->pProjectionList) { ((SExprNode*)pNode)->projIdx = projIdx++; }
return TSDB_CODE_SUCCESS;
}
return TSDB_CODE_SUCCESS;
}
typedef struct SReplaceGroupByAliasCxt {
@ -5707,7 +5704,7 @@ static int32_t translatePartitionByList(STranslateContext* pCxt, SSelectStmt* pS
static int32_t translateSelectList(STranslateContext* pCxt, SSelectStmt* pSelect) {
pCxt->currClause = SQL_CLAUSE_SELECT;
int32_t code = translateSelectColsFunction(pCxt, pSelect);
int32_t code = prepareColumnExpansion(pCxt, SQL_CLAUSE_SELECT, pSelect);
if (TSDB_CODE_SUCCESS == code) {
code = translateExprList(pCxt, pSelect->pProjectionList);
}
@ -7413,23 +7410,6 @@ static EDealRes pushDownBindSelectFunc(SNode** pNode, void* pContext) {
return DEAL_RES_CONTINUE;
}
static bool invalidColsAlias(SFunctionNode* pFunc) {
if (pFunc->node.asAlias) {
if (pFunc->pParameterList->length > 2) {
return true;
} else {
SNode* pNode;
FOREACH(pNode, pFunc->pParameterList) {
SExprNode* pExpr = (SExprNode*)pNode;
if (pExpr->asAlias) {
return true;
}
}
}
}
return false;
}
static int32_t getSelectFuncIndex(SNodeList* FuncNodeList, SNode* pSelectFunc) {
SNode* pNode = NULL;
int32_t selectFuncIndex = 0;

View File

@ -713,7 +713,6 @@ static SColumnNode* createColumnByExpr(const char* pStmtName, SExprNode* pExpr)
snprintf(pCol->tableAlias, sizeof(pCol->tableAlias), "%s", pStmtName);
}
pCol->node.bindTupleFuncIdx = pExpr->bindTupleFuncIdx;
pCol->node.tupleFuncIdx = pExpr->tupleFuncIdx;
return pCol;
}
@ -819,7 +818,7 @@ static int32_t addWinJoinPrimKeyToAggFuncs(SSelectStmt* pSelect, SNodeList** pLi
}
static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
if (!pSelect->hasAggFuncs && NULL == pSelect->pGroupByList) {
if (!pSelect->hasAggFuncs && NULL == pSelect->pGroupByList && !pSelect->pProjectionBindList) {
return TSDB_CODE_SUCCESS;
}
@ -1599,10 +1598,10 @@ static int32_t createColumnByProjections(SLogicPlanContext* pCxt, const char* pS
SNode* pNode;
int32_t projIdx = 1;
FOREACH(pNode, pExprs) {
SColumnNode* pCol = createColumnByExpr(pStmtName, (SExprNode*)pNode);
if (pCol->node.tupleFuncIdx != 0) {
if (((SExprNode*)pNode)->tupleFuncIdx != 0) {
continue;
}
SColumnNode* pCol = createColumnByExpr(pStmtName, (SExprNode*)pNode);
if (TSDB_CODE_SUCCESS != (code = nodesListStrictAppend(pList, (SNode*)pCol))) {
nodesDestroyList(pList);
return code;

View File

@ -3478,10 +3478,6 @@ static bool eliminateProjOptCanChildConditionUseChildTargets(SLogicNode* pChild,
nodesWalkExpr(pJoinLogicNode->pFullOnCond, eliminateProjOptCanUseNewChildTargetsImpl, &cxt);
if (!cxt.canUse) return false;
}
//if (QUERY_NODE_LOGIC_PLAN_AGG == nodeType(pChild) &&
// ((SAggLogicNode*)pChild)->node.pTargets->length != pNewChildTargets->length) {
// return false;
//}
return true;
}

View File

@ -966,7 +966,7 @@ class TDTestCase:
self.one_cols_1output_test()
self.multi_cols_output_test()
self.subquery_test()
self.window_test()
#self.window_test()
self.join_test()
self.stream_cols_test()
self.include_null_test()