提交 b4bba7ee 编写于 作者: H Haojun Liao

[td-10564] Refactor the sql function parse procedure.

上级 f80294fc
......@@ -182,8 +182,8 @@ typedef struct tExprNode {
struct SVariant *pVal; // value node
struct {// function node
char *functionName;
int32_t functionId;
char functionName[FUNCTIONS_NAME_MAX_LENGTH];
// int32_t functionId;
int32_t num;
// Note that the attribute of pChild is not the parameter of function, it is the columns that involved in the
......
......@@ -175,7 +175,7 @@ typedef struct SSourceParam {
int32_t num;
} SSourceParam;
SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, int16_t functionId, SSourceParam* pSource, SSchema* pResSchema, int16_t interSize);
SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, const char* funcName, SSourceParam* pSource, SSchema* pResSchema, int16_t interSize);
int32_t copyExprInfoList(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy);
STableMetaInfo* getMetaInfo(SQueryStmtInfo* pQueryInfo, int32_t tableIndex);
......
......@@ -162,7 +162,7 @@ int64_t genQueryId(void) {
static int32_t getExprFunctionId(SExprInfo *pExprInfo) {
assert(pExprInfo != NULL && pExprInfo->pExpr != NULL && pExprInfo->pExpr->nodeType == TEXPR_UNARYEXPR_NODE);
return pExprInfo->pExpr->_function.functionId;
return 0;
}
static void getNextTimeWindow(SQueryAttr* pQueryAttr, STimeWindow* tw) {
......
......@@ -4810,7 +4810,7 @@ SAggFunctionInfo aggFunc[35] = {{
},
{
// 33
"_block_dist", // return table id and the corresponding tags for join match and subscribe
"block_dist", // return table id and the corresponding tags for join match and subscribe
FUNCTION_TYPE_AGG,
FUNCTION_BLKINFO,
FUNCTION_BLKINFO,
......
......@@ -544,7 +544,7 @@ struct SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfOutput, co
pFillCol[i].col.colId = pExprInfo->base.resSchema.colId;
pFillCol[i].tagIndex = -2;
pFillCol[i].flag = pExprInfo->base.pColumns->flag; // always be the normal column for table query
pFillCol[i].functionId = pExprInfo->pExpr->_function.functionId;
// pFillCol[i].functionId = pExprInfo->pExpr->_function.functionId;
pFillCol[i].fillVal.i = fillVal[i];
offset += pExprInfo->base.resSchema.bytes;
......
......@@ -43,7 +43,7 @@ void addExprInfoParam(SSqlExpr* pExpr, char* argument, int32_t type, int32
void cleanupFieldInfo(SFieldInfo* pFieldInfo);
STableComInfo getTableInfo(const STableMeta* pTableMeta);
SArray* extractFunctionIdList(SArray* pExprInfoList);
SArray *extractFunctionList(SArray* pExprInfoList);
#ifdef __cplusplus
}
......
......@@ -1709,9 +1709,9 @@ void setResultColName(char* name, tSqlExprItem* pItem, SToken* pToken, SToken* f
}
SExprInfo* doAddOneExprInfo(SQueryStmtInfo* pQueryInfo, int16_t functionId, SSourceParam* pSourceParam, int32_t outputIndex,
SExprInfo* doAddOneExprInfo(SQueryStmtInfo* pQueryInfo, const char* funcName, SSourceParam* pSourceParam, int32_t outputIndex,
STableMetaInfo* pTableMetaInfo, SSchema* pResultSchema, int32_t interSize, const char* token, bool finalResult) {
SExprInfo* pExpr = createExprInfo(pTableMetaInfo, functionId, pSourceParam, pResultSchema, interSize);
SExprInfo* pExpr = createExprInfo(pTableMetaInfo, funcName, pSourceParam, pResultSchema, interSize);
SArray* pExprList = getCurrentExprList(pQueryInfo);
addExprInfo(pExprList, outputIndex, pExpr, pQueryInfo->exprListLevelIndex);
......@@ -2978,8 +2978,8 @@ int32_t sqlExprToExprNode(tExprNode **pExpr, const tSqlExpr* pSqlExpr, SQuerySt
(*pExpr)->nodeType = TEXPR_FUNCTION_NODE;
(*pExpr)->_function.pChild = p;
(*pExpr)->_function.functionId = functionId;
(*pExpr)->_function.functionName = strndup(pSqlExpr->Expr.operand.z, pSqlExpr->Expr.operand.n);
// (*pExpr)->_function.functionId = functionId;
strncpy((*pExpr)->_function.functionName, pSqlExpr->Expr.operand.z, pSqlExpr->Expr.operand.n);
return TSDB_CODE_SUCCESS;
} else {
printf("agg function found, %s\n", pSqlExpr->exprToken.z);
......@@ -3826,7 +3826,7 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQuer
validateSqlNode(p, pQueryInfo, &buf);
}
SArray* functionList = extractFunctionIdList(pQueryInfo->exprList[0]);
SArray* functionList = extractFunctionList(pQueryInfo->exprList[0]);
extractFunctionDesc(functionList, &pQueryInfo->info);
if ((code = checkForInvalidExpr(pQueryInfo, &buf)) != TSDB_CODE_SUCCESS) {
......
......@@ -61,7 +61,7 @@ SSchema* getTableTagSchema(const STableMeta* pTableMeta) {
return getOneColumnSchema(pTableMeta, getTableInfo(pTableMeta).numOfColumns);
}
static tExprNode* createFunctionExprNode(int32_t functionId, struct SSourceParam *pParam) {//SSchema* pSchema, tExprNode* pColumnNode, int32_t numOfCols) {
static tExprNode* createFunctionExprNode(const char* funcName, struct SSourceParam *pParam) {
tExprNode** p = malloc(pParam->num * POINTER_BYTES);
if (pParam->pColumnList != NULL) {
......@@ -81,7 +81,7 @@ static tExprNode* createFunctionExprNode(int32_t functionId, struct SSourceParam
tExprNode* pNode = calloc(1, sizeof(tExprNode));
pNode->nodeType = TEXPR_FUNCTION_NODE;
pNode->_function.functionId = functionId;
tstrncpy(pNode->_function.functionName, funcName, tListLen(pNode->_function.functionName));
pNode->_function.pChild = p;
pNode->_function.num = pParam->num;
......@@ -101,7 +101,7 @@ SExprInfo* createBinaryExprInfo(tExprNode* pNode, SSchema* pResSchema) {
return pExpr;
}
SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, int16_t functionId, SSourceParam* pSourceParam, SSchema* pResSchema, int16_t interSize) {
SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, const char* funcName, SSourceParam* pSourceParam, SSchema* pResSchema, int16_t interSize) {
SExprInfo* pExpr = calloc(1, sizeof(SExprInfo));
if (pExpr == NULL) {
return NULL;
......@@ -120,7 +120,7 @@ SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, int16_t functionId, SS
memcpy(&p->resSchema, pResSchema, sizeof(SSchema));
if (pSourceParam->pExprNodeList != NULL) {
pExpr->pExpr = createFunctionExprNode(functionId, pSourceParam);
pExpr->pExpr = createFunctionExprNode(funcName, pSourceParam);
return pExpr;
}
......@@ -131,16 +131,16 @@ SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, int16_t functionId, SS
SSchema* s = getTbnameColumnSchema();
setColumn(p->pColumns, uid, pTableMetaInfo->aliasName, TSDB_COL_TAG, s);
pExpr->pExpr = createFunctionExprNode(functionId, pSourceParam);
} else if (TSDB_COL_IS_UD_COL(pCol->flag) || functionId == FUNCTION_BLKINFO) {
pExpr->pExpr = createFunctionExprNode(funcName, pSourceParam);
} else if (TSDB_COL_IS_UD_COL(pCol->flag) || strcmp(funcName, "block_dist") == 0) {
setColumn(p->pColumns, uid, pTableMetaInfo->aliasName, TSDB_COL_UDC, pResSchema);
pExpr->pExpr = createFunctionExprNode(functionId, pSourceParam);
pExpr->pExpr = createFunctionExprNode(funcName, pSourceParam);
} else {
for(int32_t i = 0; i < pSourceParam->num; ++i) {
SColumn* c = taosArrayGetP(pSourceParam->pColumnList, i);
p->pColumns[i] = *c;
}
pExpr->pExpr = createFunctionExprNode(functionId, pSourceParam);
pExpr->pExpr = createFunctionExprNode(funcName, pSourceParam);
}
return pExpr;
......@@ -156,14 +156,13 @@ void addExprInfo(SArray* pExprList, int32_t index, SExprInfo* pExprInfo, int32_t
taosArrayInsert(pExprList, index, &pExprInfo);
}
printf("add function, id:%d, level:%d, total:%ld\n", pExprInfo->pExpr->_function.functionId, level, taosArrayGetSize(pExprList));
printf("add function, id:%s, level:%d, total:%ld\n", pExprInfo->pExpr->_function.functionName, level, taosArrayGetSize(pExprList));
}
void updateExprInfo(SExprInfo* pExprInfo, int16_t functionId, int32_t colId, int16_t srcColumnIndex, int16_t resType, int16_t resSize) {
assert(pExprInfo != NULL);
SSqlExpr* pse = &pExprInfo->base;
pExprInfo->pExpr->_function.functionId = functionId;
assert(0);
pse->resSchema.type = resType;
......@@ -172,7 +171,7 @@ void updateExprInfo(SExprInfo* pExprInfo, int16_t functionId, int32_t colId, int
SExprInfo* getExprInfo(SQueryStmtInfo* pQueryInfo, int32_t index) {
assert(pQueryInfo != NULL && pQueryInfo->exprList && index >= 0);
return taosArrayGetP(pQueryInfo->exprList, index);
return taosArrayGetP(getCurrentExprList(pQueryInfo->exprList), index);
}
void destroyExprInfo(SExprInfo* pExprInfo) {
......@@ -214,7 +213,7 @@ void addExprInfoParam(SSqlExpr* pExpr, char* argument, int32_t type, int32_t byt
int32_t getExprFunctionId(SExprInfo *pExprInfo) {
assert(pExprInfo != NULL && pExprInfo->pExpr != NULL && pExprInfo->pExpr->nodeType == TEXPR_UNARYEXPR_NODE);
return pExprInfo->pExpr->_function.functionId;
return 0;
}
void assignExprInfo(SExprInfo* dst, const SExprInfo* src) {
......@@ -310,14 +309,14 @@ int32_t getResRowLength(SArray* pExprList) {
return size;
}
SArray* extractFunctionIdList(SArray* pExprInfoList) {
SArray* extractFunctionList(SArray* pExprInfoList) {
assert(pExprInfoList != NULL);
size_t len = taosArrayGetSize(pExprInfoList);
SArray* p = taosArrayInit(len, sizeof(int32_t));
for(int32_t i = 0; i < len; ++i) {
SExprInfo* pExprInfo = taosArrayGetP(pExprInfoList, i);
taosArrayPush(p, &pExprInfo->pExpr->_function.functionId);
taosArrayPush(p, &pExprInfo->pExpr->_function.functionName);
}
return p;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册