fix: pass basic test
This commit is contained in:
parent
80f77251b2
commit
9bb628650c
|
@ -124,6 +124,7 @@ int32_t nodesListStrictAppendList(SNodeList* pTarget, SNodeList* pSrc);
|
||||||
int32_t nodesListPushFront(SNodeList* pList, SNode* pNode);
|
int32_t nodesListPushFront(SNodeList* pList, SNode* pNode);
|
||||||
SListCell* nodesListErase(SNodeList* pList, SListCell* pCell);
|
SListCell* nodesListErase(SNodeList* pList, SListCell* pCell);
|
||||||
void nodesListInsertList(SNodeList* pTarget, SListCell* pPos, SNodeList* pSrc);
|
void nodesListInsertList(SNodeList* pTarget, SListCell* pPos, SNodeList* pSrc);
|
||||||
|
void nodesListInsertListAfterPos(SNodeList* pTarget, SListCell* pPos, SNodeList* pSrc);
|
||||||
SNode* nodesListGetNode(SNodeList* pList, int32_t index);
|
SNode* nodesListGetNode(SNodeList* pList, int32_t index);
|
||||||
SListCell* nodesListGetCell(SNodeList* pList, int32_t index);
|
SListCell* nodesListGetCell(SNodeList* pList, int32_t index);
|
||||||
void nodesDestroyList(SNodeList* pList);
|
void nodesDestroyList(SNodeList* pList);
|
||||||
|
|
|
@ -1595,6 +1595,26 @@ void nodesListInsertList(SNodeList* pTarget, SListCell* pPos, SNodeList* pSrc) {
|
||||||
nodesFree(pSrc);
|
nodesFree(pSrc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void nodesListInsertListAfterPos(SNodeList* pTarget, SListCell* pPos, SNodeList* pSrc) {
|
||||||
|
if (NULL == pTarget || NULL == pPos || NULL == pSrc || NULL == pSrc->pHead) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NULL == pPos->pNext) {
|
||||||
|
pTarget->pTail = pSrc->pHead;
|
||||||
|
} else {
|
||||||
|
pPos->pNext->pPrev = pSrc->pHead;
|
||||||
|
}
|
||||||
|
|
||||||
|
pSrc->pHead->pPrev = pPos;
|
||||||
|
pSrc->pTail->pNext = pPos->pNext;
|
||||||
|
|
||||||
|
pPos->pNext = pSrc->pHead;
|
||||||
|
|
||||||
|
pTarget->length += pSrc->length;
|
||||||
|
nodesFree(pSrc);
|
||||||
|
}
|
||||||
|
|
||||||
SNode* nodesListGetNode(SNodeList* pList, int32_t index) {
|
SNode* nodesListGetNode(SNodeList* pList, int32_t index) {
|
||||||
SNode* node;
|
SNode* node;
|
||||||
FOREACH(node, pList) {
|
FOREACH(node, pList) {
|
||||||
|
|
|
@ -3034,7 +3034,7 @@ static void biMakeAliasNameInMD5(char* pExprStr, int32_t len, char* pAlias) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SNode* biMakeTbnameProjectionNode(char* funcName, char* tableAlias) {
|
static SNode* biMakeTbnameProjectAstNode(char* funcName, char* tableAlias) {
|
||||||
SValueNode* val = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
SValueNode* val = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||||
val->literal = strdup(tableAlias);
|
val->literal = strdup(tableAlias);
|
||||||
val->node.resType.type = TSDB_DATA_TYPE_BINARY;
|
val->node.resType.type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
@ -3045,18 +3045,18 @@ static SNode* biMakeTbnameProjectionNode(char* funcName, char* tableAlias) {
|
||||||
SNodeList* paramList = nodesMakeList();
|
SNodeList* paramList = nodesMakeList();
|
||||||
nodesListAppend(paramList, (SNode*)val);
|
nodesListAppend(paramList, (SNode*)val);
|
||||||
|
|
||||||
SFunctionNode* tbNamefunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
SFunctionNode* tbNameFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||||
strncpy(tbNamefunc->functionName, "tbname", strlen("tbname"));
|
strncpy(tbNameFunc->functionName, "tbname", strlen("tbname"));
|
||||||
nodesListMakeAppend(&tbNamefunc->pParameterList, (SNode*)val);
|
nodesListMakeAppend(&tbNameFunc->pParameterList, (SNode*)val);
|
||||||
|
|
||||||
snprintf(tbNamefunc->node.userAlias, sizeof(tbNamefunc->node.userAlias), "%s.tbname", tableAlias);
|
snprintf(tbNameFunc->node.userAlias, sizeof(tbNameFunc->node.userAlias), "%s.tbname", tableAlias);
|
||||||
biMakeAliasNameInMD5(tbNamefunc->node.userAlias, strlen(tbNamefunc->node.userAlias), tbNamefunc->node.aliasName);
|
biMakeAliasNameInMD5(tbNameFunc->node.userAlias, strlen(tbNameFunc->node.userAlias), tbNameFunc->node.aliasName);
|
||||||
if (funcName == NULL) {
|
if (funcName == NULL) {
|
||||||
return (SNode*)tbNamefunc;
|
return (SNode*)tbNameFunc;
|
||||||
} else {
|
} else {
|
||||||
SFunctionNode* multiResFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
SFunctionNode* multiResFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||||
strncpy(multiResFunc->functionName, funcName, strlen(funcName));
|
strncpy(multiResFunc->functionName, funcName, strlen(funcName));
|
||||||
nodesListMakeAppend(&multiResFunc->pParameterList, (SNode*)tbNamefunc);
|
nodesListMakeAppend(&multiResFunc->pParameterList, (SNode*)tbNameFunc);
|
||||||
|
|
||||||
snprintf(multiResFunc->node.userAlias, sizeof(multiResFunc->node.userAlias), "%s(%s.tbname)", funcName, tableAlias);
|
snprintf(multiResFunc->node.userAlias, sizeof(multiResFunc->node.userAlias), "%s(%s.tbname)", funcName, tableAlias);
|
||||||
biMakeAliasNameInMD5(multiResFunc->node.userAlias, strlen(multiResFunc->node.userAlias), multiResFunc->node.aliasName);
|
biMakeAliasNameInMD5(multiResFunc->node.userAlias, strlen(multiResFunc->node.userAlias), multiResFunc->node.aliasName);
|
||||||
|
@ -3068,7 +3068,9 @@ static int32_t biRewriteSelectFuncParamStar(STranslateContext* pCxt, SSelectStmt
|
||||||
SNodeList* pTbnameNodeList = nodesMakeList();
|
SNodeList* pTbnameNodeList = nodesMakeList();
|
||||||
|
|
||||||
SFunctionNode* pFunc = (SFunctionNode*)pNode;
|
SFunctionNode* pFunc = (SFunctionNode*)pNode;
|
||||||
if (pFunc->funcType == FUNCTION_TYPE_LAST || pFunc->funcType == FUNCTION_TYPE_LAST_ROW || pFunc->funcType == FUNCTION_TYPE_FIRST) {
|
if (strcasecmp(pFunc->functionName, "last") == 0 ||
|
||||||
|
strcasecmp(pFunc->functionName, "last_row") == 0 ||
|
||||||
|
strcasecmp(pFunc->functionName, "first") == 0) {
|
||||||
SNodeList* pParams = pFunc->pParameterList;
|
SNodeList* pParams = pFunc->pParameterList;
|
||||||
SNode* pPara = NULL;
|
SNode* pPara = NULL;
|
||||||
FOREACH(pPara, pParams) {
|
FOREACH(pPara, pParams) {
|
||||||
|
@ -3077,15 +3079,15 @@ static int32_t biRewriteSelectFuncParamStar(STranslateContext* pCxt, SSelectStmt
|
||||||
size_t n = taosArrayGetSize(pTables);
|
size_t n = taosArrayGetSize(pTables);
|
||||||
for (int32_t i = 0; i < n; ++i) {
|
for (int32_t i = 0; i < n; ++i) {
|
||||||
STableNode* pTable = taosArrayGetP(pTables, i);
|
STableNode* pTable = taosArrayGetP(pTables, i);
|
||||||
SNode* pTbnameNode = biMakeTbnameProjectionNode(pFunc->functionName, pTable->tableAlias);
|
SNode* pTbnameNode = biMakeTbnameProjectAstNode(pFunc->functionName, pTable->tableAlias);
|
||||||
nodesListAppend(pTbnameNodeList, pTbnameNode);
|
nodesListAppend(pTbnameNodeList, pTbnameNode);
|
||||||
}
|
}
|
||||||
nodesListInsertList(pSelect->pProjectionList, pSelectListCell, pTbnameNodeList);
|
nodesListInsertListAfterPos(pSelect->pProjectionList, pSelectListCell, pTbnameNodeList);
|
||||||
} else if (isTableStar(pPara)) {
|
} else if (isTableStar(pPara)) {
|
||||||
char* pTableAlias = ((SColumnNode*)pPara)->tableAlias;
|
char* pTableAlias = ((SColumnNode*)pPara)->tableAlias;
|
||||||
SNode* pTbnameNode = biMakeTbnameProjectionNode(pFunc->functionName, pTableAlias);
|
SNode* pTbnameNode = biMakeTbnameProjectAstNode(pFunc->functionName, pTableAlias);
|
||||||
nodesListAppend(pTbnameNodeList, pTbnameNode);
|
nodesListAppend(pTbnameNodeList, pTbnameNode);
|
||||||
nodesListInsertList(pSelect->pProjectionList, pSelectListCell, pTbnameNodeList);
|
nodesListInsertListAfterPos(pSelect->pProjectionList, pSelectListCell, pTbnameNodeList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3103,16 +3105,16 @@ static int32_t biRewriteSelectStar(STranslateContext* pCxt, SSelectStmt* pSelect
|
||||||
size_t n = taosArrayGetSize(pTables);
|
size_t n = taosArrayGetSize(pTables);
|
||||||
for (int32_t i = 0; i < n; ++i) {
|
for (int32_t i = 0; i < n; ++i) {
|
||||||
STableNode* pTable = taosArrayGetP(pTables, i);
|
STableNode* pTable = taosArrayGetP(pTables, i);
|
||||||
SNode* pTbnameNode = biMakeTbnameProjectionNode(NULL, pTable->tableAlias);
|
SNode* pTbnameNode = biMakeTbnameProjectAstNode(NULL, pTable->tableAlias);
|
||||||
nodesListAppend(pTbnameNodeList, pTbnameNode);
|
nodesListAppend(pTbnameNodeList, pTbnameNode);
|
||||||
}
|
}
|
||||||
INSERT_LIST(pSelect->pProjectionList, pTbnameNodeList);
|
nodesListInsertListAfterPos(pSelect->pProjectionList, cell, pTbnameNodeList);
|
||||||
} else if (isTableStar(pNode)) {
|
} else if (isTableStar(pNode)) {
|
||||||
char* pTableAlias = ((SColumnNode*)pNode)->tableAlias;
|
char* pTableAlias = ((SColumnNode*)pNode)->tableAlias;
|
||||||
SNode* pTbnameNode = biMakeTbnameProjectionNode(NULL, pTableAlias);
|
SNode* pTbnameNode = biMakeTbnameProjectAstNode(NULL, pTableAlias);
|
||||||
nodesListAppend(pTbnameNodeList, pTbnameNode);
|
nodesListAppend(pTbnameNodeList, pTbnameNode);
|
||||||
INSERT_LIST(pSelect->pProjectionList, pTbnameNodeList);
|
nodesListInsertListAfterPos(pSelect->pProjectionList, cell, pTbnameNodeList);
|
||||||
} else if (isMultiResFunc(pNode)) {
|
} else if (nodeType(pNode) == QUERY_NODE_FUNCTION) {
|
||||||
biRewriteSelectFuncParamStar(pCxt, pSelect, pNode, cell);
|
biRewriteSelectFuncParamStar(pCxt, pSelect, pNode, cell);
|
||||||
}
|
}
|
||||||
WHERE_NEXT;
|
WHERE_NEXT;
|
||||||
|
|
Loading…
Reference in New Issue