fix: SColumnRefNode disable
This commit is contained in:
parent
d243308541
commit
c8fb8486ef
|
@ -531,7 +531,7 @@ int32_t nodesCollectColumnsFromNode(SNode* node, const char* pTableAlias, EColle
|
||||||
|
|
||||||
typedef bool (*FFuncClassifier)(int32_t funcId);
|
typedef bool (*FFuncClassifier)(int32_t funcId);
|
||||||
int32_t nodesCollectFuncs(SSelectStmt* pSelect, ESqlClause clause, char* tableAlias, FFuncClassifier classifier, SNodeList** pFuncs);
|
int32_t nodesCollectFuncs(SSelectStmt* pSelect, ESqlClause clause, char* tableAlias, FFuncClassifier classifier, SNodeList** pFuncs);
|
||||||
int32_t nodesCollectSelectFuncs(SSelectStmt* pSelect, ESqlClause clause, char* tableAlias, FFuncClassifier classifier, SNodeList** pFuncs);
|
int32_t nodesCollectSelectFuncs(SSelectStmt* pSelect, ESqlClause clause, char* tableAlias, FFuncClassifier classifier, SNodeList* pFuncs);
|
||||||
|
|
||||||
int32_t nodesCollectSpecialNodes(SSelectStmt* pSelect, ESqlClause clause, ENodeType type, SNodeList** pNodes);
|
int32_t nodesCollectSpecialNodes(SSelectStmt* pSelect, ESqlClause clause, ENodeType type, SNodeList** pNodes);
|
||||||
|
|
||||||
|
|
|
@ -2161,7 +2161,7 @@ static int32_t funcNodeEqual(const void* pLeft, const void* pRight, size_t len)
|
||||||
return nodesEqualNode(*(const SNode**)pLeft, *(const SNode**)pRight) ? 0 : 1;
|
return nodesEqualNode(*(const SNode**)pLeft, *(const SNode**)pRight) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t nodesCollectSelectFuncs(SSelectStmt* pSelect, ESqlClause clause, char* tableAlias, FFuncClassifier classifier, SNodeList** pFuncs) {
|
int32_t nodesCollectSelectFuncs(SSelectStmt* pSelect, ESqlClause clause, char* tableAlias, FFuncClassifier classifier, SNodeList* pFuncs) {
|
||||||
if (NULL == pSelect || NULL == pFuncs) {
|
if (NULL == pSelect || NULL == pFuncs) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
@ -2169,22 +2169,12 @@ int32_t nodesCollectSelectFuncs(SSelectStmt* pSelect, ESqlClause clause, char* t
|
||||||
SCollectFuncsCxt cxt = {.errCode = TSDB_CODE_SUCCESS,
|
SCollectFuncsCxt cxt = {.errCode = TSDB_CODE_SUCCESS,
|
||||||
.classifier = classifier,
|
.classifier = classifier,
|
||||||
.tableAlias = tableAlias,
|
.tableAlias = tableAlias,
|
||||||
.pFuncs = *pFuncs};
|
.pFuncs = pFuncs};
|
||||||
if (NULL == cxt.pFuncs) {
|
if (NULL == cxt.pFuncs) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
nodesWalkSelectStmt(pSelect, clause, collectFuncs, &cxt);
|
nodesWalkSelectStmt(pSelect, clause, collectFuncs, &cxt);
|
||||||
if (TSDB_CODE_SUCCESS == cxt.errCode) {
|
|
||||||
if (LIST_LENGTH(cxt.pFuncs) > 0) {
|
|
||||||
*pFuncs = cxt.pFuncs;
|
|
||||||
} else {
|
|
||||||
nodesDestroyList(cxt.pFuncs);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
nodesDestroyList(cxt.pFuncs);
|
|
||||||
}
|
|
||||||
|
|
||||||
return cxt.errCode;
|
return cxt.errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1316,7 +1316,7 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode** pCol) {
|
||||||
} else {
|
} else {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
if (SQL_CLAUSE_ORDER_BY == pCxt->currClause) {
|
if (SQL_CLAUSE_ORDER_BY == pCxt->currClause) {
|
||||||
res = translateColumnUseAlias(pCxt, pCol, &found);
|
// res = translateColumnUseAlias(pCxt, pCol, &found);
|
||||||
}
|
}
|
||||||
if (DEAL_RES_ERROR != res && !found) {
|
if (DEAL_RES_ERROR != res && !found) {
|
||||||
if (isSetOperator(pCxt->pCurrStmt)) {
|
if (isSetOperator(pCxt->pCurrStmt)) {
|
||||||
|
@ -2747,12 +2747,10 @@ static EDealRes doCheckAggColCoexist(SNode** pNode, void* pContext) {
|
||||||
static int32_t reCalSelectFuncNum(SSelectStmt* pSelect) {
|
static int32_t reCalSelectFuncNum(SSelectStmt* pSelect) {
|
||||||
pSelect->selectFuncNum = 0;
|
pSelect->selectFuncNum = 0;
|
||||||
SNodeList* pNodeList = nodesMakeList();
|
SNodeList* pNodeList = nodesMakeList();
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = nodesCollectSelectFuncs(pSelect, SQL_CLAUSE_FROM, NULL, fmIsSelectFunc, pNodeList);
|
||||||
for (ESqlClause clause = SQL_CLAUSE_FROM; clause < SQL_CLAUSE_ORDER_BY; clause++) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
code = nodesCollectSelectFuncs(pSelect, clause, NULL, fmIsSelectFunc, &pNodeList);
|
nodesDestroyList(pNodeList);
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
return code;
|
||||||
return code;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
SNode* pNode = NULL;
|
SNode* pNode = NULL;
|
||||||
FOREACH(pNode, pNodeList) {
|
FOREACH(pNode, pNodeList) {
|
||||||
|
@ -4525,14 +4523,34 @@ typedef struct SReplaceOrderByAliasCxt {
|
||||||
|
|
||||||
static EDealRes replaceOrderByAliasImpl(SNode** pNode, void* pContext) {
|
static EDealRes replaceOrderByAliasImpl(SNode** pNode, void* pContext) {
|
||||||
SReplaceOrderByAliasCxt* pCxt = pContext;
|
SReplaceOrderByAliasCxt* pCxt = pContext;
|
||||||
if (QUERY_NODE_COLUMN_REF == nodeType(*pNode)) {
|
SNodeList* pProjectionList = pCxt->pProjectionList;
|
||||||
SNodeList* pProjectionList = pCxt->pProjectionList;
|
SNode* pProject = NULL;
|
||||||
SNode* pProject = NULL;
|
if (QUERY_NODE_COLUMN == nodeType(*pNode)) {
|
||||||
FOREACH(pProject, pProjectionList) {
|
FOREACH(pProject, pProjectionList) {
|
||||||
SExprNode* pExpr = (SExprNode*)pProject;
|
SExprNode* pExpr = (SExprNode*)pProject;
|
||||||
SNode* activeNode = pProject;
|
if (0 == strcmp(((SColumnRefNode*)*pNode)->colName, pExpr->userAlias)) {
|
||||||
if (0 == strcmp(((SColumnRefNode*)*pNode)->colName, pExpr->aliasName)) {
|
SNode* pNew = nodesCloneNode(pProject);
|
||||||
SNode* pNew = nodesCloneNode(activeNode);
|
if (NULL == pNew) {
|
||||||
|
pCxt->pTranslateCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return DEAL_RES_ERROR;
|
||||||
|
}
|
||||||
|
((SExprNode*)pNew)->orderAlias = true;
|
||||||
|
nodesDestroyNode(*pNode);
|
||||||
|
*pNode = pNew;
|
||||||
|
return DEAL_RES_CONTINUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (QUERY_NODE_ORDER_BY_EXPR == nodeType(*pNode)) {
|
||||||
|
STranslateContext* pTransCxt = pCxt->pTranslateCxt;
|
||||||
|
SNode* pExpr = ((SOrderByExprNode*)*pNode)->pExpr;
|
||||||
|
if (QUERY_NODE_VALUE == nodeType(pExpr)) {
|
||||||
|
SValueNode* pVal = (SValueNode*)pExpr;
|
||||||
|
if (DEAL_RES_ERROR == translateValue(pTransCxt, pVal)) {
|
||||||
|
return pTransCxt->errCode;
|
||||||
|
}
|
||||||
|
int32_t pos = getPositionValue(pVal);
|
||||||
|
if ( 0 < pos && pos <= LIST_LENGTH(pProjectionList)) {
|
||||||
|
SNode* pNew = nodesCloneNode(nodesListGetNode(pProjectionList, pos - 1));
|
||||||
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;
|
||||||
|
@ -4544,6 +4562,7 @@ static EDealRes replaceOrderByAliasImpl(SNode** pNode, void* pContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue