fix: select failed as using table alias name
This commit is contained in:
parent
10d82a3acf
commit
5a72630b3d
|
@ -3155,6 +3155,31 @@ static bool fromSingleTable(SNode* table) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool IsEqualTbNameFuncNode(SSelectStmt* pSelect, SNode* pFunc1, SNode* pFunc2) {
|
||||||
|
if (isTbnameFuction(pFunc1) && isTbnameFuction(pFunc2)) {
|
||||||
|
SValueNode* pVal1 = (SValueNode*)nodesListGetNode(((SFunctionNode*)pFunc1)->pParameterList, 0);
|
||||||
|
SValueNode* pVal2 = (SValueNode*)nodesListGetNode(((SFunctionNode*)pFunc1)->pParameterList, 0);
|
||||||
|
if (!pVal1 && !pVal2) {
|
||||||
|
return true;
|
||||||
|
} else if (pVal1 && pVal2) {
|
||||||
|
return strcmp(pVal1->literal, pVal2->literal) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pSelect->pFromTable &&
|
||||||
|
(pSelect->pFromTable->type == QUERY_NODE_REAL_TABLE || pSelect->pFromTable->type == QUERY_NODE_TEMP_TABLE)) {
|
||||||
|
STableNode* pTable = (STableNode*)pSelect->pFromTable;
|
||||||
|
if (pVal1) {
|
||||||
|
return strcmp(pTable->tableAlias, pVal1->literal) == 0;
|
||||||
|
} else if (!pVal1) {
|
||||||
|
return strcmp(pTable->tableAlias, pVal2->literal) == 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) {
|
static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) {
|
||||||
STranslateContext* pCxt = (STranslateContext*)pContext;
|
STranslateContext* pCxt = (STranslateContext*)pContext;
|
||||||
SSelectStmt* pSelect = (SSelectStmt*)pCxt->pCurrStmt;
|
SSelectStmt* pSelect = (SSelectStmt*)pCxt->pCurrStmt;
|
||||||
|
@ -3174,6 +3199,9 @@ static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) {
|
||||||
((SColumnNode*)*pNode)->colType == COLUMN_TYPE_TAG) {
|
((SColumnNode*)*pNode)->colType == COLUMN_TYPE_TAG) {
|
||||||
return rewriteExprToGroupKeyFunc(pCxt, pNode);
|
return rewriteExprToGroupKeyFunc(pCxt, pNode);
|
||||||
}
|
}
|
||||||
|
if (IsEqualTbNameFuncNode(pSelect, pActualNode, *pNode)) {
|
||||||
|
return rewriteExprToGroupKeyFunc(pCxt, pNode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SNode* pPartKey = NULL;
|
SNode* pPartKey = NULL;
|
||||||
bool partionByTbname = hasTbnameFunction(pSelect->pPartitionByList);
|
bool partionByTbname = hasTbnameFunction(pSelect->pPartitionByList);
|
||||||
|
@ -3185,6 +3213,9 @@ static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) {
|
||||||
((SColumnNode*)*pNode)->colType == COLUMN_TYPE_TAG) {
|
((SColumnNode*)*pNode)->colType == COLUMN_TYPE_TAG) {
|
||||||
return rewriteExprToGroupKeyFunc(pCxt, pNode);
|
return rewriteExprToGroupKeyFunc(pCxt, pNode);
|
||||||
}
|
}
|
||||||
|
if (IsEqualTbNameFuncNode(pSelect, pPartKey, *pNode)) {
|
||||||
|
return rewriteExprToGroupKeyFunc(pCxt, pNode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (NULL != pSelect->pWindow && QUERY_NODE_STATE_WINDOW == nodeType(pSelect->pWindow)) {
|
if (NULL != pSelect->pWindow && QUERY_NODE_STATE_WINDOW == nodeType(pSelect->pWindow)) {
|
||||||
if (nodesEqualNode(((SStateWindowNode*)pSelect->pWindow)->pExpr, *pNode)) {
|
if (nodesEqualNode(((SStateWindowNode*)pSelect->pWindow)->pExpr, *pNode)) {
|
||||||
|
|
Loading…
Reference in New Issue