enhance: pseduo column coverted to column when necessary
This commit is contained in:
parent
6496bb3d31
commit
6ad518d61d
|
@ -1571,25 +1571,6 @@ static int32_t translateAggFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t translateScanPseudoColumnFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
|
||||||
if (!fmIsScanPseudoColumnFunc(pFunc->funcId)) {
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
if (0 == LIST_LENGTH(pFunc->pParameterList)) {
|
|
||||||
if (!isSelectStmt(pCxt->pCurrStmt) || NULL == ((SSelectStmt*)pCxt->pCurrStmt)->pFromTable) {
|
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TBNAME);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
SValueNode* pVal = (SValueNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
|
||||||
STableNode* pTable = NULL;
|
|
||||||
pCxt->errCode = findTable(pCxt, pVal->literal, &pTable);
|
|
||||||
if (TSDB_CODE_SUCCESS == pCxt->errCode && (NULL == pTable || QUERY_NODE_REAL_TABLE != nodeType(pTable))) {
|
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TBNAME);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t translateIndefiniteRowsFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
static int32_t translateIndefiniteRowsFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||||
if (!fmIsIndefiniteRowsFunc(pFunc->funcId)) {
|
if (!fmIsIndefiniteRowsFunc(pFunc->funcId)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -1726,20 +1707,6 @@ static int32_t translateForbidFillFunc(STranslateContext* pCxt, SFunctionNode* p
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t translateWindowPseudoColumnFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
|
||||||
if (!fmIsWindowPseudoColumnFunc(pFunc->funcId)) {
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
if (!isSelectStmt(pCxt->pCurrStmt) || NULL == ((SSelectStmt*)pCxt->pCurrStmt)->pWindow) {
|
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_WINDOW_PC);
|
|
||||||
}
|
|
||||||
if (beforeWindow(pCxt->currClause)) {
|
|
||||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_WINDOW_PC, "There mustn't be %s",
|
|
||||||
pFunc->functionName);
|
|
||||||
}
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t translateForbidStreamFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
static int32_t translateForbidStreamFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||||
if (!fmIsForbidStreamFunc(pFunc->funcId)) {
|
if (!fmIsForbidStreamFunc(pFunc->funcId)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -1978,10 +1945,65 @@ static int32_t rewriteSystemInfoFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||||
return TSDB_CODE_PAR_INTERNAL_ERROR;
|
return TSDB_CODE_PAR_INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t translateNormalFunction(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
static int32_t replacePsedudoColumnFuncWithColumn(STranslateContext* pCxt, SNode** ppNode) {
|
||||||
|
SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
|
||||||
|
if (pCol == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
SExprNode* pOldExpr = (SExprNode*)(*ppNode);
|
||||||
|
pCol->node.resType = pOldExpr->resType;
|
||||||
|
strcpy(pCol->node.aliasName, pOldExpr->aliasName);
|
||||||
|
strcpy(pCol->node.userAlias, pOldExpr->userAlias);
|
||||||
|
strcpy(pCol->colName, pOldExpr->aliasName);
|
||||||
|
|
||||||
|
nodesDestroyNode(*ppNode);
|
||||||
|
*ppNode = (SNode*)pCol;
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateWindowPseudoColumnFunc2(STranslateContext* pCxt, SNode** ppNode) {
|
||||||
|
SFunctionNode* pFunc = (SFunctionNode*)(*ppNode);
|
||||||
|
if (!isSelectStmt(pCxt->pCurrStmt)) {
|
||||||
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_WINDOW_PC);
|
||||||
|
}
|
||||||
|
if (((SSelectStmt*)pCxt->pCurrStmt)->pWindow && beforeWindow(pCxt->currClause)) {
|
||||||
|
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_WINDOW_PC, "There mustn't be %s",
|
||||||
|
pFunc->functionName);
|
||||||
|
}
|
||||||
|
if (NULL == ((SSelectStmt*)pCxt->pCurrStmt)->pWindow) {
|
||||||
|
replacePsedudoColumnFuncWithColumn(pCxt, ppNode);
|
||||||
|
return translateColumn(pCxt, (SColumnNode**)ppNode);
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateScanPseudoColumnFunc2(STranslateContext* pCxt, SNode** ppNode) {
|
||||||
|
SFunctionNode* pFunc = (SFunctionNode*)(*ppNode);
|
||||||
|
if (0 == LIST_LENGTH(pFunc->pParameterList)) {
|
||||||
|
if (!isSelectStmt(pCxt->pCurrStmt) || NULL == ((SSelectStmt*)pCxt->pCurrStmt)->pFromTable) {
|
||||||
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TBNAME);
|
||||||
|
}
|
||||||
|
if (QUERY_NODE_REAL_TABLE != nodeType(((SSelectStmt*)pCxt->pCurrStmt)->pFromTable)) {
|
||||||
|
replacePsedudoColumnFuncWithColumn(pCxt, ppNode);
|
||||||
|
return translateColumn(pCxt, (SColumnNode**)ppNode);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SValueNode* pVal = (SValueNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
||||||
|
STableNode* pTable = NULL;
|
||||||
|
pCxt->errCode = findTable(pCxt, pVal->literal, &pTable);
|
||||||
|
if (TSDB_CODE_SUCCESS == pCxt->errCode && (NULL == pTable || QUERY_NODE_REAL_TABLE != nodeType(pTable))) {
|
||||||
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TBNAME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateNormalFunction(STranslateContext* pCxt, SNode** ppNode) {
|
||||||
|
SFunctionNode* pFunc = (SFunctionNode*)(*ppNode);
|
||||||
int32_t code = translateAggFunc(pCxt, pFunc);
|
int32_t code = translateAggFunc(pCxt, pFunc);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = translateScanPseudoColumnFunc(pCxt, pFunc);
|
code = translateScanPseudoColumnFunc2(pCxt, ppNode);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = translateIndefiniteRowsFunc(pCxt, pFunc);
|
code = translateIndefiniteRowsFunc(pCxt, pFunc);
|
||||||
|
@ -1990,7 +2012,7 @@ static int32_t translateNormalFunction(STranslateContext* pCxt, SFunctionNode* p
|
||||||
code = translateForbidFillFunc(pCxt, pFunc);
|
code = translateForbidFillFunc(pCxt, pFunc);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = translateWindowPseudoColumnFunc(pCxt, pFunc);
|
code = translateWindowPseudoColumnFunc2(pCxt, ppNode);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = translateForbidStreamFunc(pCxt, pFunc);
|
code = translateForbidStreamFunc(pCxt, pFunc);
|
||||||
|
@ -2082,7 +2104,7 @@ static int32_t translateFunctionImpl(STranslateContext* pCxt, SFunctionNode** pF
|
||||||
if (fmIsClientPseudoColumnFunc((*pFunc)->funcId)) {
|
if (fmIsClientPseudoColumnFunc((*pFunc)->funcId)) {
|
||||||
return rewriteClientPseudoColumnFunc(pCxt, (SNode**)pFunc);
|
return rewriteClientPseudoColumnFunc(pCxt, (SNode**)pFunc);
|
||||||
}
|
}
|
||||||
return translateNormalFunction(pCxt, *pFunc);
|
return translateNormalFunction(pCxt, (SNode**)pFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode** pFunc) {
|
static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode** pFunc) {
|
||||||
|
|
Loading…
Reference in New Issue