diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index 3ac357055e..db92285e11 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -163,8 +163,8 @@ int rawBlockBindData(SQuery *query, STableMeta* pTableMeta, void* data, SVCr int numFields, bool needChangeLength, char* errstr, int32_t errstrLen); int32_t rewriteToVnodeModifyOpStmt(SQuery* pQuery, SArray* pBufArray); -SArray* serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap); -SArray* serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap); +int32_t serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap, SArray** pOut); +int32_t serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap, SArray** pOut); void destoryCatalogReq(SCatalogReq *pCatalogReq); bool isPrimaryKeyImpl(SNode* pExpr); int32_t insAppendStmtTableDataCxt(SHashObj* pAllVgHash, STableColsData* pTbData, STableDataCxt* pTbCtx, SStbInterlaceInfo* pBuildInfo); diff --git a/source/client/src/clientRawBlockWrite.c b/source/client/src/clientRawBlockWrite.c index ce404092b0..dd61bd8500 100644 --- a/source/client/src/clientRawBlockWrite.c +++ b/source/client/src/clientRawBlockWrite.c @@ -1116,9 +1116,9 @@ static int32_t taosCreateTable(TAOS* taos, void* meta, int32_t metaLen) { if (taosHashGetSize(pVgroupHashmap) == 0) { goto end; } - SArray* pBufArray = serializeVgroupsCreateTableBatch(pVgroupHashmap); - if (NULL == pBufArray) { - code = TSDB_CODE_OUT_OF_MEMORY; + SArray* pBufArray = NULL; + code = serializeVgroupsCreateTableBatch(pVgroupHashmap, &pBufArray); + if (TSDB_CODE_SUCCESS != code) { goto end; } @@ -1264,9 +1264,9 @@ static int32_t taosDropTable(TAOS* taos, void* meta, int32_t metaLen) { if (taosHashGetSize(pVgroupHashmap) == 0) { goto end; } - SArray* pBufArray = serializeVgroupsDropTableBatch(pVgroupHashmap); - if (NULL == pBufArray) { - code = TSDB_CODE_OUT_OF_MEMORY; + SArray* pBufArray = NULL; + code = serializeVgroupsDropTableBatch(pVgroupHashmap, &pBufArray); + if (TSDB_CODE_SUCCESS != code) { goto end; } diff --git a/source/common/src/tname.c b/source/common/src/tname.c index 4fe2beb6aa..a4d740d427 100644 --- a/source/common/src/tname.c +++ b/source/common/src/tname.c @@ -98,7 +98,7 @@ SName* toName(int32_t acctId, const char* pDbName, const char* pTableName, SName int32_t tNameExtractFullName(const SName* name, char* dst) { // invalid full name format, abort if (!tNameIsValid(name)) { - return -1; + return TSDB_CODE_INVALID_PARA; } int32_t len = snprintf(dst, TSDB_DB_FNAME_LEN, "%d.%s", name->acctId, name->dbname); @@ -154,8 +154,7 @@ int32_t tNameGetDbName(const SName* name, char* dst) { const char* tNameGetDbNameP(const SName* name) { return &name->dbname[0]; } int32_t tNameGetFullDbName(const SName* name, char* dst) { - snprintf(dst, TSDB_DB_FNAME_LEN, "%d.%s", name->acctId, name->dbname); - return 0; + return snprintf(dst, TSDB_DB_FNAME_LEN, "%d.%s", name->acctId, name->dbname); } bool tNameIsEmpty(const SName* name) { return name->type == 0 || name->acctId == 0; } diff --git a/source/libs/parser/inc/parTranslater.h b/source/libs/parser/inc/parTranslater.h index 55ea71a368..99e303e51c 100644 --- a/source/libs/parser/inc/parTranslater.h +++ b/source/libs/parser/inc/parTranslater.h @@ -47,7 +47,7 @@ typedef struct STranslateContext { SNode* pPostRoot; } STranslateContext; -bool biRewriteToTbnameFunc(STranslateContext* pCxt, SNode** ppNode); +int32_t biRewriteToTbnameFunc(STranslateContext* pCxt, SNode** ppNode, bool* pRet); int32_t biRewriteSelectStar(STranslateContext* pCxt, SSelectStmt* pSelect); int32_t biCheckCreateTableTbnameCol(STranslateContext* pCxt, SCreateTableStmt* pStmt); int32_t findTable(STranslateContext* pCxt, const char* pTableAlias, STableNode** pOutput); @@ -57,4 +57,4 @@ int32_t getTargetMetaImpl(SParseContext* pParCxt, SParseMetaCache* pMetaCache, c } #endif -#endif /*_TD_PARSER_TRANS_H_*/ \ No newline at end of file +#endif /*_TD_PARSER_TRANS_H_*/ diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 149e02ad3d..c53180eb87 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -509,7 +509,7 @@ cmd ::= SHOW USERS FULL. cmd ::= SHOW USER PRIVILEGES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USER_PRIVILEGES_STMT); } cmd ::= SHOW db_kind_opt(A) DATABASES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT); - setShowKind(pCxt, pCxt->pRootNode, A); + (void)setShowKind(pCxt, pCxt->pRootNode, A); } cmd ::= SHOW table_kind_db_name_cond_opt(A) TABLES like_pattern_opt(B). { pCxt->pRootNode = createShowTablesStmt(pCxt, A, B, OP_TYPE_LIKE); diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 7c2f504a4f..d61d80a691 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -101,7 +101,7 @@ static bool checkPassword(SAstCreateContext* pCxt, const SToken* pPasswordToken, pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG); } else { strncpy(pPassword, pPasswordToken->z, pPasswordToken->n); - strdequote(pPassword); + (void)strdequote(pPassword); if (strtrim(pPassword) <= 0) { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_PASSWD_EMPTY); } else if (invalidPassword(pPassword)) { @@ -126,8 +126,8 @@ static int32_t parseEndpoint(SAstCreateContext* pCxt, const SToken* pEp, char* p char ep[TSDB_FQDN_LEN + 1 + 5] = {0}; COPY_STRING_FORM_ID_TOKEN(ep, pEp); - strdequote(ep); - strtrim(ep); + (void)strdequote(ep); + (void)strtrim(ep); if (NULL == pPort) { strcpy(pFqdn, ep); return TSDB_CODE_SUCCESS; @@ -371,7 +371,7 @@ SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* val->literal = strndup(pLiteral->z, pLiteral->n); if (TK_NK_ID != pLiteral->type && TK_TIMEZONE != pLiteral->type && (IS_VAR_DATA_TYPE(dataType) || TSDB_DATA_TYPE_TIMESTAMP == dataType)) { - trimString(pLiteral->z, pLiteral->n, val->literal, pLiteral->n); + (void)trimString(pLiteral->z, pLiteral->n, val->literal, pLiteral->n); } CHECK_OUT_OF_MEM(val->literal); val->node.resType.type = dataType; @@ -784,7 +784,10 @@ SNode* createPlaceholderValueNode(SAstCreateContext* pCxt, const SToken* pLitera return NULL; } } - taosArrayPush(pCxt->pPlaceholderValues, &val); + if (NULL == taosArrayPush(pCxt->pPlaceholderValues, &val)) { + pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY; + } + CHECK_PARSER_STATUS(pCxt); return (SNode*)val; } @@ -905,7 +908,8 @@ SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType d } else if (TSDB_DATA_TYPE_NCHAR == dt.type) { func->node.resType.bytes = func->node.resType.bytes * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE; } - nodesListMakeAppend(&func->pParameterList, pExpr); + pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr); + CHECK_PARSER_STATUS(pCxt); return (SNode*)func; } @@ -923,8 +927,10 @@ SNode* createNodeListNodeEx(SAstCreateContext* pCxt, SNode* p1, SNode* p2) { CHECK_OUT_OF_MEM(list); list->pNodeList = nodesMakeList(); CHECK_OUT_OF_MEM(list->pNodeList); - nodesListAppend(list->pNodeList, p1); - nodesListAppend(list->pNodeList, p2); + pCxt->errCode = nodesListAppend(list->pNodeList, p1); + CHECK_PARSER_STATUS(pCxt); + pCxt->errCode = nodesListAppend(list->pNodeList, p2); + CHECK_PARSER_STATUS(pCxt); return (SNode*)list; } @@ -1121,7 +1127,8 @@ SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode) { CHECK_OUT_OF_MEM(groupingSet); groupingSet->groupingSetType = GP_TYPE_NORMAL; groupingSet->pParameterList = nodesMakeList(); - nodesListAppend(groupingSet->pParameterList, pNode); + pCxt->errCode = nodesListAppend(groupingSet->pParameterList, pNode); + CHECK_PARSER_STATUS(pCxt); return (SNode*)groupingSet; } @@ -1842,7 +1849,7 @@ SNode* createCreateSubTableFromFileClause(SAstCreateContext* pCxt, bool ignoreEx pStmt->ignoreExists = ignoreExists; pStmt->pSpecificTags = pSpecificTags; if (TK_NK_STRING == pFilePath->type) { - trimString(pFilePath->z, pFilePath->n, pStmt->filePath, PATH_MAX); + (void)trimString(pFilePath->z, pFilePath->n, pStmt->filePath, PATH_MAX); } else { strncpy(pStmt->filePath, pFilePath->z, pFilePath->n); } @@ -2087,7 +2094,7 @@ SNode* createShowTablesStmt(SAstCreateContext* pCxt, SShowTablesOption option, S pDbName = createIdentifierValueNode(pCxt, &option.dbName); } SNode* pStmt = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, pDbName, pTbName, tableCondType); - setShowKind(pCxt, pStmt, option.kind); + (void)setShowKind(pCxt, pStmt, option.kind); return pStmt; } @@ -2408,9 +2415,9 @@ SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const } else { pStmt->dnodeId = -1; } - trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config)); + (void)trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config)); if (NULL != pValue) { - trimString(pValue->z, pValue->n, pStmt->value, sizeof(pStmt->value)); + (void)trimString(pValue->z, pValue->n, pStmt->value, sizeof(pStmt->value)); } return (SNode*)pStmt; } @@ -2591,9 +2598,9 @@ SNode* createAlterClusterStmt(SAstCreateContext* pCxt, const SToken* pConfig, co CHECK_PARSER_STATUS(pCxt); SAlterClusterStmt* pStmt = (SAlterClusterStmt*)nodesMakeNode(QUERY_NODE_ALTER_CLUSTER_STMT); CHECK_OUT_OF_MEM(pStmt); - trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config)); + (void)trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config)); if (NULL != pValue) { - trimString(pValue->z, pValue->n, pStmt->value, sizeof(pStmt->value)); + (void)trimString(pValue->z, pValue->n, pStmt->value, sizeof(pStmt->value)); } return (SNode*)pStmt; } @@ -2602,9 +2609,9 @@ SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, cons CHECK_PARSER_STATUS(pCxt); SAlterLocalStmt* pStmt = (SAlterLocalStmt*)nodesMakeNode(QUERY_NODE_ALTER_LOCAL_STMT); CHECK_OUT_OF_MEM(pStmt); - trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config)); + (void)trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config)); if (NULL != pValue) { - trimString(pValue->z, pValue->n, pStmt->value, sizeof(pStmt->value)); + (void)trimString(pValue->z, pValue->n, pStmt->value, sizeof(pStmt->value)); } return (SNode*)pStmt; } @@ -2869,7 +2876,7 @@ SNode* createKillQueryStmt(SAstCreateContext* pCxt, const SToken* pQueryId) { CHECK_PARSER_STATUS(pCxt); SKillQueryStmt* pStmt = (SKillQueryStmt*)nodesMakeNode(QUERY_NODE_KILL_QUERY_STMT); CHECK_OUT_OF_MEM(pStmt); - trimString(pQueryId->z, pQueryId->n, pStmt->queryId, sizeof(pStmt->queryId) - 1); + (void)trimString(pQueryId->z, pQueryId->n, pStmt->queryId, sizeof(pStmt->queryId) - 1); return (SNode*)pStmt; } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 9b1c8096aa..210e8d59db 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -384,10 +384,13 @@ static bool hasSameTableAlias(SArray* pTables) { } static int32_t addNamespace(STranslateContext* pCxt, void* pTable) { - size_t currTotalLevel = taosArrayGetSize(pCxt->pNsLevel); + int32_t code = 0; + size_t currTotalLevel = taosArrayGetSize(pCxt->pNsLevel); if (currTotalLevel > pCxt->currLevel) { SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel); - taosArrayPush(pTables, &pTable); + if (NULL == taosArrayPush(pTables, &pTable)) { + return TSDB_CODE_OUT_OF_MEMORY; + } if (hasSameTableAlias(pTables)) { return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_UNIQUE_TABLE_ALIAS, "Not unique table/alias: '%s'", ((STableNode*)pTable)->tableAlias); @@ -399,18 +402,22 @@ static int32_t addNamespace(STranslateContext* pCxt, void* pTable) { return TSDB_CODE_OUT_OF_MEMORY; } if (pCxt->currLevel == currTotalLevel) { - taosArrayPush(pTables, &pTable); + (void)taosArrayPush(pTables, &pTable); if (hasSameTableAlias(pTables)) { - taosArrayDestroy(pTables); + (void)taosArrayDestroy(pTables); return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_UNIQUE_TABLE_ALIAS, "Not unique table/alias: '%s'", ((STableNode*)pTable)->tableAlias); } } - taosArrayPush(pCxt->pNsLevel, &pTables); + if (NULL == taosArrayPush(pCxt->pNsLevel, &pTables)) { + code = TSDB_CODE_OUT_OF_MEMORY; + (void)taosArrayDestroy(pTables); + break; + } ++currTotalLevel; } while (currTotalLevel <= pCxt->currLevel); } - return TSDB_CODE_SUCCESS; + return code; } static int32_t collectUseDatabaseImpl(const char* pFullDbName, SHashObj* pDbs) { @@ -421,13 +428,16 @@ static int32_t collectUseDatabaseImpl(const char* pFullDbName, SHashObj* pDbs) { static int32_t collectUseDatabase(const SName* pName, SHashObj* pDbs) { char dbFName[TSDB_DB_FNAME_LEN] = {0}; - tNameGetFullDbName(pName, dbFName); + (void)tNameGetFullDbName(pName, dbFName); return collectUseDatabaseImpl(dbFName, pDbs); } static int32_t collectUseTable(const SName* pName, SHashObj* pTable) { char fullName[TSDB_TABLE_FNAME_LEN]; - tNameExtractFullName(pName, fullName); + int32_t code = tNameExtractFullName(pName, fullName); + if (TSDB_CODE_SUCCESS != code) { + return code; + } return taosHashPut(pTable, fullName, strlen(fullName), pName, sizeof(SName)); } @@ -537,7 +547,7 @@ static int32_t refreshGetTableMeta(STranslateContext* pCxt, const char* pDbName, STableMeta** pMeta) { SParseContext* pParCxt = pCxt->pParseCxt; SName name; - toName(pCxt->pParseCxt->acctId, pDbName, pTableName, &name); + (void)toName(pCxt->pParseCxt->acctId, pDbName, pTableName, &name); int32_t code = TSDB_CODE_SUCCESS; if (pParCxt->async) { code = getTableMetaFromCache(pCxt->pMetaCache, &name, pMeta); @@ -559,7 +569,7 @@ static int32_t refreshGetTableMeta(STranslateContext* pCxt, const char* pDbName, static int32_t getDBVgInfoImpl(STranslateContext* pCxt, const SName* pName, SArray** pVgInfo) { SParseContext* pParCxt = pCxt->pParseCxt; char fullDbName[TSDB_DB_FNAME_LEN]; - tNameGetFullDbName(pName, fullDbName); + (void)tNameGetFullDbName(pName, fullDbName); int32_t code = collectUseDatabaseImpl(fullDbName, pCxt->pDbs); if (TSDB_CODE_SUCCESS == code) { if (pParCxt->async) { @@ -581,9 +591,10 @@ static int32_t getDBVgInfoImpl(STranslateContext* pCxt, const SName* pName, SArr static int32_t getDBVgInfo(STranslateContext* pCxt, const char* pDbName, SArray** pVgInfo) { SName name; - tNameSetDbName(&name, pCxt->pParseCxt->acctId, pDbName, strlen(pDbName)); + int32_t code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, pDbName, strlen(pDbName)); + if (TSDB_CODE_SUCCESS != code) return code; char dbFname[TSDB_DB_FNAME_LEN] = {0}; - tNameGetFullDbName(&name, dbFname); + (void)tNameGetFullDbName(&name, dbFname); return getDBVgInfoImpl(pCxt, &name, pVgInfo); } @@ -642,10 +653,11 @@ static int32_t getDBCfg(STranslateContext* pCxt, const char* pDbName, SDbCfgInfo SParseContext* pParCxt = pCxt->pParseCxt; SName name; - tNameSetDbName(&name, pCxt->pParseCxt->acctId, pDbName, strlen(pDbName)); + int32_t code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, pDbName, strlen(pDbName)); + if (TSDB_CODE_SUCCESS != code) return code; char dbFname[TSDB_DB_FNAME_LEN] = {0}; - tNameGetFullDbName(&name, dbFname); - int32_t code = collectUseDatabaseImpl(dbFname, pCxt->pDbs); + (void)tNameGetFullDbName(&name, dbFname); + code = collectUseDatabaseImpl(dbFname, pCxt->pDbs); if (TSDB_CODE_SUCCESS == code) { if (pParCxt->async) { code = getDbCfgFromCache(pCxt->pMetaCache, dbFname, pInfo); @@ -801,7 +813,7 @@ static int32_t resetHighLevelTranslateNamespace(STranslateContext* pCxt) { } for (int32_t i = size - 1; i >= pCxt->currLevel; --i) { - taosArrayDestroy(taosArrayGetP(pCxt->pNsLevel, i)); + (void)taosArrayDestroy(taosArrayGetP(pCxt->pNsLevel, i)); } taosArrayPopTailBatch(pCxt->pNsLevel, levelNum); @@ -818,9 +830,9 @@ static int32_t resetTranslateNamespace(STranslateContext* pCxt) { if (NULL != pCxt->pNsLevel) { size_t size = taosArrayGetSize(pCxt->pNsLevel); for (size_t i = 0; i < size; ++i) { - taosArrayDestroy(taosArrayGetP(pCxt->pNsLevel, i)); + (void)taosArrayDestroy(taosArrayGetP(pCxt->pNsLevel, i)); } - taosArrayDestroy(pCxt->pNsLevel); + (void)taosArrayDestroy(pCxt->pNsLevel); } pCxt->pNsLevel = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES); if (NULL == pCxt->pNsLevel) { @@ -833,9 +845,9 @@ static void destroyTranslateContext(STranslateContext* pCxt) { if (NULL != pCxt->pNsLevel) { size_t size = taosArrayGetSize(pCxt->pNsLevel); for (size_t i = 0; i < size; ++i) { - taosArrayDestroy(taosArrayGetP(pCxt->pNsLevel, i)); + (void)taosArrayDestroy(taosArrayGetP(pCxt->pNsLevel, i)); } - taosArrayDestroy(pCxt->pNsLevel); + (void)taosArrayDestroy(pCxt->pNsLevel); } if (NULL != pCxt->pCmdMsg) { @@ -1024,66 +1036,83 @@ static bool isBlockTimeLineAlignedQuery(SNode* pStmt) { return false; } -SNodeList* buildPartitionListFromOrderList(SNodeList* pOrderList, int32_t nodesNum) { +int32_t buildPartitionListFromOrderList(SNodeList* pOrderList, int32_t nodesNum, SNodeList**ppOut) { + *ppOut = NULL; SNodeList* pPartitionList = NULL; SNode* pNode = NULL; if (pOrderList->length <= nodesNum) { - return NULL; + return TSDB_CODE_SUCCESS; } pNode = nodesListGetNode(pOrderList, nodesNum); SOrderByExprNode* pOrder = (SOrderByExprNode*)pNode; if (!isPrimaryKeyImpl(pOrder->pExpr)) { - return NULL; + return TSDB_CODE_SUCCESS; } + int32_t code = 0; for (int32_t i = 0; i < nodesNum; ++i) { pNode = nodesListGetNode(pOrderList, i); pOrder = (SOrderByExprNode*)pNode; - nodesListMakeStrictAppend(&pPartitionList, nodesCloneNode(pOrder->pExpr)); + code = nodesListMakeStrictAppend(&pPartitionList, nodesCloneNode(pOrder->pExpr)); + if (TSDB_CODE_SUCCESS != code) { + break; + } } + if(TSDB_CODE_SUCCESS == code) + *ppOut = pPartitionList; - return pPartitionList; + return code; } -static bool isTimeLineAlignedQuery(SNode* pStmt) { +static int32_t isTimeLineAlignedQuery(SNode* pStmt, bool* pRes) { + int32_t code = TSDB_CODE_SUCCESS; SSelectStmt* pSelect = (SSelectStmt*)pStmt; if (!isTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery)) { - return false; + *pRes = false; + return code; } if (QUERY_NODE_SELECT_STMT == nodeType(((STempTableNode*)pSelect->pFromTable)->pSubquery)) { SSelectStmt* pSub = (SSelectStmt*)((STempTableNode*)pSelect->pFromTable)->pSubquery; if (pSelect->pPartitionByList) { if (!pSub->timeLineFromOrderBy && nodesListMatch(pSelect->pPartitionByList, pSub->pPartitionByList)) { - return true; + *pRes = true; + return code; } if (pSub->timeLineFromOrderBy && pSub->pOrderByList->length > 1) { - SNodeList* pPartitionList = - buildPartitionListFromOrderList(pSub->pOrderByList, pSelect->pPartitionByList->length); - bool match = nodesListMatch(pSelect->pPartitionByList, pPartitionList); - nodesDestroyList(pPartitionList); + SNodeList* pPartitionList = NULL; + code = buildPartitionListFromOrderList(pSub->pOrderByList, pSelect->pPartitionByList->length, &pPartitionList); + if (TSDB_CODE_SUCCESS == code) { + bool match = nodesListMatch(pSelect->pPartitionByList, pPartitionList); + nodesDestroyList(pPartitionList); - if (match) { - return true; + if (match) { + *pRes = true; + return code; + } } } } } - if (QUERY_NODE_SET_OPERATOR == nodeType(((STempTableNode*)pSelect->pFromTable)->pSubquery)) { + if (TSDB_CODE_SUCCESS == code && QUERY_NODE_SET_OPERATOR == nodeType(((STempTableNode*)pSelect->pFromTable)->pSubquery)) { SSetOperator* pSub = (SSetOperator*)((STempTableNode*)pSelect->pFromTable)->pSubquery; if (pSelect->pPartitionByList && pSub->timeLineFromOrderBy && pSub->pOrderByList->length > 1) { - SNodeList* pPartitionList = - buildPartitionListFromOrderList(pSub->pOrderByList, pSelect->pPartitionByList->length); - bool match = nodesListMatch(pSelect->pPartitionByList, pPartitionList); - nodesDestroyList(pPartitionList); + SNodeList* pPartitionList = NULL; + code = buildPartitionListFromOrderList(pSub->pOrderByList, pSelect->pPartitionByList->length, &pPartitionList); + if (TSDB_CODE_SUCCESS == code) { + bool match = nodesListMatch(pSelect->pPartitionByList, pPartitionList); + nodesDestroyList(pPartitionList); - if (match) { - return true; + if (match) { + *pRes = true; + return code; + } } } } - return false; + *pRes = false; + return code; } bool isPrimaryKeyImpl(SNode* pExpr) { @@ -1159,16 +1188,17 @@ static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* p pCol->numOfPKs = pTable->pMeta->tableInfo.numOfPKs; } -static void setColumnInfoByExpr(STempTableNode* pTable, SExprNode* pExpr, SColumnNode** pColRef) { +static int32_t setColumnInfoByExpr(STempTableNode* pTable, SExprNode* pExpr, SColumnNode** pColRef) { SColumnNode* pCol = *pColRef; if (NULL == pExpr->pAssociation) { pExpr->pAssociation = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SAssociationNode)); + if (!pExpr->pAssociation) return TSDB_CODE_OUT_OF_MEMORY; } SAssociationNode assNode; assNode.pPlace = (SNode**)pColRef; assNode.pAssociationNode = (SNode*)*pColRef; - taosArrayPush(pExpr->pAssociation, &assNode); + (void)taosArrayPush(pExpr->pAssociation, &assNode); strcpy(pCol->tableAlias, pTable->table.tableAlias); pCol->isPrimTs = isPrimaryKeyImpl((SNode*)pExpr); @@ -1186,6 +1216,7 @@ static void setColumnInfoByExpr(STempTableNode* pTable, SExprNode* pExpr, SColum strcpy(pCol->node.userAlias, pExpr->userAlias); } pCol->node.resType = pExpr->resType; + return TSDB_CODE_SUCCESS; } static void setColumnPrimTs(STranslateContext* pCxt, SColumnNode* pCol, const STableNode* pTable) { @@ -1230,6 +1261,7 @@ static void setColumnPrimTs(STranslateContext* pCxt, SColumnNode* pCol, const ST } static int32_t createColumnsByTable(STranslateContext* pCxt, const STableNode* pTable, bool igTags, SNodeList* pList) { + int32_t code = 0; if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) { const STableMeta* pMeta = ((SRealTableNode*)pTable)->pMeta; int32_t nums = pMeta->tableInfo.numOfColumns + @@ -1245,7 +1277,7 @@ static int32_t createColumnsByTable(STranslateContext* pCxt, const STableNode* p } setColumnInfoBySchema((SRealTableNode*)pTable, pMeta->schema + i, (i - pMeta->tableInfo.numOfColumns), pCol); setColumnPrimTs(pCxt, pCol, pTable); - nodesListAppend(pList, (SNode*)pCol); + code = nodesListStrictAppend(pList, (SNode*)pCol); } } else { STempTableNode* pTempTable = (STempTableNode*)pTable; @@ -1256,12 +1288,15 @@ static int32_t createColumnsByTable(STranslateContext* pCxt, const STableNode* p if (NULL == pCol) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY); } - nodesListAppend(pList, (SNode*)pCol); - SListCell* pCell = nodesListGetCell(pList, LIST_LENGTH(pList) - 1); - setColumnInfoByExpr(pTempTable, (SExprNode*)pNode, (SColumnNode**)&pCell->pNode); + code = nodesListStrictAppend(pList, (SNode*)pCol); + if (TSDB_CODE_SUCCESS == code) { + SListCell* pCell = nodesListGetCell(pList, LIST_LENGTH(pList) - 1); + code = setColumnInfoByExpr(pTempTable, (SExprNode*)pNode, (SColumnNode**)&pCell->pNode); + } + if (TSDB_CODE_SUCCESS != code) break; } } - return TSDB_CODE_SUCCESS; + return code; } static bool isInternalPrimaryKey(const SColumnNode* pCol) { @@ -1294,6 +1329,7 @@ static int32_t findAndSetColumn(STranslateContext* pCxt, SColumnNode** pColRef, } } + int32_t code = 0; if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) { const STableMeta* pMeta = ((SRealTableNode*)pTable)->pMeta; if (isInternalPrimaryKey(pCol)) { @@ -1326,16 +1362,20 @@ static int32_t findAndSetColumn(STranslateContext* pCxt, SColumnNode** pColRef, if (*pFound) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_AMBIGUOUS_COLUMN, pCol->colName); } - setColumnInfoByExpr(pTempTable, pExpr, pColRef); + code = setColumnInfoByExpr(pTempTable, pExpr, pColRef); + if (TSDB_CODE_SUCCESS != code) { + break; + } *pFound = true; } else if (isPrimaryKeyImpl(pNode) && isInternalPrimaryKey(pCol)) { - setColumnInfoByExpr(pTempTable, pExpr, pColRef); + code = setColumnInfoByExpr(pTempTable, pExpr, pColRef); + if (TSDB_CODE_SUCCESS != code) break; pCol->isPrimTs = true; *pFound = true; } } } - return TSDB_CODE_SUCCESS; + return code; } static EDealRes translateColumnWithPrefix(STranslateContext* pCxt, SColumnNode** pCol) { @@ -1441,11 +1481,17 @@ static void biMakeAliasNameInMD5(char* pExprStr, int32_t len, char* pAlias) { } } -static SNode* biMakeTbnameProjectAstNode(char* funcName, char* tableAlias) { +static int32_t biMakeTbnameProjectAstNode(char* funcName, char* tableAlias, SNode** pOutNode) { + int32_t code = 0; SValueNode* valNode = NULL; if (tableAlias != NULL) { SValueNode* n = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); + if (!n) return TSDB_CODE_OUT_OF_MEMORY; n->literal = tstrdup(tableAlias); + if (!n->literal) { + nodesDestroyNode((SNode*)n); + return TSDB_CODE_OUT_OF_MEMORY; + } n->node.resType.type = TSDB_DATA_TYPE_BINARY; n->node.resType.bytes = strlen(n->literal); n->translate = false; @@ -1453,39 +1499,63 @@ static SNode* biMakeTbnameProjectAstNode(char* funcName, char* tableAlias) { } SFunctionNode* tbNameFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); - tstrncpy(tbNameFunc->functionName, "tbname", TSDB_FUNC_NAME_LEN); - if (valNode != NULL) { - nodesListMakeAppend(&tbNameFunc->pParameterList, (SNode*)valNode); + if (!tbNameFunc) { + nodesDestroyNode((SNode*)valNode); + valNode = NULL; + code = TSDB_CODE_OUT_OF_MEMORY; } - snprintf(tbNameFunc->node.userAlias, sizeof(tbNameFunc->node.userAlias), (tableAlias) ? "%s.tbname" : "%stbname", - (tableAlias) ? tableAlias : ""); - strncpy(tbNameFunc->node.aliasName, tbNameFunc->functionName, TSDB_COL_NAME_LEN); - - if (funcName == NULL) { - return (SNode*)tbNameFunc; - } else { - SFunctionNode* multiResFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); - tstrncpy(multiResFunc->functionName, funcName, TSDB_FUNC_NAME_LEN); - nodesListMakeAppend(&multiResFunc->pParameterList, (SNode*)tbNameFunc); - - if (tsKeepColumnName) { - snprintf(multiResFunc->node.userAlias, sizeof(tbNameFunc->node.userAlias), - (tableAlias) ? "%s.tbname" : "%stbname", (tableAlias) ? tableAlias : ""); - strcpy(multiResFunc->node.aliasName, tbNameFunc->functionName); - } else { - snprintf(multiResFunc->node.userAlias, sizeof(multiResFunc->node.userAlias), - tableAlias ? "%s(%s.tbname)" : "%s(%stbname)", funcName, tableAlias ? tableAlias : ""); - biMakeAliasNameInMD5(multiResFunc->node.userAlias, strlen(multiResFunc->node.userAlias), - multiResFunc->node.aliasName); + if (TSDB_CODE_SUCCESS == code) { + tstrncpy(tbNameFunc->functionName, "tbname", TSDB_FUNC_NAME_LEN); + if (valNode != NULL) { + code = nodesListMakeStrictAppend(&tbNameFunc->pParameterList, (SNode*)valNode); + valNode = NULL; } - - return (SNode*)multiResFunc; } + if (TSDB_CODE_SUCCESS == code) { + snprintf(tbNameFunc->node.userAlias, sizeof(tbNameFunc->node.userAlias), (tableAlias) ? "%s.tbname" : "%stbname", + (tableAlias) ? tableAlias : ""); + strncpy(tbNameFunc->node.aliasName, tbNameFunc->functionName, TSDB_COL_NAME_LEN); + if (funcName == NULL) { + *pOutNode = (SNode*)tbNameFunc; + return code; + } else { + SFunctionNode* multiResFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); + if (!multiResFunc) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + + if (TSDB_CODE_SUCCESS == code) { + tstrncpy(multiResFunc->functionName, funcName, TSDB_FUNC_NAME_LEN); + code = nodesListMakeStrictAppend(&multiResFunc->pParameterList, (SNode*)tbNameFunc); + if (TSDB_CODE_SUCCESS != code) tbNameFunc = NULL; + } + + if (TSDB_CODE_SUCCESS == code) { + if (tsKeepColumnName) { + snprintf(multiResFunc->node.userAlias, sizeof(tbNameFunc->node.userAlias), + (tableAlias) ? "%s.tbname" : "%stbname", (tableAlias) ? tableAlias : ""); + strcpy(multiResFunc->node.aliasName, tbNameFunc->functionName); + } else { + snprintf(multiResFunc->node.userAlias, sizeof(multiResFunc->node.userAlias), + tableAlias ? "%s(%s.tbname)" : "%s(%stbname)", funcName, tableAlias ? tableAlias : ""); + biMakeAliasNameInMD5(multiResFunc->node.userAlias, strlen(multiResFunc->node.userAlias), + multiResFunc->node.aliasName); + } + *pOutNode = (SNode*)multiResFunc; + } else { + nodesDestroyNode((SNode*)multiResFunc); + } + } + } + if (TSDB_CODE_SUCCESS != code) nodesDestroyNode((SNode*)tbNameFunc); + return code; } static int32_t biRewriteSelectFuncParamStar(STranslateContext* pCxt, SSelectStmt* pSelect, SNode* pNode, SListCell* pSelectListCell) { SNodeList* pTbnameNodeList = nodesMakeList(); + if (!pTbnameNodeList) return TSDB_CODE_OUT_OF_MEMORY; + int32_t code = 0; SFunctionNode* pFunc = (SFunctionNode*)pNode; if (strcasecmp(pFunc->functionName, "last") == 0 || strcasecmp(pFunc->functionName, "last_row") == 0 || @@ -1496,16 +1566,19 @@ static int32_t biRewriteSelectFuncParamStar(STranslateContext* pCxt, SSelectStmt if (nodesIsStar(pPara)) { SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel); size_t n = taosArrayGetSize(pTables); - for (int32_t i = 0; i < n; ++i) { + for (int32_t i = 0; i < n && TSDB_CODE_SUCCESS == code; ++i) { STableNode* pTable = taosArrayGetP(pTables, i); if (nodeType(pTable) == QUERY_NODE_REAL_TABLE && ((SRealTableNode*)pTable)->pMeta != NULL && ((SRealTableNode*)pTable)->pMeta->tableType == TSDB_SUPER_TABLE) { - SNode* pTbnameNode = biMakeTbnameProjectAstNode(pFunc->functionName, NULL); - nodesListAppend(pTbnameNodeList, pTbnameNode); + SNode* pTbnameNode = NULL; + code = biMakeTbnameProjectAstNode(pFunc->functionName, NULL, &pTbnameNode); + if (TSDB_CODE_SUCCESS == code) + code = nodesListStrictAppend(pTbnameNodeList, pTbnameNode); } } - if (LIST_LENGTH(pTbnameNodeList) > 0) { + if (TSDB_CODE_SUCCESS == code && LIST_LENGTH(pTbnameNodeList) > 0) { nodesListInsertListAfterPos(pSelect->pProjectionList, pSelectListCell, pTbnameNodeList); + pTbnameNodeList = NULL; } } else if (nodesIsTableStar(pPara)) { char* pTableAlias = ((SColumnNode*)pPara)->tableAlias; @@ -1514,37 +1587,47 @@ static int32_t biRewriteSelectFuncParamStar(STranslateContext* pCxt, SSelectStmt if (TSDB_CODE_SUCCESS == code && nodeType(pTable) == QUERY_NODE_REAL_TABLE && ((SRealTableNode*)pTable)->pMeta != NULL && ((SRealTableNode*)pTable)->pMeta->tableType == TSDB_SUPER_TABLE) { - SNode* pTbnameNode = biMakeTbnameProjectAstNode(pFunc->functionName, pTableAlias); - nodesListAppend(pTbnameNodeList, pTbnameNode); + SNode* pTbnameNode = NULL; + code = biMakeTbnameProjectAstNode(pFunc->functionName, pTableAlias, &pTbnameNode); + if (TSDB_CODE_SUCCESS == code) + code = nodesListStrictAppend(pTbnameNodeList, pTbnameNode); } - if (LIST_LENGTH(pTbnameNodeList) > 0) { + if (TSDB_CODE_SUCCESS == code && LIST_LENGTH(pTbnameNodeList) > 0) { nodesListInsertListAfterPos(pSelect->pProjectionList, pSelectListCell, pTbnameNodeList); + pTbnameNodeList = NULL; } } + if (TSDB_CODE_SUCCESS != code) break; } } - return TSDB_CODE_SUCCESS; + nodesDestroyList(pTbnameNodeList); + return code; } // after translate from // before translate select list int32_t biRewriteSelectStar(STranslateContext* pCxt, SSelectStmt* pSelect) { + int32_t code = TSDB_CODE_SUCCESS; SNode* pNode = NULL; SNodeList* pTbnameNodeList = nodesMakeList(); + if (!pTbnameNodeList) return TSDB_CODE_OUT_OF_MEMORY; WHERE_EACH(pNode, pSelect->pProjectionList) { if (nodesIsStar(pNode)) { SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel); size_t n = taosArrayGetSize(pTables); - for (int32_t i = 0; i < n; ++i) { + for (int32_t i = 0; i < n && TSDB_CODE_SUCCESS == code; ++i) { STableNode* pTable = taosArrayGetP(pTables, i); if (nodeType(pTable) == QUERY_NODE_REAL_TABLE && ((SRealTableNode*)pTable)->pMeta != NULL && ((SRealTableNode*)pTable)->pMeta->tableType == TSDB_SUPER_TABLE) { - SNode* pTbnameNode = biMakeTbnameProjectAstNode(NULL, NULL); - nodesListAppend(pTbnameNodeList, pTbnameNode); + SNode* pTbnameNode = NULL; + code = biMakeTbnameProjectAstNode(NULL, NULL, &pTbnameNode); + if (TSDB_CODE_SUCCESS == code) + code = nodesListStrictAppend(pTbnameNodeList, pTbnameNode); } } - if (LIST_LENGTH(pTbnameNodeList) > 0) { + if (TSDB_CODE_SUCCESS == code && LIST_LENGTH(pTbnameNodeList) > 0) { nodesListInsertListAfterPos(pSelect->pProjectionList, cell, pTbnameNodeList); + pTbnameNodeList = NULL; } } else if (nodesIsTableStar(pNode)) { char* pTableAlias = ((SColumnNode*)pNode)->tableAlias; @@ -1552,38 +1635,46 @@ int32_t biRewriteSelectStar(STranslateContext* pCxt, SSelectStmt* pSelect) { int32_t code = findTable(pCxt, pTableAlias, &pTable); if (TSDB_CODE_SUCCESS == code && nodeType(pTable) == QUERY_NODE_REAL_TABLE && ((SRealTableNode*)pTable)->pMeta != NULL && ((SRealTableNode*)pTable)->pMeta->tableType == TSDB_SUPER_TABLE) { - SNode* pTbnameNode = biMakeTbnameProjectAstNode(NULL, pTableAlias); - nodesListAppend(pTbnameNodeList, pTbnameNode); + SNode* pTbnameNode = NULL; + code = biMakeTbnameProjectAstNode(NULL, pTableAlias, &pTbnameNode); + if (TSDB_CODE_SUCCESS ==code) + code = nodesListStrictAppend(pTbnameNodeList, pTbnameNode); } - if (LIST_LENGTH(pTbnameNodeList) > 0) { + if (TSDB_CODE_SUCCESS == code && LIST_LENGTH(pTbnameNodeList) > 0) { nodesListInsertListAfterPos(pSelect->pProjectionList, cell, pTbnameNodeList); + pTbnameNodeList = NULL; } } else if (nodeType(pNode) == QUERY_NODE_FUNCTION) { - biRewriteSelectFuncParamStar(pCxt, pSelect, pNode, cell); + code = biRewriteSelectFuncParamStar(pCxt, pSelect, pNode, cell); } + if (TSDB_CODE_SUCCESS != code) break; WHERE_NEXT; } + nodesDestroyList(pTbnameNodeList); - return TSDB_CODE_SUCCESS; + return code; } -bool biRewriteToTbnameFunc(STranslateContext* pCxt, SNode** ppNode) { +int32_t biRewriteToTbnameFunc(STranslateContext* pCxt, SNode** ppNode, bool* pRet) { SColumnNode* pCol = (SColumnNode*)(*ppNode); if ((strcasecmp(pCol->colName, "tbname") == 0) && ((SSelectStmt*)pCxt->pCurrStmt)->pFromTable && QUERY_NODE_REAL_TABLE == nodeType(((SSelectStmt*)pCxt->pCurrStmt)->pFromTable)) { SFunctionNode* tbnameFuncNode = NULL; - tbnameFuncNode = - (SFunctionNode*)biMakeTbnameProjectAstNode(NULL, (pCol->tableAlias[0] != '\0') ? pCol->tableAlias : NULL); + int32_t code = biMakeTbnameProjectAstNode(NULL, (pCol->tableAlias[0] != '\0') ? pCol->tableAlias : NULL, + (SNode**)&tbnameFuncNode); + if (TSDB_CODE_SUCCESS != code) return code; tbnameFuncNode->node.resType = pCol->node.resType; strcpy(tbnameFuncNode->node.aliasName, pCol->node.aliasName); strcpy(tbnameFuncNode->node.userAlias, pCol->node.userAlias); nodesDestroyNode(*ppNode); *ppNode = (SNode*)tbnameFuncNode; - return true; + *pRet = true; + return TSDB_CODE_SUCCESS; } - return false; + *pRet = false; + return TSDB_CODE_SUCCESS; } int32_t biCheckCreateTableTbnameCol(STranslateContext* pCxt, SCreateTableStmt* pStmt) { @@ -1625,7 +1716,10 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode** pCol) { if (pCxt->pParseCxt->biMode) { SNode** ppNode = (SNode**)pCol; - if (biRewriteToTbnameFunc(pCxt, ppNode)) { + bool ret; + pCxt->errCode = biRewriteToTbnameFunc(pCxt, ppNode, &ret); + if (TSDB_CODE_SUCCESS != pCxt->errCode) return DEAL_RES_ERROR; + if (ret) { return translateFunction(pCxt, (SFunctionNode**)ppNode); } } @@ -2034,9 +2128,9 @@ static int32_t rewriteCountStarAsCount1(STranslateContext* pCxt, SFunctionNode* pVal->node.resType.type = TSDB_DATA_TYPE_INT; pVal->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_INT].bytes; const int32_t val = 1; - nodesSetValueNodeValue(pVal, (void*)&val); + (void)nodesSetValueNodeValue(pVal, (void*)&val); pVal->translate = true; - nodesListErase(pCount->pParameterList, nodesListGetCell(pCount->pParameterList, 0)); + (void)nodesListErase(pCount->pParameterList, nodesListGetCell(pCount->pParameterList, 0)); code = nodesListAppend(pCount->pParameterList, (SNode*)pVal); return code; } @@ -2292,7 +2386,7 @@ static int32_t translateInterpPseudoColumnFunc(STranslateContext* pCxt, SNode** if (code != TSDB_CODE_SUCCESS) { return code; } - translateColumn(pCxt, (SColumnNode**)ppNode); + (void)translateColumn(pCxt, (SColumnNode**)ppNode); return pCxt->errCode; } return TSDB_CODE_SUCCESS; @@ -2307,11 +2401,17 @@ static int32_t translateTimelineFunc(STranslateContext* pCxt, SFunctionNode* pFu "%s function must be used in select statements", pFunc->functionName); } SSelectStmt* pSelect = (SSelectStmt*)pCxt->pCurrStmt; + bool isTimelineAlignedQuery = false; if ((NULL != pSelect->pFromTable && QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) && - !isGlobalTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery) && - !isTimeLineAlignedQuery(pCxt->pCurrStmt)) || - (NULL != pSelect->pFromTable && QUERY_NODE_JOIN_TABLE == nodeType(pSelect->pFromTable) && - (TIME_LINE_GLOBAL != pSelect->timeLineCurMode && TIME_LINE_MULTI != pSelect->timeLineCurMode))) { + !isGlobalTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery))) { + int32_t code = isTimeLineAlignedQuery(pCxt->pCurrStmt, &isTimelineAlignedQuery); + if (TSDB_CODE_SUCCESS != code) return code; + if (!isTimelineAlignedQuery) + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC, + "%s function requires valid time series input", pFunc->functionName); + } + if (NULL != pSelect->pFromTable && QUERY_NODE_JOIN_TABLE == nodeType(pSelect->pFromTable) && + (TIME_LINE_GLOBAL != pSelect->timeLineCurMode && TIME_LINE_MULTI != pSelect->timeLineCurMode)) { return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC, "%s function requires valid time series input", pFunc->functionName); } @@ -2494,7 +2594,7 @@ static void setFuncClassification(SNode* pCurrStmt, SFunctionNode* pFunc) { } } -static int32_t rewriteFuncToValue(STranslateContext* pCxt, char* pLiteral, SNode** pNode) { +static int32_t rewriteFuncToValue(STranslateContext* pCxt, char** pLiteral, SNode** pNode) { SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); if (NULL == pVal) { return TSDB_CODE_OUT_OF_MEMORY; @@ -2502,13 +2602,14 @@ static int32_t rewriteFuncToValue(STranslateContext* pCxt, char* pLiteral, SNode strcpy(pVal->node.aliasName, ((SExprNode*)*pNode)->aliasName); strcpy(pVal->node.userAlias, ((SExprNode*)*pNode)->userAlias); pVal->node.resType = ((SExprNode*)*pNode)->resType; - if (NULL == pLiteral) { + if (NULL == pLiteral || NULL == *pLiteral) { pVal->isNull = true; } else { - pVal->literal = pLiteral; + pVal->literal = *pLiteral; if (IS_VAR_DATA_TYPE(pVal->node.resType.type)) { - pVal->node.resType.bytes = strlen(pLiteral); + pVal->node.resType.bytes = strlen(*pLiteral); } + *pLiteral = NULL; } if (DEAL_RES_ERROR != translateValue(pCxt, pVal)) { nodesDestroyNode(*pNode); @@ -2527,7 +2628,9 @@ static int32_t rewriteDatabaseFunc(STranslateContext* pCxt, SNode** pNode) { return TSDB_CODE_OUT_OF_MEMORY; } } - return rewriteFuncToValue(pCxt, pCurrDb, pNode); + int32_t code = rewriteFuncToValue(pCxt, &pCurrDb, pNode); + if (TSDB_CODE_SUCCESS != code) taosMemoryFree(pCurrDb); + return code; } static int32_t rewriteClentVersionFunc(STranslateContext* pCxt, SNode** pNode) { @@ -2535,7 +2638,9 @@ static int32_t rewriteClentVersionFunc(STranslateContext* pCxt, SNode** pNode) { if (NULL == pVer) { return TSDB_CODE_OUT_OF_MEMORY; } - return rewriteFuncToValue(pCxt, pVer, pNode); + int32_t code = rewriteFuncToValue(pCxt, &pVer, pNode); + if (TSDB_CODE_SUCCESS != code) taosMemoryFree(pVer); + return code; } static int32_t rewriteServerVersionFunc(STranslateContext* pCxt, SNode** pNode) { @@ -2543,7 +2648,9 @@ static int32_t rewriteServerVersionFunc(STranslateContext* pCxt, SNode** pNode) if (NULL == pVer) { return TSDB_CODE_OUT_OF_MEMORY; } - return rewriteFuncToValue(pCxt, pVer, pNode); + int32_t code = rewriteFuncToValue(pCxt, &pVer, pNode); + if (TSDB_CODE_SUCCESS != code) taosMemoryFree(pVer); + return code; } static int32_t rewriteServerStatusFunc(STranslateContext* pCxt, SNode** pNode) { @@ -2551,18 +2658,26 @@ static int32_t rewriteServerStatusFunc(STranslateContext* pCxt, SNode** pNode) { return TSDB_CODE_RPC_NETWORK_UNAVAIL; } char* pStatus = taosStrdup((void*)"1"); - return rewriteFuncToValue(pCxt, pStatus, pNode); + int32_t code = rewriteFuncToValue(pCxt, &pStatus, pNode); + if (TSDB_CODE_SUCCESS != code) taosMemoryFree(pStatus); + return code; } static int32_t rewriteUserFunc(STranslateContext* pCxt, SNode** pNode) { char userConn[TSDB_USER_LEN + 1 + TSDB_FQDN_LEN] = {0}; // format 'user@host' int32_t len = snprintf(userConn, sizeof(userConn), "%s@", pCxt->pParseCxt->pUser); - taosGetFqdn(userConn + len); + if (TSDB_CODE_SUCCESS != taosGetFqdn(userConn + len)) { + return terrno; + } char* pUserConn = taosStrdup((void*)userConn); if (NULL == pUserConn) { return TSDB_CODE_OUT_OF_MEMORY; } - return rewriteFuncToValue(pCxt, pUserConn, pNode); + int32_t code = rewriteFuncToValue(pCxt, &pUserConn, pNode); + if (TSDB_CODE_SUCCESS != code) { + taosMemoryFree(pUserConn); + } + return code; } static int32_t rewriteSystemInfoFunc(STranslateContext* pCxt, SNode** pNode) { @@ -2622,7 +2737,7 @@ static int32_t rewriteToColumnAndRetranslate(STranslateContext* pCxt, SNode** pp if (code != TSDB_CODE_SUCCESS) { return code; } - translateColumn(pCxt, (SColumnNode**)ppNode); + (void)translateColumn(pCxt, (SColumnNode**)ppNode); if (pCxt->errCode != TSDB_CODE_SUCCESS) { return generateSyntaxErrMsg(&pCxt->msgBuf, errCode); } else { @@ -2750,7 +2865,9 @@ static int32_t rewriteQueryTimeFunc(STranslateContext* pCxt, int64_t val, SNode* return TSDB_CODE_OUT_OF_MEMORY; } snprintf(pStr, 20, "%" PRId64 "", val); - return rewriteFuncToValue(pCxt, pStr, pNode); + int32_t code = rewriteFuncToValue(pCxt, &pStr, pNode); + if (TSDB_CODE_SUCCESS != code) taosMemoryFree(pStr); + return code; } static int32_t rewriteQstartFunc(STranslateContext* pCxt, SNode** pNode) { @@ -3389,12 +3506,17 @@ static EDealRes doCheckAggColCoexist(SNode** pNode, void* pContext) { static EDealRes doCheckGetAggColCoexist(SNode** pNode, void* pContext) { CheckAggColCoexistCxt* pCxt = (CheckAggColCoexistCxt*)pContext; + int32_t code = 0; if (isVectorFunc(*pNode)) { return DEAL_RES_IGNORE_CHILD; } if (isScanPseudoColumnFunc(*pNode) || QUERY_NODE_COLUMN == nodeType(*pNode)) { pCxt->existCol = true; - nodesListMakeStrictAppend(&pCxt->pColList, *pNode); + code = nodesListMakeStrictAppend(&pCxt->pColList, *pNode); + if (TSDB_CODE_SUCCESS != code) { + pCxt->pTranslateCxt->errCode = code; + return DEAL_RES_ERROR; + } } return DEAL_RES_CONTINUE; } @@ -3563,7 +3685,9 @@ static int32_t addMnodeToVgroupList(const SEpSet* pEpSet, SArray** pVgroupList) } SVgroupInfo vg = {.vgId = MNODE_HANDLE}; memcpy(&vg.epSet, pEpSet, sizeof(SEpSet)); - taosArrayPush(*pVgroupList, &vg); + if (NULL == taosArrayPush(*pVgroupList, &vg)) { + return TSDB_CODE_OUT_OF_MEMORY; + } return TSDB_CODE_SUCCESS; } @@ -3616,7 +3740,9 @@ static int32_t getVnodeSysTableVgroupListImpl(STranslateContext* pCxt, SName* pT if (NULL == *pVgroupList) { code = TSDB_CODE_OUT_OF_MEMORY; } else { - taosArrayPush(*pVgroupList, &vgInfo); + if (NULL == taosArrayPush(*pVgroupList, &vgInfo)) { + code = TSDB_CODE_OUT_OF_MEMORY; + } } } else if (TSDB_CODE_MND_DB_NOT_EXIST == code || TSDB_CODE_MND_DB_IN_CREATING == code || TSDB_CODE_MND_DB_IN_DROPPING == code) { @@ -3659,7 +3785,7 @@ static int32_t setVnodeSysTableVgroupList(STranslateContext* pCxt, SName* pName, if (TSDB_CODE_SUCCESS == code) { code = toVgroupsInfo(pVgs, &pRealTable->pVgroupList); } - taosArrayDestroy(pVgs); + (void)taosArrayDestroy(pVgs); return code; } @@ -3670,7 +3796,7 @@ static int32_t setDnodeSysTableVgroupList(STranslateContext* pCxt, SName* pName, if (TSDB_CODE_SUCCESS == code) { code = dnodeToVgroupsInfo(pDnodes, &pRealTable->pVgroupList); } - taosArrayDestroy(pDnodes); + (void)taosArrayDestroy(pDnodes); return code; } @@ -3690,7 +3816,7 @@ static int32_t setSuperTableVgroupList(STranslateContext* pCxt, SName* pName, SR if (TSDB_CODE_SUCCESS == code) { code = toVgroupsInfo(vgroupList, &pRealTable->pVgroupList); } - taosArrayDestroy(vgroupList); + (void)taosArrayDestroy(vgroupList); return code; } @@ -3785,15 +3911,16 @@ static int32_t setTableTsmas(STranslateContext* pCxt, SName* pName, SRealTableNo for (int32_t i = 0; i < pRealTable->pTsmas->size; ++i) { STableTSMAInfo* pTsma = taosArrayGetP(pRealTable->pTsmas, i); SName tsmaTargetTbName = {0}; - toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, "", &tsmaTargetTbName); + SVgroupInfo vgInfo = {0}; + bool exists = false; + (void)toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, "", &tsmaTargetTbName); int32_t len = snprintf(buf, TSDB_TABLE_FNAME_LEN + TSDB_TABLE_NAME_LEN, "%s.%s_%s", pTsma->dbFName, pTsma->name, pRealTable->table.tableName); len = taosCreateMD5Hash(buf, len); strncpy(tsmaTargetTbName.tname, buf, MD5_OUTPUT_LEN); - collectUseTable(&tsmaTargetTbName, pCxt->pTargetTables); - SVgroupInfo vgInfo = {0}; - bool exists = false; - code = catalogGetCachedTableHashVgroup(pCxt->pParseCxt->pCatalog, &tsmaTargetTbName, &vgInfo, &exists); + code = collectUseTable(&tsmaTargetTbName, pCxt->pTargetTables); + if (TSDB_CODE_SUCCESS == code) + code = catalogGetCachedTableHashVgroup(pCxt->pParseCxt->pCatalog, &tsmaTargetTbName, &vgInfo, &exists); if (TSDB_CODE_SUCCESS == code) { ASSERT(exists); if (!pRealTable->tsmaTargetTbVgInfo) { @@ -3810,7 +3937,7 @@ static int32_t setTableTsmas(STranslateContext* pCxt, SName* pName, SRealTableNo } pVgpsInfo->numOfVgroups = 1; pVgpsInfo->vgroups[0] = vgInfo; - taosArrayPush(pRealTable->tsmaTargetTbVgInfo, &pVgpsInfo); + (void)taosArrayPush(pRealTable->tsmaTargetTbVgInfo, &pVgpsInfo); } else { break; } @@ -3839,7 +3966,7 @@ static int32_t setTableTsmas(STranslateContext* pCxt, SName* pName, SRealTableNo // ignore table not exists error code = TSDB_CODE_SUCCESS; } - taosArrayPush(pRealTable->tsmaTargetTbInfo, &ctbInfo); + (void)taosArrayPush(pRealTable->tsmaTargetTbInfo, &ctbInfo); } } } @@ -4449,9 +4576,10 @@ int32_t translateTable(STranslateContext* pCxt, SNode** pTable, SNode* pJoinPare if (TSDB_VIEW_TABLE == pRealTable->pMeta->tableType && !pCurrSmt->tagScan) { return translateView(pCxt, pTable, &name); } - translateAudit(pCxt, pRealTable, &name); + code = translateAudit(pCxt, pRealTable, &name); #endif - code = setTableVgroupList(pCxt, &name, pRealTable); + if (TSDB_CODE_SUCCESS == code) + code = setTableVgroupList(pCxt, &name, pRealTable); if (TSDB_CODE_SUCCESS == code) { code = setTableIndex(pCxt, &name, pRealTable); } @@ -4579,7 +4707,7 @@ static SNode* createMultiResFunc(SFunctionNode* pSrcFunc, SExprNode* pExpr) { strcpy(pFunc->node.aliasName, pCol->colName); } else { len = snprintf(buf, sizeof(buf) - 1, "%s(%s.%s)", pSrcFunc->functionName, pCol->tableAlias, pCol->colName); - taosCreateMD5Hash(buf, len); + (void)taosCreateMD5Hash(buf, len); strncpy(pFunc->node.aliasName, buf, TSDB_COL_NAME_LEN - 1); len = snprintf(buf, sizeof(buf) - 1, "%s(%s)", pSrcFunc->functionName, pCol->colName); // note: userAlias could be truncated here @@ -4587,7 +4715,7 @@ static SNode* createMultiResFunc(SFunctionNode* pSrcFunc, SExprNode* pExpr) { } } else { len = snprintf(buf, sizeof(buf) - 1, "%s(%s)", pSrcFunc->functionName, pExpr->aliasName); - taosCreateMD5Hash(buf, len); + (void)taosCreateMD5Hash(buf, len); strncpy(pFunc->node.aliasName, buf, TSDB_COL_NAME_LEN - 1); len = snprintf(buf, sizeof(buf) - 1, "%s(%s)", pSrcFunc->functionName, pExpr->userAlias); // note: userAlias could be truncated here @@ -4906,21 +5034,24 @@ static int32_t rewriteProjectAlias(SNodeList* pProjectionList) { static int32_t checkProjectAlias(STranslateContext* pCxt, SNodeList* pProjectionList, SHashObj** pOutput) { SHashObj* pUserAliasSet = taosHashInit(LIST_LENGTH(pProjectionList), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); + if (!pUserAliasSet) return TSDB_CODE_OUT_OF_MEMORY; SNode* pProject = NULL; + int32_t code = TSDB_CODE_SUCCESS; FOREACH(pProject, pProjectionList) { SExprNode* pExpr = (SExprNode*)pProject; if (NULL != taosHashGet(pUserAliasSet, pExpr->userAlias, strlen(pExpr->userAlias))) { taosHashCleanup(pUserAliasSet); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_AMBIGUOUS_COLUMN, pExpr->userAlias); } - taosHashPut(pUserAliasSet, pExpr->userAlias, strlen(pExpr->userAlias), &pExpr, POINTER_BYTES); + code = taosHashPut(pUserAliasSet, pExpr->userAlias, strlen(pExpr->userAlias), &pExpr, POINTER_BYTES); + if (TSDB_CODE_SUCCESS != code) break; } - if (NULL == pOutput) { - taosHashCleanup(pUserAliasSet); - } else { + if (TSDB_CODE_SUCCESS == code && NULL != pOutput) { *pOutput = pUserAliasSet; + } else { + taosHashCleanup(pUserAliasSet); } - return TSDB_CODE_SUCCESS; + return code; } static int32_t translateProjectionList(STranslateContext* pCxt, SSelectStmt* pSelect) { @@ -5009,14 +5140,15 @@ static int32_t getQueryTimeRange(STranslateContext* pCxt, SNode* pWhere, STimeWi } SNode* pPrimaryKeyCond = NULL; - filterPartitionCond(&pCond, &pPrimaryKeyCond, NULL, NULL, NULL); + int32_t code = filterPartitionCond(&pCond, &pPrimaryKeyCond, NULL, NULL, NULL); - int32_t code = TSDB_CODE_SUCCESS; - if (NULL != pPrimaryKeyCond) { - bool isStrict = false; - code = getTimeRange(&pPrimaryKeyCond, pTimeRange, &isStrict); - } else { - *pTimeRange = TSWINDOW_INITIALIZER; + if (TSDB_CODE_SUCCESS == code) { + if (NULL != pPrimaryKeyCond) { + bool isStrict = false; + code = getTimeRange(&pPrimaryKeyCond, pTimeRange, &isStrict); + } else { + *pTimeRange = TSWINDOW_INITIALIZER; + } } nodesDestroyNode(pCond); nodesDestroyNode(pPrimaryKeyCond); @@ -5325,7 +5457,9 @@ static EDealRes collectWindowsPseudocolumns(SNode* pNode, void* pContext) { SFunctionNode* pFunc = (SFunctionNode*)pNode; if (FUNCTION_TYPE_WSTART == pFunc->funcType || FUNCTION_TYPE_WEND == pFunc->funcType || FUNCTION_TYPE_WDURATION == pFunc->funcType) { - nodesListStrictAppend(pCols, nodesCloneNode(pNode)); + if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pCols, nodesCloneNode(pNode))) { + return DEAL_RES_ERROR; + } } } return DEAL_RES_CONTINUE; @@ -5363,26 +5497,37 @@ static int32_t translateWindow(STranslateContext* pCxt, SSelectStmt* pSelect) { ((SRealTableNode*)pSelect->pFromTable)->pMeta->tableType == TSDB_SYSTEM_TABLE) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYSTABLE_NOT_ALLOWED, "WINDOW"); } - if (QUERY_NODE_INTERVAL_WINDOW != nodeType(pSelect->pWindow) && - ((NULL != pSelect->pFromTable && QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) && - !isGlobalTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery) && - !isTimeLineAlignedQuery(pCxt->pCurrStmt)) || - (NULL != pSelect->pFromTable && QUERY_NODE_JOIN_TABLE == nodeType(pSelect->pFromTable) && - (TIME_LINE_GLOBAL != pSelect->timeLineCurMode && TIME_LINE_MULTI != pSelect->timeLineCurMode)))) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY); + int32_t code = 0; + if (QUERY_NODE_INTERVAL_WINDOW != nodeType(pSelect->pWindow)) { + if (NULL != pSelect->pFromTable && QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) && + !isGlobalTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery)) { + bool isTimelineAlignedQuery = false; + code = isTimeLineAlignedQuery(pCxt->pCurrStmt, &isTimelineAlignedQuery); + if (TSDB_CODE_SUCCESS != code) return code; + if (!isTimelineAlignedQuery) return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY); + } + if (NULL != pSelect->pFromTable && QUERY_NODE_JOIN_TABLE == nodeType(pSelect->pFromTable) && + (TIME_LINE_GLOBAL != pSelect->timeLineCurMode && TIME_LINE_MULTI != pSelect->timeLineCurMode)) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY); + } } - if (QUERY_NODE_INTERVAL_WINDOW == nodeType(pSelect->pWindow) && - ((NULL != pSelect->pFromTable && QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) && - !isBlockTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery) && - !isTimeLineAlignedQuery(pCxt->pCurrStmt)) || - (NULL != pSelect->pFromTable && QUERY_NODE_JOIN_TABLE == nodeType(pSelect->pFromTable) && - (TIME_LINE_NONE == pSelect->timeLineCurMode)))) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY); + if (QUERY_NODE_INTERVAL_WINDOW == nodeType(pSelect->pWindow)) { + if (NULL != pSelect->pFromTable && QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) && + !isBlockTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery)) { + bool isTimelineAlignedQuery = false; + code = isTimeLineAlignedQuery(pCxt->pCurrStmt, &isTimelineAlignedQuery); + if (TSDB_CODE_SUCCESS != code) return code; + if (!isTimelineAlignedQuery) return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY); + } + if (NULL != pSelect->pFromTable && QUERY_NODE_JOIN_TABLE == nodeType(pSelect->pFromTable) && + (TIME_LINE_NONE == pSelect->timeLineCurMode)) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY); + } } pCxt->currClause = SQL_CLAUSE_WINDOW; - int32_t code = translateExpr(pCxt, &pSelect->pWindow); + code = translateExpr(pCxt, &pSelect->pWindow); if (TSDB_CODE_SUCCESS == code) { code = translateSpecificWindow(pCxt, pSelect); } @@ -5576,9 +5721,12 @@ typedef struct SEqCondTbNameTableInfo { } SEqCondTbNameTableInfo; //[tableAlias.]tbname = tbNamVal -static bool isOperatorEqTbnameCond(STranslateContext* pCxt, SOperatorNode* pOperator, char** ppTableAlias, - SArray** ppTabNames) { - if (pOperator->opType != OP_TYPE_EQUAL) return false; +static int32_t isOperatorEqTbnameCond(STranslateContext* pCxt, SOperatorNode* pOperator, char** ppTableAlias, + SArray** ppTabNames, bool* pRet) { + if (pOperator->opType != OP_TYPE_EQUAL) { + *pRet = false; + return TSDB_CODE_SUCCESS; + } SFunctionNode* pTbnameFunc = NULL; SValueNode* pValueNode = NULL; if (nodeType(pOperator->pLeft) == QUERY_NODE_FUNCTION && @@ -5592,7 +5740,8 @@ static bool isOperatorEqTbnameCond(STranslateContext* pCxt, SOperatorNode* pOper pTbnameFunc = (SFunctionNode*)pOperator->pRight; pValueNode = (SValueNode*)pOperator->pLeft; } else { - return false; + *pRet = false; + return TSDB_CODE_SUCCESS; } if (LIST_LENGTH(pTbnameFunc->pParameterList) == 0) { @@ -5603,21 +5752,25 @@ static bool isOperatorEqTbnameCond(STranslateContext* pCxt, SOperatorNode* pOper SValueNode* pQualValNode = (SValueNode*)pQualNode; *ppTableAlias = pQualValNode->literal; } else { - return false; + *pRet = false; + return TSDB_CODE_SUCCESS; } *ppTabNames = taosArrayInit(1, sizeof(void*)); - taosArrayPush(*ppTabNames, &(pValueNode->literal)); - return true; + if (!*ppTabNames) return TSDB_CODE_OUT_OF_MEMORY; + (void)taosArrayPush(*ppTabNames, &(pValueNode->literal)); + *pRet = true; + return TSDB_CODE_SUCCESS; } //[tableAlias.]tbname in (value1, value2, ...) -static bool isOperatorTbnameInCond(STranslateContext* pCxt, SOperatorNode* pOperator, char** ppTableAlias, - SArray** ppTbNames) { +static int32_t isOperatorTbnameInCond(STranslateContext* pCxt, SOperatorNode* pOperator, char** ppTableAlias, + SArray** ppTbNames, bool* pRet) { if (pOperator->opType != OP_TYPE_IN) return false; if (nodeType(pOperator->pLeft) != QUERY_NODE_FUNCTION || ((SFunctionNode*)(pOperator->pLeft))->funcType != FUNCTION_TYPE_TBNAME || nodeType(pOperator->pRight) != QUERY_NODE_NODE_LIST) { - return false; + *pRet = false; + return TSDB_CODE_SUCCESS; } SFunctionNode* pTbnameFunc = (SFunctionNode*)pOperator->pLeft; @@ -5629,27 +5782,36 @@ static bool isOperatorTbnameInCond(STranslateContext* pCxt, SOperatorNode* pOper SValueNode* pQualValNode = (SValueNode*)pQualNode; *ppTableAlias = pQualValNode->literal; } else { - return false; + *pRet = false; + return TSDB_CODE_SUCCESS; } - *ppTbNames = taosArrayInit(1, sizeof(void*)); SNodeListNode* pValueListNode = (SNodeListNode*)pOperator->pRight; + *ppTbNames = taosArrayInit(LIST_LENGTH(pValueListNode->pNodeList), sizeof(void*)); + if (!*ppTbNames) return TSDB_CODE_OUT_OF_MEMORY; SNodeList* pValueNodeList = pValueListNode->pNodeList; SNode* pValNode = NULL; FOREACH(pValNode, pValueNodeList) { if (nodeType(pValNode) != QUERY_NODE_VALUE) { - return false; + *pRet = false; + return TSDB_CODE_SUCCESS; } - taosArrayPush(*ppTbNames, &((SValueNode*)pValNode)->literal); + (void)taosArrayPush(*ppTbNames, &((SValueNode*)pValNode)->literal); } - return true; + *pRet = true; + return TSDB_CODE_SUCCESS; } -static bool findEqCondTbNameInOperatorNode(STranslateContext* pCxt, SNode* pWhere, SEqCondTbNameTableInfo* pInfo) { +static int32_t findEqCondTbNameInOperatorNode(STranslateContext* pCxt, SNode* pWhere, SEqCondTbNameTableInfo* pInfo, bool* pRet) { int32_t code = TSDB_CODE_SUCCESS; char* pTableAlias = NULL; char* pTbNameVal = NULL; - if (isOperatorEqTbnameCond(pCxt, (SOperatorNode*)pWhere, &pTableAlias, &pInfo->aTbnames) || - isOperatorTbnameInCond(pCxt, (SOperatorNode*)pWhere, &pTableAlias, &pInfo->aTbnames)) { + bool eqTbnameCond = false, tbnameInCond = false; + code = isOperatorEqTbnameCond(pCxt, (SOperatorNode*)pWhere, &pTableAlias, &pInfo->aTbnames, &eqTbnameCond); + if (TSDB_CODE_SUCCESS == code) { + code = isOperatorTbnameInCond(pCxt, (SOperatorNode*)pWhere, &pTableAlias, &pInfo->aTbnames, &tbnameInCond); + } + if (TSDB_CODE_SUCCESS != code) return code; + if (eqTbnameCond || tbnameInCond) { STableNode* pTable; if (pTableAlias == NULL) { pTable = (STableNode*)((SSelectStmt*)(pCxt->pCurrStmt))->pFromTable; @@ -5659,12 +5821,14 @@ static bool findEqCondTbNameInOperatorNode(STranslateContext* pCxt, SNode* pWher if (code == TSDB_CODE_SUCCESS && nodeType(pTable) == QUERY_NODE_REAL_TABLE && ((SRealTableNode*)pTable)->pMeta && ((SRealTableNode*)pTable)->pMeta->tableType == TSDB_SUPER_TABLE) { pInfo->pRealTable = (SRealTableNode*)pTable; - return true; + *pRet = true; + return TSDB_CODE_SUCCESS; } - taosArrayDestroy(pInfo->aTbnames); + (void)taosArrayDestroy(pInfo->aTbnames); pInfo->aTbnames = NULL; } - return false; + *pRet = false; + return TSDB_CODE_SUCCESS; } static bool isTableExistInTableTbnames(SArray* aTableTbNames, SRealTableNode* pTable) { @@ -5677,103 +5841,127 @@ static bool isTableExistInTableTbnames(SArray* aTableTbNames, SRealTableNode* pT return false; } -static void findEqualCondTbnameInLogicCondAnd(STranslateContext* pCxt, SNode* pWhere, SArray* aTableTbnames) { - SNode* pTmpNode = NULL; +static int32_t findEqualCondTbnameInLogicCondAnd(STranslateContext* pCxt, SNode* pWhere, SArray* aTableTbnames) { + SNode* pTmpNode = NULL; + int32_t code = TSDB_CODE_SUCCESS; FOREACH(pTmpNode, ((SLogicConditionNode*)pWhere)->pParameterList) { if (nodeType(pTmpNode) == QUERY_NODE_OPERATOR) { SEqCondTbNameTableInfo info = {0}; - bool bIsEqTbnameCond = findEqCondTbNameInOperatorNode(pCxt, pTmpNode, &info); + bool bIsEqTbnameCond; + code = findEqCondTbNameInOperatorNode(pCxt, pTmpNode, &info, &bIsEqTbnameCond); + if (TSDB_CODE_SUCCESS != code) break; if (bIsEqTbnameCond) { if (!isTableExistInTableTbnames(aTableTbnames, info.pRealTable)) { // TODO: intersect tbNames of same table? speed - taosArrayPush(aTableTbnames, &info); + if (NULL == taosArrayPush(aTableTbnames, &info)) { + code = TSDB_CODE_OUT_OF_MEMORY; + break; + } } else { - taosArrayDestroy(info.aTbnames); + (void)taosArrayDestroy(info.aTbnames); } } } // TODO: logic cond } + return code; } -static void unionEqualCondTbnamesOfSameTable(SArray* aTableTbnames, SEqCondTbNameTableInfo* pInfo) { +static int32_t unionEqualCondTbnamesOfSameTable(SArray* aTableTbnames, SEqCondTbNameTableInfo* pInfo) { + int32_t code = TSDB_CODE_SUCCESS; bool bFoundTable = false; for (int i = 0; i < taosArrayGetSize(aTableTbnames); ++i) { SEqCondTbNameTableInfo* info = taosArrayGet(aTableTbnames, i); if (info->pRealTable == pInfo->pRealTable) { - taosArrayAddAll(info->aTbnames, pInfo->aTbnames); - taosArrayDestroy(pInfo->aTbnames); + if (NULL == taosArrayAddAll(info->aTbnames, pInfo->aTbnames)) { + code = TSDB_CODE_OUT_OF_MEMORY; + break; + } + (void)taosArrayDestroy(pInfo->aTbnames); pInfo->aTbnames = NULL; bFoundTable = true; break; } } - if (!bFoundTable) { - taosArrayPush(aTableTbnames, pInfo); + if (TSDB_CODE_SUCCESS == code && !bFoundTable) { + if (NULL == taosArrayPush(aTableTbnames, pInfo)) { + code = TSDB_CODE_OUT_OF_MEMORY; + } } + return code; } -static void findEqualCondTbnameInLogicCondOr(STranslateContext* pCxt, SNode* pWhere, SArray* aTableTbnames) { - bool bAllTbName = true; - SNode* pTmpNode = NULL; +static int32_t findEqualCondTbnameInLogicCondOr(STranslateContext* pCxt, SNode* pWhere, SArray* aTableTbnames) { + int32_t code = TSDB_CODE_SUCCESS; + bool bAllTbName = true; + SNode* pTmpNode = NULL; FOREACH(pTmpNode, ((SLogicConditionNode*)pWhere)->pParameterList) { // TODO: logic cond if (nodeType(pTmpNode) == QUERY_NODE_OPERATOR) { SEqCondTbNameTableInfo info = {0}; - bool bIsEqTbnameCond = findEqCondTbNameInOperatorNode(pCxt, pTmpNode, &info); + bool bIsEqTbnameCond; + code = findEqCondTbNameInOperatorNode(pCxt, pTmpNode, &info, &bIsEqTbnameCond); + if (TSDB_CODE_SUCCESS != code) break; if (!bIsEqTbnameCond) { bAllTbName = false; break; } else { - unionEqualCondTbnamesOfSameTable(aTableTbnames, &info); + code = unionEqualCondTbnamesOfSameTable(aTableTbnames, &info); + if (TSDB_CODE_SUCCESS != code) break; } } else { bAllTbName = false; break; } } - if (!bAllTbName) { + if (TSDB_CODE_SUCCESS == code && !bAllTbName) { for (int i = 0; i < taosArrayGetSize(aTableTbnames); ++i) { SEqCondTbNameTableInfo* pInfo = taosArrayGet(aTableTbnames, i); - taosArrayDestroy(pInfo->aTbnames); + (void)taosArrayDestroy(pInfo->aTbnames); pInfo->aTbnames = NULL; } taosArrayClear(aTableTbnames); } + return code; } static int32_t findEqualCondTbname(STranslateContext* pCxt, SNode* pWhere, SArray* aTableTbnames) { + int32_t code = TSDB_CODE_SUCCESS; // TODO: optimize nested and/or condition. now only the fist level is processed. if (nodeType(pWhere) == QUERY_NODE_OPERATOR) { SEqCondTbNameTableInfo info = {0}; - bool bIsEqTbnameCond = findEqCondTbNameInOperatorNode(pCxt, pWhere, &info); + bool bIsEqTbnameCond; + code = findEqCondTbNameInOperatorNode(pCxt, pWhere, &info, &bIsEqTbnameCond); + if (TSDB_CODE_SUCCESS != code) return code; if (bIsEqTbnameCond) { - taosArrayPush(aTableTbnames, &info); + if (NULL == taosArrayPush(aTableTbnames, &info)) { + return TSDB_CODE_OUT_OF_MEMORY; + } } } else if (nodeType(pWhere) == QUERY_NODE_LOGIC_CONDITION) { if (((SLogicConditionNode*)pWhere)->condType == LOGIC_COND_TYPE_AND) { - findEqualCondTbnameInLogicCondAnd(pCxt, pWhere, aTableTbnames); + code = findEqualCondTbnameInLogicCondAnd(pCxt, pWhere, aTableTbnames); } else if (((SLogicConditionNode*)pWhere)->condType == LOGIC_COND_TYPE_OR) { - findEqualCondTbnameInLogicCondOr(pCxt, pWhere, aTableTbnames); + code = findEqualCondTbnameInLogicCondOr(pCxt, pWhere, aTableTbnames); } } - return TSDB_CODE_SUCCESS; + return code; } -static int32_t findVgroupsFromEqualTbname(STranslateContext* pCxt, SArray* aTbnames, const char* dbName, +static void findVgroupsFromEqualTbname(STranslateContext* pCxt, SArray* aTbnames, const char* dbName, int32_t numOfVgroups, SVgroupsInfo* vgsInfo) { int32_t nVgroups = 0; int32_t nTbls = taosArrayGetSize(aTbnames); if (nTbls >= numOfVgroups) { vgsInfo->numOfVgroups = 0; - return TSDB_CODE_SUCCESS; + return; } for (int j = 0; j < nTbls; ++j) { SName snameTb; char* tbName = taosArrayGetP(aTbnames, j); - toName(pCxt->pParseCxt->acctId, dbName, tbName, &snameTb); + (void)toName(pCxt->pParseCxt->acctId, dbName, tbName, &snameTb); SVgroupInfo vgInfo = {0}; bool bExists; int32_t code = catalogGetCachedTableHashVgroup(pCxt->pParseCxt->pCatalog, &snameTb, &vgInfo, &bExists); @@ -5795,7 +5983,6 @@ static int32_t findVgroupsFromEqualTbname(STranslateContext* pCxt, SArray* aTbna break; } } - return TSDB_CODE_SUCCESS; } static int32_t setEqualTbnameTableVgroups(STranslateContext* pCxt, SSelectStmt* pSelect, SArray* aTables) { @@ -5831,7 +6018,7 @@ static int32_t setEqualTbnameTableVgroups(STranslateContext* pCxt, SSelectStmt* code = TSDB_CODE_OUT_OF_MEMORY; break; } - taosArrayPush(pTbNames, &pNewTbName); + (void)taosArrayPush(pTbNames, &pNewTbName); sprintf(pNewTbName, "%s.%s_%s", pTsma->dbFName, pTsma->name, pTbName); int32_t len = taosCreateMD5Hash(pNewTbName, strlen(pNewTbName)); } @@ -5842,7 +6029,7 @@ static int32_t setEqualTbnameTableVgroups(STranslateContext* pCxt, SSelectStmt* if (TSDB_CODE_SUCCESS == code) { findVgroupsFromEqualTbname(pCxt, pTbNames, pInfo->pRealTable->table.dbName, numOfVgs, vgsInfo); if (vgsInfo->numOfVgroups != 0) { - taosArrayPush(pInfo->pRealTable->tsmaTargetTbVgInfo, &vgsInfo); + (void)taosArrayPush(pInfo->pRealTable->tsmaTargetTbVgInfo, &vgsInfo); } else { taosMemoryFree(vgsInfo); } @@ -5864,9 +6051,9 @@ static int32_t setTableVgroupsFromEqualTbnameCond(STranslateContext* pCxt, SSele } for (int i = 0; i < taosArrayGetSize(aTables); ++i) { SEqCondTbNameTableInfo* pInfo = taosArrayGet(aTables, i); - taosArrayDestroy(pInfo->aTbnames); + (void)taosArrayDestroy(pInfo->aTbnames); } - taosArrayDestroy(aTables); + (void)taosArrayDestroy(aTables); return code; } @@ -5877,7 +6064,7 @@ static int32_t translateWhere(STranslateContext* pCxt, SSelectStmt* pSelect) { code = getQueryTimeRange(pCxt, pSelect->pWhere, &pSelect->timeRange); } if (pSelect->pWhere != NULL && pCxt->pParseCxt->topicQuery == false) { - setTableVgroupsFromEqualTbnameCond(pCxt, pSelect); + code = setTableVgroupsFromEqualTbnameCond(pCxt, pSelect); } return code; } @@ -5939,8 +6126,10 @@ static EDealRes collectTableAlias(SNode* pNode, void* pContext) { *(SSHashObj**)pContext = pHash; } - tSimpleHashPut(*(SSHashObj**)pContext, pCol->tableAlias, strlen(pCol->tableAlias), pCol->tableAlias, - sizeof(pCol->tableAlias)); + if (TSDB_CODE_SUCCESS != tSimpleHashPut(*(SSHashObj**)pContext, pCol->tableAlias, strlen(pCol->tableAlias), pCol->tableAlias, + sizeof(pCol->tableAlias))) { + return DEAL_RES_ERROR; + } return DEAL_RES_CONTINUE; } @@ -6200,8 +6389,9 @@ static int32_t translateSelectFrom(STranslateContext* pCxt, SSelectStmt* pSelect code = checkIsEmptyResult(pCxt, pSelect); } if (TSDB_CODE_SUCCESS == code) { - resetSelectFuncNumWithoutDup(pSelect); - code = checkAggColCoexist(pCxt, pSelect); + code = resetSelectFuncNumWithoutDup(pSelect); + if (TSDB_CODE_SUCCESS == code) + code = checkAggColCoexist(pCxt, pSelect); } /* if (TSDB_CODE_SUCCESS == code) { @@ -6574,6 +6764,7 @@ static int64_t getBigintFromValueNode(SValueNode* pVal) { } static int32_t buildCreateDbRetentions(const SNodeList* pRetentions, SCreateDbReq* pReq) { + int32_t code = TSDB_CODE_SUCCESS; if (NULL != pRetentions) { pReq->pRetensions = taosArrayInit(LIST_LENGTH(pRetentions), sizeof(SRetention)); if (NULL == pReq->pRetensions) { @@ -6588,17 +6779,23 @@ static int32_t buildCreateDbRetentions(const SNodeList* pRetentions, SCreateDbRe pKeep = (SValueNode*)nodesListGetNode(((SNodeListNode*)pNode)->pNodeList, 1); SRetention retention = { .freq = pFreq->datum.i, .freqUnit = pFreq->unit, .keep = pKeep->datum.i, .keepUnit = pKeep->unit}; - taosArrayPush(pReq->pRetensions, &retention); + if (NULL == taosArrayPush(pReq->pRetensions, &retention)) { + code = TSDB_CODE_OUT_OF_MEMORY; + break; + } + } + if (TSDB_CODE_SUCCESS == code) { + pReq->numOfRetensions = taosArrayGetSize(pReq->pRetensions); } - pReq->numOfRetensions = taosArrayGetSize(pReq->pRetensions); } - return TSDB_CODE_SUCCESS; + return code; } static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt, SCreateDbReq* pReq) { SName name = {0}; - tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); - tNameGetFullDbName(&name, pReq->db); + int32_t code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); + if (TSDB_CODE_SUCCESS != code) return code; + (void)tNameGetFullDbName(&name, pReq->db); pReq->numOfVgroups = pStmt->pOptions->numOfVgroups; pReq->numOfStables = pStmt->pOptions->singleStable; pReq->buffer = pStmt->pOptions->buffer; @@ -7256,7 +7453,9 @@ static int32_t fillCmdSql(STranslateContext* pCxt, int16_t msgType, void* pReq) typedef int32_t (*FSerializeFunc)(void* pBuf, int32_t bufLen, void* pReq); static int32_t buildCmdMsg(STranslateContext* pCxt, int16_t msgType, FSerializeFunc func, void* pReq) { - fillCmdSql(pCxt, msgType, pReq); + int32_t code = TSDB_CODE_SUCCESS; + code = fillCmdSql(pCxt, msgType, pReq); + if (TSDB_CODE_SUCCESS != code) return code; pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; @@ -7269,9 +7468,10 @@ static int32_t buildCmdMsg(STranslateContext* pCxt, int16_t msgType, FSerializeF taosMemoryFreeClear(pCxt->pCmdMsg); return TSDB_CODE_OUT_OF_MEMORY; } - func(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, pReq); - - return TSDB_CODE_SUCCESS; + if (-1 == func(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, pReq)) { + code = TSDB_CODE_INVALID_MSG; + } + return code; } static int32_t translateCreateDatabase(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt) { @@ -7290,19 +7490,22 @@ static int32_t translateCreateDatabase(STranslateContext* pCxt, SCreateDatabaseS static int32_t translateDropDatabase(STranslateContext* pCxt, SDropDatabaseStmt* pStmt) { SDropDbReq dropReq = {0}; SName name = {0}; - tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); - tNameGetFullDbName(&name, dropReq.db); + int32_t code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); + if (TSDB_CODE_SUCCESS != code) return code; + (void)tNameGetFullDbName(&name, dropReq.db); dropReq.ignoreNotExists = pStmt->ignoreNotExists; - int32_t code = buildCmdMsg(pCxt, TDMT_MND_DROP_DB, (FSerializeFunc)tSerializeSDropDbReq, &dropReq); + code = buildCmdMsg(pCxt, TDMT_MND_DROP_DB, (FSerializeFunc)tSerializeSDropDbReq, &dropReq); tFreeSDropDbReq(&dropReq); return code; } -static void buildAlterDbReq(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt, SAlterDbReq* pReq) { - SName name = {0}; - tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); - tNameGetFullDbName(&name, pReq->db); +static int32_t buildAlterDbReq(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt, SAlterDbReq* pReq) { + SName name = {0}; + int32_t code = TSDB_CODE_SUCCESS; + code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); + if (TSDB_CODE_SUCCESS != code) return code; + (void)tNameGetFullDbName(&name, pReq->db); pReq->buffer = pStmt->pOptions->buffer; pReq->pageSize = -1; pReq->pages = pStmt->pOptions->pages; @@ -7324,7 +7527,7 @@ static void buildAlterDbReq(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt, pReq->s3KeepLocal = pStmt->pOptions->s3KeepLocal; pReq->s3Compact = pStmt->pOptions->s3Compact; pReq->withArbitrator = pStmt->pOptions->withArbitrator; - return; + return code; } static int32_t translateAlterDatabase(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt) { @@ -7358,9 +7561,10 @@ static int32_t translateAlterDatabase(STranslateContext* pCxt, SAlterDatabaseStm } SAlterDbReq alterReq = {0}; - buildAlterDbReq(pCxt, pStmt, &alterReq); + code = buildAlterDbReq(pCxt, pStmt, &alterReq); - code = buildCmdMsg(pCxt, TDMT_MND_ALTER_DB, (FSerializeFunc)tSerializeSAlterDbReq, &alterReq); + if (TSDB_CODE_SUCCESS == code) + code = buildCmdMsg(pCxt, TDMT_MND_ALTER_DB, (FSerializeFunc)tSerializeSAlterDbReq, &alterReq); tFreeSAlterDbReq(&alterReq); return code; } @@ -7368,8 +7572,9 @@ static int32_t translateAlterDatabase(STranslateContext* pCxt, SAlterDatabaseStm static int32_t translateTrimDatabase(STranslateContext* pCxt, STrimDatabaseStmt* pStmt) { STrimDbReq req = {.maxSpeed = pStmt->maxSpeed}; SName name = {0}; - tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); - tNameGetFullDbName(&name, req.db); + int32_t code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); + if (TSDB_CODE_SUCCESS != code) return code; + (void)tNameGetFullDbName(&name, req.db); return buildCmdMsg(pCxt, TDMT_MND_TRIM_DB, (FSerializeFunc)tSerializeSTrimDbReq, &req); } @@ -7393,13 +7598,17 @@ static int32_t checkColumnOptions(SNodeList* pList) { static int32_t translateS3MigrateDatabase(STranslateContext* pCxt, SS3MigrateDatabaseStmt* pStmt) { SS3MigrateDbReq req = {0}; SName name = {0}; - tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); - tNameGetFullDbName(&name, req.db); + int32_t code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); + if (TSDB_CODE_SUCCESS != code) return code; + (void)tNameGetFullDbName(&name, req.db); return buildCmdMsg(pCxt, TDMT_MND_S3MIGRATE_DB, (FSerializeFunc)tSerializeSS3MigrateDbReq, &req); } static int32_t columnDefNodeToField(SNodeList* pList, SArray** pArray, bool calBytes) { *pArray = taosArrayInit(LIST_LENGTH(pList), sizeof(SFieldWithOptions)); + if (!pArray) return TSDB_CODE_OUT_OF_MEMORY; + + int32_t code = TSDB_CODE_SUCCESS; SNode* pNode; FOREACH(pNode, pList) { SColumnDefNode* pCol = (SColumnDefNode*)pNode; @@ -7422,13 +7631,21 @@ static int32_t columnDefNodeToField(SNodeList* pList, SArray** pArray, bool calB if (pCol->pOptions && ((SColumnOptions*)pCol->pOptions)->bPrimaryKey) { field.flags |= COL_IS_KEY; } - taosArrayPush(*pArray, &field); + if (NULL == taosArrayPush(*pArray, &field)) { + code = TSDB_CODE_OUT_OF_MEMORY; + break; + } } - return TSDB_CODE_SUCCESS; + if (TSDB_CODE_SUCCESS != code) { + (void)taosArrayDestroy(*pArray); + *pArray = NULL; + } + return code; } static int32_t tagDefNodeToField(SNodeList* pList, SArray** pArray, bool calBytes) { *pArray = taosArrayInit(LIST_LENGTH(pList), sizeof(SField)); + if (!*pArray) return TSDB_CODE_OUT_OF_MEMORY; SNode* pNode; FOREACH(pNode, pList) { SColumnDefNode* pCol = (SColumnDefNode*)pNode; @@ -7444,7 +7661,7 @@ static int32_t tagDefNodeToField(SNodeList* pList, SArray** pArray, bool calByte if (pCol->sma) { field.flags |= COL_SMA_ON; } - taosArrayPush(*pArray, &field); + (void)taosArrayPush(*pArray, &field); } return TSDB_CODE_SUCCESS; } @@ -8143,12 +8360,15 @@ static int32_t buildRollupFuncs(SNodeList* pFuncs, SArray** pArray) { return TSDB_CODE_SUCCESS; } *pArray = taosArrayInit(LIST_LENGTH(pFuncs), TSDB_FUNC_NAME_LEN); + if (!*pArray) return TSDB_CODE_OUT_OF_MEMORY; SNode* pNode; - FOREACH(pNode, pFuncs) { taosArrayPush(*pArray, ((SFunctionNode*)pNode)->functionName); } + FOREACH(pNode, pFuncs) { (void)taosArrayPush(*pArray, ((SFunctionNode*)pNode)->functionName); } return TSDB_CODE_SUCCESS; } static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStmt, SMCreateStbReq* pReq) { + int32_t code = TSDB_CODE_SUCCESS; + SName tableName; pReq->igExists = pStmt->ignoreExists; pReq->delay1 = pStmt->pOptions->maxDelay1; pReq->delay2 = pStmt->pOptions->maxDelay2; @@ -8161,25 +8381,29 @@ static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStm pReq->source = TD_REQ_FROM_APP; // columnDefNodeToField(pStmt->pCols, &pReq->pColumns, true); // columnDefNodeToField(pStmt->pTags, &pReq->pTags, true); - columnDefNodeToField(pStmt->pCols, &pReq->pColumns, true); - tagDefNodeToField(pStmt->pTags, &pReq->pTags, true); - pReq->numOfColumns = LIST_LENGTH(pStmt->pCols); - pReq->numOfTags = LIST_LENGTH(pStmt->pTags); - if (pStmt->pOptions->commentNull == false) { - pReq->pComment = taosStrdup(pStmt->pOptions->comment); - if (NULL == pReq->pComment) { - return TSDB_CODE_OUT_OF_MEMORY; + code = columnDefNodeToField(pStmt->pCols, &pReq->pColumns, true); + if (TSDB_CODE_SUCCESS == code) + code = tagDefNodeToField(pStmt->pTags, &pReq->pTags, true); + if (TSDB_CODE_SUCCESS == code) { + pReq->numOfColumns = LIST_LENGTH(pStmt->pCols); + pReq->numOfTags = LIST_LENGTH(pStmt->pTags); + if (pStmt->pOptions->commentNull == false) { + pReq->pComment = taosStrdup(pStmt->pOptions->comment); + if (NULL == pReq->pComment) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pReq->commentLen = strlen(pStmt->pOptions->comment); + } else { + pReq->commentLen = -1; } - pReq->commentLen = strlen(pStmt->pOptions->comment); - } else { - pReq->commentLen = -1; + code = buildRollupFuncs(pStmt->pOptions->pRollupFuncs, &pReq->pFuncs); } - buildRollupFuncs(pStmt->pOptions->pRollupFuncs, &pReq->pFuncs); - pReq->numOfFuncs = taosArrayGetSize(pReq->pFuncs); - - SName tableName; - tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tableName), pReq->name); - int32_t code = collectUseTable(&tableName, pCxt->pTables); + if (TSDB_CODE_SUCCESS == code) { + pReq->numOfFuncs = taosArrayGetSize(pReq->pFuncs); + code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tableName), pReq->name); + } + if (TSDB_CODE_SUCCESS == code) + code = collectUseTable(&tableName, pCxt->pTables); if (TSDB_CODE_SUCCESS == code) { code = collectUseTable(&tableName, pCxt->pTargetTables); } @@ -8206,9 +8430,11 @@ static int32_t doTranslateDropSuperTable(STranslateContext* pCxt, const SName* p int32_t code = collectUseTable(pTableName, pCxt->pTargetTables); if (TSDB_CODE_SUCCESS == code) { SMDropStbReq dropReq = {0}; - tNameExtractFullName(pTableName, dropReq.name); - dropReq.igNotExists = ignoreNotExists; - code = buildCmdMsg(pCxt, TDMT_MND_DROP_STB, (FSerializeFunc)tSerializeSMDropStbReq, &dropReq); + code = tNameExtractFullName(pTableName, dropReq.name); + if (TSDB_CODE_SUCCESS == code) { + dropReq.igNotExists = ignoreNotExists; + code = buildCmdMsg(pCxt, TDMT_MND_DROP_STB, (FSerializeFunc)tSerializeSMDropStbReq, &dropReq); + } tFreeSMDropStbReq(&dropReq); } return code; @@ -8230,7 +8456,8 @@ static int32_t translateDropSuperTable(STranslateContext* pCxt, SDropSuperTableS static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, SMAlterStbReq* pAlterReq) { SName tableName; - tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tableName), pAlterReq->name); + int32_t code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tableName), pAlterReq->name); + if (TSDB_CODE_SUCCESS != code) return code; pAlterReq->alterType = pStmt->alterType; if (TSDB_ALTER_TABLE_UPDATE_OPTIONS == pStmt->alterType) { @@ -8262,17 +8489,23 @@ static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt* case TSDB_ALTER_TABLE_UPDATE_TAG_BYTES: { TAOS_FIELD field = {.type = pStmt->dataType.type, .bytes = calcTypeBytes(pStmt->dataType)}; strcpy(field.name, pStmt->colName); - taosArrayPush(pAlterReq->pFields, &field); + if (NULL == taosArrayPush(pAlterReq->pFields, &field)) { + return TSDB_CODE_OUT_OF_MEMORY; + } break; } case TSDB_ALTER_TABLE_UPDATE_TAG_NAME: case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME: { TAOS_FIELD oldField = {0}; strcpy(oldField.name, pStmt->colName); - taosArrayPush(pAlterReq->pFields, &oldField); + if (NULL == taosArrayPush(pAlterReq->pFields, &oldField)) { + return TSDB_CODE_OUT_OF_MEMORY; + } TAOS_FIELD newField = {0}; strcpy(newField.name, pStmt->newColName); - taosArrayPush(pAlterReq->pFields, &newField); + if (NULL == taosArrayPush(pAlterReq->pFields, &newField)) { + return TSDB_CODE_OUT_OF_MEMORY; + } break; } case TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS: { @@ -8288,13 +8521,16 @@ static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt* if (code != TSDB_CODE_SUCCESS) { return code; } - taosArrayPush(pAlterReq->pFields, &field); + if (NULL == taosArrayPush(pAlterReq->pFields, &field)) { + return TSDB_CODE_OUT_OF_MEMORY; + } break; } case TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION: { - taosArrayDestroy(pAlterReq->pFields); + (void)taosArrayDestroy(pAlterReq->pFields); pAlterReq->pFields = taosArrayInit(1, sizeof(SFieldWithOptions)); + if (!pAlterReq->pFields) return TSDB_CODE_OUT_OF_MEMORY; SFieldWithOptions field = {.type = pStmt->dataType.type, .bytes = calcTypeBytes(pStmt->dataType)}; // TAOS_FIELD field = {.type = pStmt->dataType.type, .bytes = calcTypeBytes(pStmt->dataType)}; strcpy(field.name, pStmt->colName); @@ -8313,7 +8549,7 @@ static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt* return code; } } - taosArrayPush(pAlterReq->pFields, &field); + if (NULL == taosArrayPush(pAlterReq->pFields, &field)) return TSDB_CODE_OUT_OF_MEMORY; break; } default: @@ -8518,10 +8754,12 @@ static int32_t translateAlterSuperTable(STranslateContext* pCxt, SAlterTableStmt static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* pStmt) { SUseDbReq usedbReq = {0}; SName name = {0}; - tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); - tNameExtractFullName(&name, usedbReq.db); - int32_t code = - getDBVgVersion(pCxt, usedbReq.db, &usedbReq.vgVersion, &usedbReq.dbId, &usedbReq.numOfTable, &usedbReq.stateTs); + int32_t code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); + if (TSDB_CODE_SUCCESS == code) { + code = tNameExtractFullName(&name, usedbReq.db); + } + if (TSDB_CODE_SUCCESS == code) + code = getDBVgVersion(pCxt, usedbReq.db, &usedbReq.vgVersion, &usedbReq.dbId, &usedbReq.numOfTable, &usedbReq.stateTs); if (TSDB_CODE_SUCCESS == code) { code = buildCmdMsg(pCxt, TDMT_MND_USE_DB, (FSerializeFunc)tSerializeSUseDbReq, &usedbReq); } @@ -8735,20 +8973,23 @@ static int32_t getSmaIndexAst(STranslateContext* pCxt, SCreateIndexStmt* pStmt, static int32_t buildCreateSmaReq(STranslateContext* pCxt, SCreateIndexStmt* pStmt, SMCreateSmaReq* pReq) { SName name; - tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->indexDbName, pStmt->indexName, &name), pReq->name); - memset(&name, 0, sizeof(SName)); - tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name), pReq->stb); - pReq->igExists = pStmt->ignoreExists; - pReq->interval = ((SValueNode*)pStmt->pOptions->pInterval)->datum.i; - pReq->intervalUnit = ((SValueNode*)pStmt->pOptions->pInterval)->unit; - pReq->offset = (NULL != pStmt->pOptions->pOffset ? ((SValueNode*)pStmt->pOptions->pOffset)->datum.i : 0); - pReq->sliding = + int32_t code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->indexDbName, pStmt->indexName, &name), pReq->name); + if (TSDB_CODE_SUCCESS == code) { + memset(&name, 0, sizeof(SName)); + code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name), pReq->stb); + } + if (TSDB_CODE_SUCCESS == code) { + pReq->igExists = pStmt->ignoreExists; + pReq->interval = ((SValueNode*)pStmt->pOptions->pInterval)->datum.i; + pReq->intervalUnit = ((SValueNode*)pStmt->pOptions->pInterval)->unit; + pReq->offset = (NULL != pStmt->pOptions->pOffset ? ((SValueNode*)pStmt->pOptions->pOffset)->datum.i : 0); + pReq->sliding = (NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->datum.i : pReq->interval); - pReq->slidingUnit = + pReq->slidingUnit = (NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->unit : pReq->intervalUnit); + } - int32_t code = TSDB_CODE_SUCCESS; - if (NULL != pStmt->pOptions->pStreamOptions) { + if (TSDB_CODE_SUCCESS == code && NULL != pStmt->pOptions->pStreamOptions) { SStreamOptions* pStreamOpt = (SStreamOptions*)pStmt->pOptions->pStreamOptions; if (NULL != pStreamOpt->pDelay) { code = getTableMaxDelayOption(pCxt, (SValueNode*)pStreamOpt->pDelay, &pReq->maxDelay); @@ -8868,7 +9109,8 @@ int32_t translatePostCreateSmaIndex(SParseContext* pParseCxt, SQuery* pQuery, SS if (TSDB_CODE_SUCCESS == code) { code = setQuery(&pCxt, pQuery); } - setRefreshMeta(&pCxt, pQuery); + int32_t tmpCode = setRefreshMeta(&pCxt, pQuery); + if (TSDB_CODE_SUCCESS == code) code = tmpCode; destroyTranslateContext(&pCxt); tFreeSMCreateSmaReq(pStmt->pReq); taosMemoryFreeClear(pStmt->pReq); @@ -8882,14 +9124,17 @@ static int32_t buildCreateFullTextReq(STranslateContext* pCxt, SCreateIndexStmt* static int32_t buildCreateTagIndexReq(STranslateContext* pCxt, SCreateIndexStmt* pStmt, SCreateTagIndexReq* pReq) { SName name; - tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->indexDbName, pStmt->indexName, &name), pReq->idxName); - memset(&name, 0, sizeof(SName)); - - tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name), pReq->stbName); - memset(&name, 0, sizeof(SName)); - - tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); - tNameGetFullDbName(&name, pReq->dbFName); + int32_t code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->indexDbName, pStmt->indexName, &name), pReq->idxName); + if (TSDB_CODE_SUCCESS == code) { + memset(&name, 0, sizeof(SName)); + code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name), pReq->stbName); + } + if (TSDB_CODE_SUCCESS == code) { + memset(&name, 0, sizeof(SName)); + code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); + } + if (TSDB_CODE_SUCCESS != code) return code; + (void)tNameGetFullDbName(&name, pReq->dbFName); SNode* pNode = NULL; ASSERT(LIST_LENGTH(pStmt->pCols) == 1); @@ -8959,7 +9204,8 @@ static int32_t translateCreateIndex(STranslateContext* pCxt, SCreateIndexStmt* p static int32_t translateDropIndex(STranslateContext* pCxt, SDropIndexStmt* pStmt) { SMDropSmaReq dropSmaReq = {0}; SName name; - tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->indexDbName, pStmt->indexName, &name), dropSmaReq.name); + int32_t code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->indexDbName, pStmt->indexName, &name), dropSmaReq.name); + if (TSDB_CODE_SUCCESS != code) return code; dropSmaReq.igNotExists = pStmt->ignoreNotExists; return buildCmdMsg(pCxt, TDMT_MND_DROP_SMA, (FSerializeFunc)tSerializeSMDropSmaReq, &dropSmaReq); } @@ -9033,23 +9279,28 @@ static int32_t buildCreateTopicReq(STranslateContext* pCxt, SCreateTopicStmt* pS SName name; if ('\0' != pStmt->subSTbName[0]) { pReq->subType = TOPIC_SUB_TYPE__TABLE; - toName(pCxt->pParseCxt->acctId, pStmt->subDbName, pStmt->subSTbName, &name); - tNameGetFullDbName(&name, pReq->subDbName); - tNameExtractFullName(&name, pReq->subStbName); - if (pStmt->pQuery != NULL) { - code = nodesNodeToString(pStmt->pQuery, false, &pReq->ast, NULL); + (void)toName(pCxt->pParseCxt->acctId, pStmt->subDbName, pStmt->subSTbName, &name); + (void)tNameGetFullDbName(&name, pReq->subDbName); + if (TSDB_CODE_SUCCESS == code) { + (void)tNameExtractFullName(&name, pReq->subStbName); + if (pStmt->pQuery != NULL) { + code = nodesNodeToString(pStmt->pQuery, false, &pReq->ast, NULL); + } } } else if ('\0' != pStmt->subDbName[0]) { pReq->subType = TOPIC_SUB_TYPE__DB; - tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->subDbName, strlen(pStmt->subDbName)); - tNameGetFullDbName(&name, pReq->subDbName); + code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->subDbName, strlen(pStmt->subDbName)); + if (TSDB_CODE_SUCCESS == code) + (void)tNameGetFullDbName(&name, pReq->subDbName); } else { pReq->subType = TOPIC_SUB_TYPE__COLUMN; char* dbName = ((SRealTableNode*)(((SSelectStmt*)pStmt->pQuery)->pFromTable))->table.dbName; - tNameSetDbName(&name, pCxt->pParseCxt->acctId, dbName, strlen(dbName)); - tNameGetFullDbName(&name, pReq->subDbName); - pCxt->pParseCxt->topicQuery = true; - code = translateQuery(pCxt, pStmt->pQuery); + code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, dbName, strlen(dbName)); + if (TSDB_CODE_SUCCESS == code) { + (void)tNameGetFullDbName(&name, pReq->subDbName); + pCxt->pParseCxt->topicQuery = true; + code = translateQuery(pCxt, pStmt->pQuery); + } if (TSDB_CODE_SUCCESS == code) { code = checkTopicQuery(pCxt, (SSelectStmt*)pStmt->pQuery); } @@ -9061,14 +9312,20 @@ static int32_t buildCreateTopicReq(STranslateContext* pCxt, SCreateTopicStmt* pS return code; } -static int32_t addTagList(SNodeList** ppList, SNode* pNode) { +static int32_t addTagList(SNodeList** ppList, SNode** pNode) { if (NULL == *ppList) { *ppList = nodesMakeList(); + if (!*ppList) return TSDB_CODE_OUT_OF_MEMORY; } - nodesListStrictAppend(*ppList, pNode); + int32_t code = nodesListStrictAppend(*ppList, *pNode); + *pNode = NULL; + if (TSDB_CODE_SUCCESS != code) { + nodesDestroyList(*ppList); + *ppList = NULL; + } - return TSDB_CODE_SUCCESS; + return code; } static EDealRes checkColumnTagsInCond(SNode* pNode, void* pContext) { @@ -9080,7 +9337,10 @@ static EDealRes checkColumnTagsInCond(SNode* pNode, void* pContext) { pCxt->colExists = true; return DEAL_RES_ERROR; } else if (type == TCOL_TYPE_TAG) { - addTagList(&pCxt->pTags, nodesCloneNode(pNode)); + SNode* pNodeClone = nodesCloneNode(pNode); + int32_t code = addTagList(&pCxt->pTags, &pNodeClone); + if (TSDB_CODE_SUCCESS != code) nodesDestroyNode(pNodeClone); + return DEAL_RES_ERROR; } else { pCxt->colNotFound = true; return DEAL_RES_ERROR; @@ -9088,7 +9348,11 @@ static EDealRes checkColumnTagsInCond(SNode* pNode, void* pContext) { } else if (QUERY_NODE_FUNCTION == nodeType(pNode)) { SFunctionNode* pFunc = (SFunctionNode*)pNode; if (0 == strcasecmp(pFunc->functionName, "tbname")) { - addTagList(&pCxt->pTags, nodesCloneNode(pNode)); + SNode* pNodeClone = nodesCloneNode(pNode); + if (TSDB_CODE_SUCCESS != addTagList(&pCxt->pTags, &pNodeClone)) { + nodesDestroyNode(pNodeClone); + return DEAL_RES_ERROR; + } } } @@ -9116,8 +9380,11 @@ static int32_t checkCollectTopicTags(STranslateContext* pCxt, SCreateTopicStmt* strcpy(col->colName, column->name); strcpy(col->node.aliasName, col->colName); strcpy(col->node.userAlias, col->colName); - addTagList(&colCxt.pTags, (SNode*)col); - // } + int32_t code = addTagList(&colCxt.pTags, (SNode**)&col); + if (TSDB_CODE_SUCCESS != code) { + nodesDestroyNode((SNode*)col); + return code; + } } *ppProjection = colCxt.pTags; @@ -9207,9 +9474,11 @@ static int32_t translateDropTopic(STranslateContext* pCxt, SDropTopicStmt* pStmt static int32_t translateDropCGroup(STranslateContext* pCxt, SDropCGroupStmt* pStmt) { SMDropCgroupReq dropReq = {0}; - SName name; - tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->topicName, strlen(pStmt->topicName)); - tNameGetFullDbName(&name, dropReq.topic); + SName name; + int32_t code = TSDB_CODE_SUCCESS; + code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->topicName, strlen(pStmt->topicName)); + if (TSDB_CODE_SUCCESS != code) return code; + (void)tNameGetFullDbName(&name, dropReq.topic); dropReq.igNotExists = pStmt->ignoreNotExists; strcpy(dropReq.cgroup, pStmt->cgroup); @@ -9242,7 +9511,7 @@ static int32_t translateDescribe(STranslateContext* pCxt, SDescribeStmt* pStmt) if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) { int32_t origCode = code; SName name; - toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); + (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); SViewMeta* pMeta = NULL; code = getViewMetaFromMetaCache(pCxt, &name, &pMeta); if (TSDB_CODE_SUCCESS != code) { @@ -9250,7 +9519,7 @@ static int32_t translateDescribe(STranslateContext* pCxt, SDescribeStmt* pStmt) } else { SParseSqlRes res = {.resType = PARSE_SQL_RES_SCHEMA}; char dbFName[TSDB_DB_FNAME_LEN]; - tNameGetFullDbName(&name, dbFName); + (void)tNameGetFullDbName(&name, dbFName); code = (*pCxt->pParseCxt->parseSqlFp)(pCxt->pParseCxt->parseSqlParam, name.dbname, pMeta->querySql, false, pMeta->user, &res); if (TSDB_CODE_SUCCESS == code) { @@ -9299,9 +9568,12 @@ static int32_t translateCompactRange(STranslateContext* pCxt, SCompactDatabaseSt static int32_t translateCompact(STranslateContext* pCxt, SCompactDatabaseStmt* pStmt) { SCompactDbReq compactReq = {0}; SName name; - tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); - tNameGetFullDbName(&name, compactReq.db); - int32_t code = translateCompactRange(pCxt, pStmt, &compactReq); + int32_t code = TSDB_CODE_SUCCESS; + code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); + if (TSDB_CODE_SUCCESS != code) return code; + + (void)tNameGetFullDbName(&name, compactReq.db); + code = translateCompactRange(pCxt, pStmt, &compactReq); if (TSDB_CODE_SUCCESS == code) { code = buildCmdMsg(pCxt, TDMT_MND_COMPACT_DB, (FSerializeFunc)tSerializeSCompactDbReq, &compactReq); } @@ -9380,7 +9652,7 @@ static int32_t checkCreateStream(STranslateContext* pCxt, SCreateStreamStmt* pSt static void getSourceDatabase(SNode* pStmt, int32_t acctId, char* pDbFName) { SName name = {.type = TSDB_DB_NAME_T, .acctId = acctId}; strcpy(name.dbname, ((SRealTableNode*)(((SSelectStmt*)pStmt)->pFromTable))->table.dbName); - tNameGetFullDbName(&name, pDbFName); + (void)tNameGetFullDbName(&name, pDbFName); } static void getStreamQueryFirstProjectAliasName(SHashObj* pUserAliasSet, char* aliasName, int32_t len) { @@ -9568,8 +9840,8 @@ static int32_t addNullTagsToCreateStreamQuery(STranslateContext* pCxt, STableMet return addNullTagsForExistTable(pCxt, pMeta, (SSelectStmt*)pStmt->pQuery); } -static int32_t addColDefNodeByProj(SNodeList** ppCols, SNode* pProject, int8_t flags) { - SExprNode* pExpr = (SExprNode*)pProject; +static int32_t addColDefNodeByProj(SNodeList** ppCols, const SNode* pProject, int8_t flags) { + const SExprNode* pExpr = (const SExprNode*)pProject; SColumnDefNode* pColDef = (SColumnDefNode*)nodesMakeNode(QUERY_NODE_COLUMN_DEF); strcpy(pColDef->colName, pExpr->userAlias); pColDef->dataType = pExpr->resType; @@ -9702,7 +9974,9 @@ static int32_t checkStreamQuery(STranslateContext* pCxt, SCreateStreamStmt* pStm int64_t watermark = 0; if (pStmt->pOptions->pWatermark) { - translateValue(pCxt, (SValueNode*)pStmt->pOptions->pWatermark); + if (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pWatermark)) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY, "Invalid watermark value."); + } watermark = ((SValueNode*)pStmt->pOptions->pWatermark)->datum.i; } if (watermark <= 0) { @@ -9805,6 +10079,7 @@ static int32_t setFillNullCols(SArray* pProjColPos, const STableMeta* pMeta, SCM } const SSchema* pSchemas = getTableColumnSchema(pMeta); int32_t indexOfBoundCols = 0; + int32_t code = TSDB_CODE_SUCCESS; for (int32_t i = 0; i < pMeta->tableInfo.numOfColumns; ++i) { const SSchema* pSchema = pSchemas + i; if (indexOfBoundCols < numOfBoundCols) { @@ -9815,9 +10090,12 @@ static int32_t setFillNullCols(SArray* pProjColPos, const STableMeta* pMeta, SCM } } SColLocation colLoc = {.colId = pSchema->colId, .slotId = i, .type = pSchema->type}; - taosArrayPush(pReq->fillNullCols, &colLoc); + if (NULL == taosArrayPush(pReq->fillNullCols, &colLoc)) { + code = TSDB_CODE_OUT_OF_MEMORY; + break; + } } - return TSDB_CODE_SUCCESS; + return code; } static int32_t adjustOrderOfProjections(STranslateContext* pCxt, SNodeList** ppCols, const STableMeta* pMeta, @@ -9873,13 +10151,15 @@ static int32_t adjustOrderOfProjections(STranslateContext* pCxt, SNodeList** ppC int32_t num = taosArrayGetSize(pProjColPos); pNewProjections = nodesMakeList(); pNewCols = nodesMakeList(); - if (NULL == pNewProjections) { + if (NULL == pNewProjections || !pNewCols) { code = TSDB_CODE_OUT_OF_MEMORY; } for (int32_t i = 0; TSDB_CODE_SUCCESS == code && i < num; ++i) { SProjColPos* pPos = taosArrayGet(pProjColPos, i); code = nodesListStrictAppend(pNewProjections, pPos->pProj); - addColDefNodeByProj(&pNewCols, pPos->pProj, pPos->flags); + if (TSDB_CODE_SUCCESS == code) { + code = addColDefNodeByProj(&pNewCols, pPos->pProj, pPos->flags); + } pPos->pProj = NULL; } } @@ -9889,7 +10169,7 @@ static int32_t adjustOrderOfProjections(STranslateContext* pCxt, SNodeList** ppC } if (TSDB_CODE_SUCCESS == code) { - taosArrayDestroy(pProjColPos); + (void)taosArrayDestroy(pProjColPos); nodesDestroyList(*pProjections); nodesDestroyList(*ppCols); *pProjections = pNewProjections; @@ -9998,7 +10278,7 @@ static int32_t adjustOrderOfTags(STranslateContext* pCxt, SNodeList* pTags, cons } if (TSDB_CODE_SUCCESS == code) { - taosArrayDestroy(pTagPos); + (void)taosArrayDestroy(pTagPos); nodesDestroyList(*pTagExprs); *pTagExprs = pNewTagExprs; } else { @@ -10316,17 +10596,19 @@ static int32_t translateStreamOptions(STranslateContext* pCxt, SCreateStreamStmt static int32_t buildCreateStreamReq(STranslateContext* pCxt, SCreateStreamStmt* pStmt, SCMCreateStreamReq* pReq) { pReq->igExists = pStmt->ignoreExists; - SName name; - tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->streamName, strlen(pStmt->streamName)); - tNameGetFullDbName(&name, pReq->name); + SName name; + int32_t code = TSDB_CODE_SUCCESS; + code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->streamName, strlen(pStmt->streamName)); + if (TSDB_CODE_SUCCESS != code) return code; + (void)tNameGetFullDbName(&name, pReq->name); if ('\0' != pStmt->targetTabName[0]) { strcpy(name.dbname, pStmt->targetDbName); strcpy(name.tname, pStmt->targetTabName); - tNameExtractFullName(&name, pReq->targetStbFullName); + (void)tNameExtractFullName(&name, pReq->targetStbFullName); } - int32_t code = buildCreateStreamQuery(pCxt, pStmt, pReq); + code = buildCreateStreamQuery(pCxt, pStmt, pReq); if (TSDB_CODE_SUCCESS == code) { pReq->sql = taosStrdup(pCxt->pParseCxt->pSql); if (NULL == pReq->sql) { @@ -10346,12 +10628,14 @@ static int32_t buildCreateStreamReq(STranslateContext* pCxt, SCreateStreamStmt* (NULL != pStmt->pOptions->pDeleteMark ? ((SValueNode*)pStmt->pOptions->pDeleteMark)->datum.i : 0); pReq->fillHistory = pStmt->pOptions->fillHistory; pReq->igExpired = pStmt->pOptions->ignoreExpired; - if (pReq->createStb) { - tagDefNodeToField(pStmt->pTags, &pReq->pTags, true); - pReq->numOfTags = LIST_LENGTH(pStmt->pTags); - } - columnDefNodeToField(pStmt->pCols, &pReq->pCols, false); pReq->igUpdate = pStmt->pOptions->ignoreUpdate; + if (pReq->createStb) { + pReq->numOfTags = LIST_LENGTH(pStmt->pTags); + code = tagDefNodeToField(pStmt->pTags, &pReq->pTags, true); + } + if (TSDB_CODE_SUCCESS == code) { + code = columnDefNodeToField(pStmt->pCols, &pReq->pCols, false); + } } return code; @@ -10419,7 +10703,7 @@ static int32_t createStreamReqVersionInfo(SSDataBlock* pBlock, SArray** pArray, for (int32_t i = 0; i < pBlock->info.rows; ++i) { SVgroupVer v = {.vgId = *(int32_t*)colDataGetData(pCol1, i), .ver = *(int64_t*)colDataGetData(pCol2, i)}; - taosArrayPush(*pArray, &v); + (void)taosArrayPush(*pArray, &v); } } else { int32_t precision = (pInterval->interval > 0) ? pInterval->precision : TSDB_TIME_PRECISION_MILLI; @@ -10458,7 +10742,8 @@ int32_t translatePostCreateStream(SParseContext* pParseCxt, SQuery* pQuery, SSDa code = setQuery(&cxt, pQuery); } - setRefreshMeta(&cxt, pQuery); + int32_t tmpCode = setRefreshMeta(&cxt, pQuery); + if (TSDB_CODE_SUCCESS == code) code = tmpCode; destroyTranslateContext(&cxt); tFreeSCMCreateStreamReq(pStmt->pReq); @@ -10470,10 +10755,11 @@ int32_t translatePostCreateStream(SParseContext* pParseCxt, SQuery* pQuery, SSDa static int32_t translateDropStream(STranslateContext* pCxt, SDropStreamStmt* pStmt) { SMDropStreamReq dropReq = {0}; SName name; - tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->streamName, strlen(pStmt->streamName)); - tNameGetFullDbName(&name, dropReq.name); + int32_t code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->streamName, strlen(pStmt->streamName)); + if (TSDB_CODE_SUCCESS != code) return code; + (void)tNameGetFullDbName(&name, dropReq.name); dropReq.igNotExists = pStmt->ignoreNotExists; - int32_t code = buildCmdMsg(pCxt, TDMT_MND_DROP_STREAM, (FSerializeFunc)tSerializeSMDropStreamReq, &dropReq); + code = buildCmdMsg(pCxt, TDMT_MND_DROP_STREAM, (FSerializeFunc)tSerializeSMDropStreamReq, &dropReq); tFreeMDropStreamReq(&dropReq); return code; } @@ -10481,8 +10767,9 @@ static int32_t translateDropStream(STranslateContext* pCxt, SDropStreamStmt* pSt static int32_t translatePauseStream(STranslateContext* pCxt, SPauseStreamStmt* pStmt) { SMPauseStreamReq req = {0}; SName name; - tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->streamName, strlen(pStmt->streamName)); - tNameGetFullDbName(&name, req.name); + int32_t code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->streamName, strlen(pStmt->streamName)); + if (TSDB_CODE_SUCCESS != code) return code; + (void)tNameGetFullDbName(&name, req.name); req.igNotExists = pStmt->ignoreNotExists; return buildCmdMsg(pCxt, TDMT_MND_PAUSE_STREAM, (FSerializeFunc)tSerializeSMPauseStreamReq, &req); } @@ -10490,8 +10777,9 @@ static int32_t translatePauseStream(STranslateContext* pCxt, SPauseStreamStmt* p static int32_t translateResumeStream(STranslateContext* pCxt, SResumeStreamStmt* pStmt) { SMResumeStreamReq req = {0}; SName name; - tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->streamName, strlen(pStmt->streamName)); - tNameGetFullDbName(&name, req.name); + int32_t code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->streamName, strlen(pStmt->streamName)); + if (TSDB_CODE_SUCCESS != code) return code; + (void)tNameGetFullDbName(&name, req.name); req.igNotExists = pStmt->ignoreNotExists; req.igUntreated = pStmt->ignoreUntreated; return buildCmdMsg(pCxt, TDMT_MND_RESUME_STREAM, (FSerializeFunc)tSerializeSMResumeStreamReq, &req); @@ -10523,8 +10811,8 @@ static int32_t translateCreateView(STranslateContext* pCxt, SCreateViewStmt* pSt SParseSqlRes res = {.resType = PARSE_SQL_RES_SCHEMA}; SName name; char dbFName[TSDB_DB_FNAME_LEN]; - toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, &name); - tNameGetFullDbName(&name, dbFName); + (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, &name); + (void)tNameGetFullDbName(&name, dbFName); int32_t code = validateCreateView(pCxt, pStmt); if (TSDB_CODE_SUCCESS == code) { @@ -10564,18 +10852,20 @@ static int32_t translateDropView(STranslateContext* pCxt, SDropViewStmt* pStmt) SCMDropViewReq dropReq = {0}; SName name; - tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); - tNameGetFullDbName(&name, dropReq.dbFName); - strncpy(dropReq.name, pStmt->viewName, sizeof(dropReq.name) - 1); - snprintf(dropReq.fullname, sizeof(dropReq.fullname) - 1, "%s.%s", dropReq.dbFName, dropReq.name); - dropReq.sql = (char*)pCxt->pParseCxt->pSql; - if (NULL == dropReq.sql) { - return TSDB_CODE_OUT_OF_MEMORY; + int32_t code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); + if (TSDB_CODE_SUCCESS == code) { + (void)tNameGetFullDbName(&name, dropReq.dbFName); + strncpy(dropReq.name, pStmt->viewName, sizeof(dropReq.name) - 1); + snprintf(dropReq.fullname, sizeof(dropReq.fullname) - 1, "%s.%s", dropReq.dbFName, dropReq.name); + dropReq.sql = (char*)pCxt->pParseCxt->pSql; + if (NULL == dropReq.sql) { + return TSDB_CODE_OUT_OF_MEMORY; + } + dropReq.igNotExists = pStmt->ignoreNotExists; + (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, &name); + code = collectUseTable(&name, pCxt->pTargetTables); } - dropReq.igNotExists = pStmt->ignoreNotExists; - toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, &name); - int32_t code = collectUseTable(&name, pCxt->pTargetTables); if (TSDB_CODE_SUCCESS != code) { return code; } @@ -10608,12 +10898,11 @@ static int32_t readFromFile(char* pName, int32_t* len, char** buf) { int64_t s = taosReadFile(tfile, *buf, *len); if (s != *len) { - taosCloseFile(&tfile); + (void)taosCloseFile(&tfile); taosMemoryFreeClear(*buf); return TSDB_CODE_APP_ERROR; } - taosCloseFile(&tfile); - return TSDB_CODE_SUCCESS; + return taosCloseFile(&tfile); } static int32_t translateCreateFunction(STranslateContext* pCxt, SCreateFunctionStmt* pStmt) { @@ -10792,7 +11081,7 @@ static int32_t translateBalanceVgroup(STranslateContext* pCxt, SBalanceVgroupStm static int32_t translateBalanceVgroupLeader(STranslateContext* pCxt, SBalanceVgroupLeaderStmt* pStmt) { SBalanceVgroupLeaderReq req = {0}; req.vgId = pStmt->vgId; - if (pStmt->dbName != NULL) strcpy(req.db, pStmt->dbName); + strcpy(req.db, pStmt->dbName); int32_t code = buildCmdMsg(pCxt, TDMT_MND_BALANCE_VGROUP_LEADER, (FSerializeFunc)tSerializeSBalanceVgroupLeaderReq, &req); tFreeSBalanceVgroupLeaderReq(&req); @@ -10861,10 +11150,11 @@ static int32_t translateShowCreateDatabase(STranslateContext* pCxt, SShowCreateD } SName name; - tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); - tNameGetFullDbName(&name, pStmt->dbFName); - - return getDBCfg(pCxt, pStmt->dbName, (SDbCfgInfo*)pStmt->pCfg); + int32_t code = tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); + (void)tNameGetFullDbName(&name, pStmt->dbFName); + if (TSDB_CODE_SUCCESS == code) + return getDBCfg(pCxt, pStmt->dbName, (SDbCfgInfo*)pStmt->pCfg); + return code; } static int32_t translateShowCreateTable(STranslateContext* pCxt, SShowCreateTableStmt* pStmt) { @@ -10875,7 +11165,7 @@ static int32_t translateShowCreateTable(STranslateContext* pCxt, SShowCreateTabl int32_t code = getDBCfg(pCxt, pStmt->dbName, (SDbCfgInfo*)pStmt->pDbCfg); if (TSDB_CODE_SUCCESS == code) { SName name; - toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); + (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); code = getTableCfg(pCxt, &name, (STableCfg**)&pStmt->pTableCfg); } return code; @@ -10886,7 +11176,7 @@ static int32_t translateShowCreateView(STranslateContext* pCxt, SShowCreateViewS return TSDB_CODE_OPS_NOT_SUPPORT; #else SName name; - toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, &name); + (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, &name); return getViewMetaFromMetaCache(pCxt, &name, (SViewMeta**)&pStmt->pViewMeta); #endif } @@ -10926,7 +11216,7 @@ static int32_t compareTsmaFuncWithFuncAndColId(SNode* pNode1, SNode* pNode2) { } // pFuncs are already sorted by funcId and colId -static int32_t deduplicateTsmaFuncs(SNodeList* pFuncs) { +static void deduplicateTsmaFuncs(SNodeList* pFuncs) { SNode* pLast = NULL; SNode* pFunc = NULL; SNodeList* pRes = NULL; @@ -10942,7 +11232,6 @@ static int32_t deduplicateTsmaFuncs(SNodeList* pFuncs) { pLast = pFunc; } } - return TSDB_CODE_SUCCESS; } static int32_t buildTSMAAstStreamSubTable(SCreateTSMAStmt* pStmt, SMCreateSmaReq* pReq, const SNode* pTbname, @@ -11020,8 +11309,9 @@ static int32_t buildTSMAAst(STranslateContext* pCxt, SCreateTSMAStmt* pStmt, SMC code = TSDB_CODE_OUT_OF_MEMORY; break; } - nodesListAppend(info.pPartitionByList, pTagCol); - code = nodesListMakeStrictAppend(&info.pTags, nodesCloneNode(pTagCol)); + code = nodesListAppend(info.pPartitionByList, pTagCol); + if (TSDB_CODE_SUCCESS == code) + code = nodesListMakeStrictAppend(&info.pTags, nodesCloneNode(pTagCol)); } // sub table @@ -11081,13 +11371,14 @@ static int32_t rewriteTSMAFuncs(STranslateContext* pCxt, SCreateTSMAStmt* pStmt, pFunc = (SFunctionNode*)pNode; const SSchema* pSchema = pCols + i; code = createColumnBySchema(pSchema, &pCol); - if (code) break; - nodesListErase(pFunc->pParameterList, pFunc->pParameterList->pHead); - nodesListPushFront(pFunc->pParameterList, (SNode*)pCol); + if (TSDB_CODE_SUCCESS != code) break; + (void)nodesListErase(pFunc->pParameterList, pFunc->pParameterList->pHead); + code = nodesListPushFront(pFunc->pParameterList, (SNode*)pCol); + if (TSDB_CODE_SUCCESS != code) break; snprintf(pFunc->node.userAlias, TSDB_COL_NAME_LEN, "%s", pSchema->name); // for first or last, the second param will be pk ts col, here we should remove it if (fmIsImplicitTsFunc(pFunc->funcId) && LIST_LENGTH(pFunc->pParameterList) == 2) { - nodesListErase(pFunc->pParameterList, pFunc->pParameterList->pTail); + (void)nodesListErase(pFunc->pParameterList, pFunc->pParameterList->pTail); } ++i; } @@ -11140,13 +11431,16 @@ static int32_t buildCreateTSMAReq(STranslateContext* pCxt, SCreateTSMAStmt* pStm SName name; SDbCfgInfo pDbInfo = {0}; int32_t code = TSDB_CODE_SUCCESS; - tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tsmaName, &name), pReq->name); - memset(&name, 0, sizeof(SName)); - toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, useTbName); - tNameExtractFullName(useTbName, pReq->stb); - pReq->igExists = pStmt->ignoreExists; - - code = getDBCfg(pCxt, pStmt->dbName, &pDbInfo); + code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tsmaName, &name), pReq->name); + if (TSDB_CODE_SUCCESS == code) { + memset(&name, 0, sizeof(SName)); + (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, useTbName); + code = tNameExtractFullName(useTbName, pReq->stb); + } + if (TSDB_CODE_SUCCESS == code) { + pReq->igExists = pStmt->ignoreExists; + code = getDBCfg(pCxt, pStmt->dbName, &pDbInfo); + } if (code != TSDB_CODE_SUCCESS) { return code; } @@ -11182,12 +11476,14 @@ static int32_t buildCreateTSMAReq(STranslateContext* pCxt, SCreateTSMAStmt* pStm code = getTsma(pCxt, useTbName, &pRecursiveTsma); if (code == TSDB_CODE_SUCCESS) { pReq->recursiveTsma = true; - tNameExtractFullName(useTbName, pReq->baseTsmaName); - SValueNode* pInterval = (SValueNode*)pStmt->pOptions->pInterval; - if (checkRecursiveTsmaInterval(pRecursiveTsma->interval, pRecursiveTsma->unit, pInterval->datum.i, - pInterval->unit, pDbInfo.precision, true)) { - } else { - code = TSDB_CODE_TSMA_INVALID_PARA; + code = tNameExtractFullName(useTbName, pReq->baseTsmaName); + if (TSDB_CODE_SUCCESS == code) { + SValueNode* pInterval = (SValueNode*)pStmt->pOptions->pInterval; + if (checkRecursiveTsmaInterval(pRecursiveTsma->interval, pRecursiveTsma->unit, pInterval->datum.i, + pInterval->unit, pDbInfo.precision, true)) { + } else { + code = TSDB_CODE_TSMA_INVALID_PARA; + } } } if (code == TSDB_CODE_SUCCESS) { @@ -11199,17 +11495,24 @@ static int32_t buildCreateTSMAReq(STranslateContext* pCxt, SCreateTSMAStmt* pStm FOREACH(pNode, pSelect->pProjectionList) { SFunctionNode* pFuncNode = (SFunctionNode*)pNode; if (!fmIsTSMASupportedFunc(pFuncNode->funcId)) continue; - nodesListMakeStrictAppend(&pStmt->pOptions->pFuncs, nodesCloneNode(pNode)); + code = nodesListMakeStrictAppend(&pStmt->pOptions->pFuncs, nodesCloneNode(pNode)); + if (TSDB_CODE_SUCCESS != code) { + break; + } } nodesDestroyNode((SNode*)pSelect); - memset(useTbName, 0, sizeof(SName)); - memcpy(pStmt->originalTbName, pRecursiveTsma->tb, TSDB_TABLE_NAME_LEN); - tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pRecursiveTsma->tb, useTbName), pReq->stb); - numOfCols = pRecursiveTsma->pUsedCols->size; - numOfTags = pRecursiveTsma->pTags ? pRecursiveTsma->pTags->size : 0; - pCols = pRecursiveTsma->pUsedCols->pData; - pTags = pRecursiveTsma->pTags ? pRecursiveTsma->pTags->pData : NULL; - code = getTableMeta(pCxt, pStmt->dbName, pRecursiveTsma->targetTb, &pTableMeta); + if (TSDB_CODE_SUCCESS == code) { + memset(useTbName, 0, sizeof(SName)); + memcpy(pStmt->originalTbName, pRecursiveTsma->tb, TSDB_TABLE_NAME_LEN); + code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pRecursiveTsma->tb, useTbName), pReq->stb); + } + if (TSDB_CODE_SUCCESS == code) { + numOfCols = pRecursiveTsma->pUsedCols->size; + numOfTags = pRecursiveTsma->pTags ? pRecursiveTsma->pTags->size : 0; + pCols = pRecursiveTsma->pUsedCols->pData; + pTags = pRecursiveTsma->pTags ? pRecursiveTsma->pTags->pData : NULL; + code = getTableMeta(pCxt, pStmt->dbName, pRecursiveTsma->targetTb, &pTableMeta); + } } } else { code = getTableMeta(pCxt, pStmt->dbName, pStmt->tableName, &pTableMeta); @@ -11322,11 +11625,12 @@ int32_t translatePostCreateTSMA(SParseContext* pParseCxt, SQuery* pQuery, SSData if (TSDB_CODE_SUCCESS == code) { SName name = {0}; - toName(pParseCxt->acctId, pStmt->dbName, pStmt->originalTbName, &name); + (void)toName(pParseCxt->acctId, pStmt->dbName, pStmt->originalTbName, &name); code = collectUseTable(&name, cxt.pTargetTables); } - setRefreshMeta(&cxt, pQuery); + int32_t tmpCode = setRefreshMeta(&cxt, pQuery); + if (TSDB_CODE_SUCCESS == code) code = tmpCode; destroyTranslateContext(&cxt); tFreeSMCreateSmaReq(pStmt->pReq); @@ -11336,15 +11640,17 @@ int32_t translatePostCreateTSMA(SParseContext* pParseCxt, SQuery* pQuery, SSData } static int32_t translateDropTSMA(STranslateContext* pCxt, SDropTSMAStmt* pStmt) { - int32_t code = TSDB_CODE_SUCCESS; - SMDropSmaReq dropReq = {0}; - SName name; - tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tsmaName, &name), dropReq.name); - dropReq.igNotExists = pStmt->ignoreNotExists; + int32_t code = TSDB_CODE_SUCCESS; + SMDropSmaReq dropReq = {0}; + SName name; STableTSMAInfo* pTsma = NULL; - code = getTsma(pCxt, &name, &pTsma); + code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tsmaName, &name), dropReq.name); + if (TSDB_CODE_SUCCESS == code) { + dropReq.igNotExists = pStmt->ignoreNotExists; + code = getTsma(pCxt, &name, &pTsma); + } if (code == TSDB_CODE_SUCCESS) { - toName(pCxt->pParseCxt->acctId, pStmt->dbName, pTsma->tb, &name); + (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pTsma->tb, &name); code = collectUseTable(&name, pCxt->pTargetTables); } if (TSDB_CODE_SUCCESS == code) @@ -11798,20 +12104,26 @@ static SNode* createProjectCol(const char* pProjCol) { return (SNode*)pCol; } -static SNodeList* createProjectCols(int32_t ncols, const char* const pCols[]) { +static int32_t createProjectCols(int32_t ncols, const char* const pCols[], SNodeList** pResList) { SNodeList* pProjections = NULL; + int32_t code = TSDB_CODE_SUCCESS; if (0 == ncols) { - nodesListMakeStrictAppend(&pProjections, createStarCol()); - return pProjections; + code = nodesListMakeStrictAppend(&pProjections, createStarCol()); + if (TSDB_CODE_SUCCESS == code) + *pResList = pProjections; + else + nodesDestroyList(pProjections); + return code; } for (int32_t i = 0; i < ncols; ++i) { - int32_t code = nodesListMakeStrictAppend(&pProjections, createProjectCol(pCols[i])); + code = nodesListMakeStrictAppend(&pProjections, createProjectCol(pCols[i])); if (TSDB_CODE_SUCCESS != code) { nodesDestroyList(pProjections); - return NULL; + break; } } - return pProjections; + if (TSDB_CODE_SUCCESS == code) *pResList = pProjections; + return code; } static int32_t createSimpleSelectStmtImpl(const char* pDb, const char* pTable, SNodeList* pProjectionList, @@ -11842,10 +12154,8 @@ static int32_t createSimpleSelectStmtFromCols(const char* pDb, const char* pTabl const char* const pProjCol[], SSelectStmt** pStmt) { SNodeList* pProjectionList = NULL; if (numOfProjs >= 0) { - pProjectionList = createProjectCols(numOfProjs, pProjCol); - if (NULL == pProjectionList) { - return TSDB_CODE_OUT_OF_MEMORY; - } + int32_t code = createProjectCols(numOfProjs, pProjCol, &pProjectionList); + if (TSDB_CODE_SUCCESS != code) return code; } return createSimpleSelectStmtImpl(pDb, pTable, pProjectionList, pStmt); @@ -11924,7 +12234,8 @@ static const char* getTbNameColName(ENodeType type) { return colName; } -static int32_t createLogicCondNode(SNode* pCond1, SNode* pCond2, SNode** pCond, ELogicConditionType logicCondType) { +static int32_t createLogicCondNode(SNode** pCond1, SNode** pCond2, SNode** pCond, ELogicConditionType logicCondType) { + int32_t code = TSDB_CODE_SUCCESS; SLogicConditionNode* pCondition = (SLogicConditionNode*)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION); if (NULL == pCondition) { return TSDB_CODE_OUT_OF_MEMORY; @@ -11935,114 +12246,199 @@ static int32_t createLogicCondNode(SNode* pCond1, SNode* pCond2, SNode** pCond, nodesDestroyNode((SNode*)pCondition); return TSDB_CODE_OUT_OF_MEMORY; } - if (TSDB_CODE_SUCCESS != nodesListAppend(pCondition->pParameterList, pCond1) || - TSDB_CODE_SUCCESS != nodesListAppend(pCondition->pParameterList, pCond2)) { + code = nodesListAppend(pCondition->pParameterList, *pCond1); + if (TSDB_CODE_SUCCESS == code) { + *pCond1 = NULL; + code = nodesListAppend(pCondition->pParameterList, *pCond2); + } + if (TSDB_CODE_SUCCESS == code) { + *pCond2 = NULL; + *pCond = (SNode*)pCondition; + } else { nodesDestroyNode((SNode*)pCondition); - return TSDB_CODE_OUT_OF_MEMORY; } - *pCond = (SNode*)pCondition; - return TSDB_CODE_SUCCESS; + return code; } -static int32_t insertCondIntoSelectStmt(SSelectStmt* pSelect, SNode* pCond) { +static int32_t insertCondIntoSelectStmt(SSelectStmt* pSelect, SNode** pCond) { + int32_t code = TSDB_CODE_SUCCESS; if (pSelect->pWhere == NULL) { - pSelect->pWhere = pCond; + pSelect->pWhere = *pCond; + *pCond = NULL; } else { SNodeList* pLogicCondListWhere = NULL; SNodeList* pLogicCondList2 = NULL; if (nodeType(pSelect->pWhere) == QUERY_NODE_LOGIC_CONDITION && ((SLogicConditionNode*)pSelect->pWhere)->condType == LOGIC_COND_TYPE_AND) { pLogicCondListWhere = ((SLogicConditionNode*)pSelect->pWhere)->pParameterList; + ((SLogicConditionNode*)pSelect->pWhere)->pParameterList = NULL; } else { - nodesListMakeAppend(&pLogicCondListWhere, pSelect->pWhere); + code = nodesListMakeAppend(&pLogicCondListWhere, pSelect->pWhere); + if (TSDB_CODE_SUCCESS == code) { + pSelect->pWhere = NULL; + } } - if (nodeType(pCond) == QUERY_NODE_LOGIC_CONDITION && - ((SLogicConditionNode*)pCond)->condType == LOGIC_COND_TYPE_AND) { - pLogicCondList2 = ((SLogicConditionNode*)pCond)->pParameterList; - } else { - nodesListMakeAppend(&pLogicCondList2, pCond); + if (TSDB_CODE_SUCCESS == code) { + if (nodeType(*pCond) == QUERY_NODE_LOGIC_CONDITION && + ((SLogicConditionNode*)(*pCond))->condType == LOGIC_COND_TYPE_AND) { + pLogicCondList2 = ((SLogicConditionNode*)(*pCond))->pParameterList; + ((SLogicConditionNode*)(*pCond))->pParameterList = NULL; + } else { + code = nodesListMakeAppend(&pLogicCondList2, (*pCond)); + if (TSDB_CODE_SUCCESS == code) { + *pCond = NULL; + } + } } - nodesListAppendList(pLogicCondListWhere, pLogicCondList2); + if (TSDB_CODE_SUCCESS == code) { + code = nodesListAppendList(pLogicCondListWhere, pLogicCondList2); + } - SLogicConditionNode* pWhere = (SLogicConditionNode*)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION); - pWhere->condType = LOGIC_COND_TYPE_AND; - pWhere->pParameterList = pLogicCondListWhere; + if (TSDB_CODE_SUCCESS == code) { + SLogicConditionNode* pWhere = (SLogicConditionNode*)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION); + if (pWhere) { + pWhere->condType = LOGIC_COND_TYPE_AND; + pWhere->pParameterList = pLogicCondListWhere; - pSelect->pWhere = (SNode*)pWhere; + pSelect->pWhere = (SNode*)pWhere; + } + } + if (TSDB_CODE_SUCCESS != code) { + nodesDestroyList(pLogicCondListWhere); + nodesDestroyList(pLogicCondList2); + } } - return TSDB_CODE_SUCCESS; + return code; } static int32_t addShowUserDatabasesCond(SSelectStmt* pSelect) { + int32_t code = TSDB_CODE_SUCCESS; SNode* pNameCond1 = NULL; SNode* pNameCond2 = NULL; - SValueNode* pValNode1 = nodesMakeValueNodeFromString(TSDB_INFORMATION_SCHEMA_DB); - SValueNode* pValNode2 = nodesMakeValueNodeFromString(TSDB_PERFORMANCE_SCHEMA_DB); - createOperatorNode(OP_TYPE_NOT_EQUAL, "name", (SNode*)pValNode1, &pNameCond1); - createOperatorNode(OP_TYPE_NOT_EQUAL, "name", (SNode*)pValNode2, &pNameCond2); + SNode* pNameCond = NULL; + SValueNode* pValNode1 = NULL, *pValNode2 = NULL; + pValNode1 = nodesMakeValueNodeFromString(TSDB_INFORMATION_SCHEMA_DB); + if (!pValNode1) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + if (TSDB_CODE_SUCCESS == code) { + pValNode2 = nodesMakeValueNodeFromString(TSDB_PERFORMANCE_SCHEMA_DB); + if (!pValNode2) code = TSDB_CODE_OUT_OF_MEMORY; + } + if (TSDB_CODE_SUCCESS == code) { + code = createOperatorNode(OP_TYPE_NOT_EQUAL, "name", (SNode*)pValNode1, &pNameCond1); + } + if (TSDB_CODE_SUCCESS == code) { + code = createOperatorNode(OP_TYPE_NOT_EQUAL, "name", (SNode*)pValNode2, &pNameCond2); + } nodesDestroyNode((SNode*)pValNode2); nodesDestroyNode((SNode*)pValNode1); - SNode* pNameCond = NULL; - createLogicCondNode(pNameCond1, pNameCond2, &pNameCond, LOGIC_COND_TYPE_AND); - insertCondIntoSelectStmt(pSelect, pNameCond); - return TSDB_CODE_SUCCESS; + if (TSDB_CODE_SUCCESS == code) + code = createLogicCondNode(&pNameCond1, &pNameCond2, &pNameCond, LOGIC_COND_TYPE_AND); + + if (TSDB_CODE_SUCCESS == code) + code = insertCondIntoSelectStmt(pSelect, &pNameCond); + + if (TSDB_CODE_SUCCESS != code) { + nodesDestroyNode(pNameCond1); + nodesDestroyNode(pNameCond2); + nodesDestroyNode(pNameCond); + } + return code; } static int32_t addShowSystemDatabasesCond(SSelectStmt* pSelect) { + int32_t code = TSDB_CODE_SUCCESS; SNode* pNameCond1 = NULL; SNode* pNameCond2 = NULL; - SValueNode* pValNode1 = nodesMakeValueNodeFromString(TSDB_INFORMATION_SCHEMA_DB); - SValueNode* pValNode2 = nodesMakeValueNodeFromString(TSDB_PERFORMANCE_SCHEMA_DB); - createOperatorNode(OP_TYPE_EQUAL, "name", (SNode*)pValNode1, &pNameCond1); - createOperatorNode(OP_TYPE_EQUAL, "name", (SNode*)pValNode2, &pNameCond2); + SValueNode* pValNode1 = NULL, * pValNode2 = NULL; + SNode* pNameCond = NULL; + pValNode1 = nodesMakeValueNodeFromString(TSDB_INFORMATION_SCHEMA_DB); + if (!pValNode1) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + if (TSDB_CODE_SUCCESS == code) { + pValNode2 = nodesMakeValueNodeFromString(TSDB_PERFORMANCE_SCHEMA_DB); + if (!pValNode2) code = terrno; + } + if (TSDB_CODE_SUCCESS == code) { + code = createOperatorNode(OP_TYPE_EQUAL, "name", (SNode*)pValNode1, &pNameCond1); + } + if (TSDB_CODE_SUCCESS == code) { + code = createOperatorNode(OP_TYPE_EQUAL, "name", (SNode*)pValNode2, &pNameCond2); + } nodesDestroyNode((SNode*)pValNode2); nodesDestroyNode((SNode*)pValNode1); - SNode* pNameCond = NULL; - createLogicCondNode(pNameCond1, pNameCond2, &pNameCond, LOGIC_COND_TYPE_OR); - insertCondIntoSelectStmt(pSelect, pNameCond); - return TSDB_CODE_SUCCESS; + if (TSDB_CODE_SUCCESS == code) { + code = createLogicCondNode(&pNameCond1, &pNameCond2, &pNameCond, LOGIC_COND_TYPE_OR); + } + + if (TSDB_CODE_SUCCESS == code) + code = insertCondIntoSelectStmt(pSelect, &pNameCond); + + if (TSDB_CODE_SUCCESS != code) { + nodesDestroyNode(pNameCond1); + nodesDestroyNode(pNameCond2); + nodesDestroyNode(pNameCond); + } + return code; } static int32_t addShowNormalTablesCond(SSelectStmt* pSelect) { SNode* pTypeCond = NULL; + int32_t code = TSDB_CODE_SUCCESS; SValueNode* pValNode1 = nodesMakeValueNodeFromString("NORMAL_TABLE"); - createOperatorNode(OP_TYPE_EQUAL, "type", (SNode*)pValNode1, &pTypeCond); + if (!pValNode1) code = TSDB_CODE_OUT_OF_MEMORY; + + if (TSDB_CODE_SUCCESS == code) + code = createOperatorNode(OP_TYPE_EQUAL, "type", (SNode*)pValNode1, &pTypeCond); + nodesDestroyNode((SNode*)pValNode1); - insertCondIntoSelectStmt(pSelect, pTypeCond); - return TSDB_CODE_SUCCESS; + + if (TSDB_CODE_SUCCESS == code) code = insertCondIntoSelectStmt(pSelect, &pTypeCond); + if (TSDB_CODE_SUCCESS != code) nodesDestroyNode(pTypeCond); + return code; } static int32_t addShowChildTablesCond(SSelectStmt* pSelect) { + int32_t code = TSDB_CODE_SUCCESS; SNode* pTypeCond = NULL; SValueNode* pValNode1 = nodesMakeValueNodeFromString("CHILD_TABLE"); - createOperatorNode(OP_TYPE_EQUAL, "type", (SNode*)pValNode1, &pTypeCond); + if (!pValNode1) code = TSDB_CODE_OUT_OF_MEMORY; + + if (TSDB_CODE_SUCCESS == code) + code = createOperatorNode(OP_TYPE_EQUAL, "type", (SNode*)pValNode1, &pTypeCond); + nodesDestroyNode((SNode*)pValNode1); - insertCondIntoSelectStmt(pSelect, pTypeCond); - return TSDB_CODE_SUCCESS; + + if (TSDB_CODE_SUCCESS == code) code = insertCondIntoSelectStmt(pSelect, &pTypeCond); + if (TSDB_CODE_SUCCESS != code) nodesDestroyNode(pTypeCond); + return code; } static int32_t addShowKindCond(const SShowStmt* pShow, SSelectStmt* pSelect) { + int32_t code = TSDB_CODE_SUCCESS; if (pShow->type != QUERY_NODE_SHOW_DATABASES_STMT && pShow->type != QUERY_NODE_SHOW_TABLES_STMT || pShow->showKind == SHOW_KIND_ALL) { return TSDB_CODE_SUCCESS; } if (pShow->type == QUERY_NODE_SHOW_DATABASES_STMT) { if (pShow->showKind == SHOW_KIND_DATABASES_USER) { - addShowUserDatabasesCond(pSelect); + code = addShowUserDatabasesCond(pSelect); } else if (pShow->showKind == SHOW_KIND_DATABASES_SYSTEM) { - addShowSystemDatabasesCond(pSelect); + code = addShowSystemDatabasesCond(pSelect); } } else if (pShow->type == QUERY_NODE_SHOW_TABLES_STMT) { if (pShow->showKind == SHOW_KIND_TABLES_NORMAL) { - addShowNormalTablesCond(pSelect); + code = addShowNormalTablesCond(pSelect); } else if (pShow->showKind == SHOW_KIND_TABLES_CHILD) { - addShowChildTablesCond(pSelect); + code = addShowChildTablesCond(pSelect); } } - return TSDB_CODE_SUCCESS; + return code; } static int32_t createShowCondition(const SShowStmt* pShow, SSelectStmt* pSelect) { @@ -12057,7 +12453,7 @@ static int32_t createShowCondition(const SShowStmt* pShow, SSelectStmt* pSelect) } if (NULL != pDbCond && NULL != pTbCond) { - if (TSDB_CODE_SUCCESS != createLogicCondNode(pDbCond, pTbCond, &pSelect->pWhere, LOGIC_COND_TYPE_AND)) { + if (TSDB_CODE_SUCCESS != createLogicCondNode(&pDbCond, &pTbCond, &pSelect->pWhere, LOGIC_COND_TYPE_AND)) { nodesDestroyNode(pDbCond); nodesDestroyNode(pTbCond); return TSDB_CODE_OUT_OF_MEMORY; @@ -12195,7 +12591,7 @@ static int32_t rewriteShowDnodeVariables(STranslateContext* pCxt, SQuery* pQuery } if (TSDB_CODE_SUCCESS == code) { if (NULL != pLikeCond) { - code = createLogicCondNode(pDnodeCond, pLikeCond, &pSelect->pWhere, LOGIC_COND_TYPE_AND); + code = createLogicCondNode(&pDnodeCond, &pLikeCond, &pSelect->pWhere, LOGIC_COND_TYPE_AND); } else { pSelect->pWhere = pDnodeCond; } @@ -12279,8 +12675,8 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* SVgroupCreateTableBatch* pBatch) { char dbFName[TSDB_DB_FNAME_LEN] = {0}; SName name = {.type = TSDB_DB_NAME_T, .acctId = acctId}; - strcpy(name.dbname, pStmt->dbName); - tNameGetFullDbName(&name, dbFName); + (void)strcpy(name.dbname, pStmt->dbName); + (void)tNameGetFullDbName(&name, dbFName); SVCreateTbReq req = {0}; req.type = TD_NORMAL_TABLE; @@ -12327,13 +12723,16 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* ++index; } pBatch->info = *pVgroupInfo; - strcpy(pBatch->dbName, pStmt->dbName); + (void)strcpy(pBatch->dbName, pStmt->dbName); pBatch->req.pArray = taosArrayInit(1, sizeof(struct SVCreateTbReq)); if (NULL == pBatch->req.pArray) { tdDestroySVCreateTbReq(&req); return TSDB_CODE_OUT_OF_MEMORY; } - taosArrayPush(pBatch->req.pArray, &req); + if (NULL == taosArrayPush(pBatch->req.pArray, &req)) { + tdDestroySVCreateTbReq(&req); + return TSDB_CODE_OUT_OF_MEMORY; + } return TSDB_CODE_SUCCESS; } @@ -12344,6 +12743,9 @@ static int32_t serializeVgroupCreateTableBatch(SVgroupCreateTableBatch* pTbBatch int32_t ret = 0; tEncodeSize(tEncodeSVCreateTbBatchReq, &pTbBatch->req, tlen, ret); + if (TSDB_CODE_SUCCESS != ret) { + return ret; + } tlen += sizeof(SMsgHead); void* buf = taosMemoryMalloc(tlen); if (NULL == buf) { @@ -12354,20 +12756,29 @@ static int32_t serializeVgroupCreateTableBatch(SVgroupCreateTableBatch* pTbBatch void* pBuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); tEncoderInit(&coder, pBuf, tlen - sizeof(SMsgHead)); - tEncodeSVCreateTbBatchReq(&coder, &pTbBatch->req); + ret = tEncodeSVCreateTbBatchReq(&coder, &pTbBatch->req); tEncoderClear(&coder); + if (TSDB_CODE_SUCCESS != ret) { + taosMemoryFreeClear(buf); + return ret; + } SVgDataBlocks* pVgData = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); if (NULL == pVgData) { + taosMemoryFreeClear(buf); return TSDB_CODE_OUT_OF_MEMORY; } pVgData->vg = pTbBatch->info; pVgData->pData = buf; pVgData->size = tlen; pVgData->numOfTables = (int32_t)taosArrayGetSize(pTbBatch->req.pArray); - taosArrayPush(pBufArray, &pVgData); + if (NULL == taosArrayPush(pBufArray, &pVgData)) { + ret = TSDB_CODE_OUT_OF_MEMORY; + taosMemoryFreeClear(buf); + taosMemoryFreeClear(pVgData); + } - return TSDB_CODE_SUCCESS; + return ret; } static void destroyCreateTbReqBatch(void* data) { @@ -12378,7 +12789,7 @@ static void destroyCreateTbReqBatch(void* data) { tdDestroySVCreateTbReq(pTableReq); } - taosArrayDestroy(pTbBatch->req.pArray); + (void)taosArrayDestroy(pTbBatch->req.pArray); } int32_t rewriteToVnodeModifyOpStmt(SQuery* pQuery, SArray* pBufArray) { @@ -12400,7 +12811,7 @@ static void destroyCreateTbReqArray(SArray* pArray) { taosMemoryFreeClear(pVg->pData); taosMemoryFreeClear(pVg); } - taosArrayDestroy(pArray); + (void)taosArrayDestroy(pArray); } static int32_t buildCreateTableDataBlock(int32_t acctId, const SCreateTableStmt* pStmt, const SVgroupInfo* pInfo, @@ -12429,7 +12840,7 @@ static int32_t rewriteCreateTable(STranslateContext* pCxt, SQuery* pQuery) { int32_t code = checkCreateTable(pCxt, pStmt, false); SVgroupInfo info = {0}; SName name; - toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); + (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); if (TSDB_CODE_SUCCESS == code) { code = getTableHashVgroupImpl(pCxt, &name, &info); } @@ -12478,6 +12889,7 @@ static int32_t addCreateTbReqIntoVgroup(SHashObj* pVgroupHashmap, const char* db return TSDB_CODE_OUT_OF_MEMORY; } + int32_t code = TSDB_CODE_SUCCESS; SVgroupCreateTableBatch* pTableBatch = taosHashGet(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId)); if (pTableBatch == NULL) { SVgroupCreateTableBatch tBatch = {0}; @@ -12485,14 +12897,28 @@ static int32_t addCreateTbReqIntoVgroup(SHashObj* pVgroupHashmap, const char* db strcpy(tBatch.dbName, dbName); tBatch.req.pArray = taosArrayInit(4, sizeof(struct SVCreateTbReq)); - taosArrayPush(tBatch.req.pArray, &req); - - taosHashPut(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId), &tBatch, sizeof(tBatch)); + if (!tBatch.req.pArray) { + code = terrno; + } else if (NULL == taosArrayPush(tBatch.req.pArray, &req)) { + (void)taosArrayDestroy(tBatch.req.pArray); + code = TSDB_CODE_OUT_OF_MEMORY; + } else { + code = taosHashPut(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId), &tBatch, sizeof(tBatch)); + if (TSDB_CODE_SUCCESS != code) { + (void)taosArrayDestroy(tBatch.req.pArray); + } + } } else { // add to the correct vgroup - taosArrayPush(pTableBatch->req.pArray, &req); + if (NULL == taosArrayPush(pTableBatch->req.pArray, &req)) { + code = TSDB_CODE_OUT_OF_MEMORY; + } } - return TSDB_CODE_SUCCESS; + if (TSDB_CODE_SUCCESS != code) { + tdDestroySVCreateTbReq(&req); + } + + return code; } static int32_t createCastFuncForTag(STranslateContext* pCxt, SNode* pNode, SDataType dt, SNode** pCast) { @@ -12575,7 +13001,7 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla taosMemoryFreeClear(p->pData); } } - taosArrayDestroy(pTagArray); + (void)taosArrayDestroy(pTagArray); return code; } @@ -12638,7 +13064,7 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau taosMemoryFreeClear(p->pData); } } - taosArrayDestroy(pTagArray); + (void)taosArrayDestroy(pTagArray); return code; } @@ -12661,7 +13087,7 @@ static int32_t rewriteCreateSubTable(STranslateContext* pCxt, SCreateSubTableCla } if (TSDB_CODE_SUCCESS == code) { SName name; - toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); + (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); code = collectUseTable(&name, pCxt->pTargetTables); } @@ -12689,7 +13115,7 @@ static int32_t rewriteCreateSubTable(STranslateContext* pCxt, SCreateSubTableCla taosMemoryFree(pTag); } - taosArrayDestroy(tagName); + (void)taosArrayDestroy(tagName); taosMemoryFreeClear(pSuperTableMeta); return code; } @@ -12900,7 +13326,7 @@ static int32_t parseCsvFile(SMsgBuf* pMsgBuf, SParseContext* pParseCxt, SParseFi if (pLine[0] == '#') continue; // ignore comment line begins with '#' - strtolower(pLine, pLine); + (void)strtolower(pLine, pLine); pParFileCxt->pSql = pLine; code = parseOneStbRow(pMsgBuf, pParFileCxt); @@ -12927,7 +13353,10 @@ static int32_t parseCsvFile(SMsgBuf* pMsgBuf, SParseContext* pParseCxt, SParseFi .pTag = pParFileCxt->pTag, .vg = pParFileCxt->vg}; - taosArrayPush(pParFileCxt->aCreateTbData, &data); + if (NULL == taosArrayPush(pParFileCxt->aCreateTbData, &data)) { + taosMemoryFreeClear(pParFileCxt->pTag); + code = TSDB_CODE_OUT_OF_MEMORY; + } } else { taosMemoryFreeClear(pParFileCxt->pTag); } @@ -13132,10 +13561,10 @@ static int32_t createSubTableFromFile(SMsgBuf* pMsgBuf, SParseContext* pParseCxt return code; } -SArray* serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap) { +int32_t serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap, SArray** pOut) { SArray* pBufArray = taosArrayInit(taosHashGetSize(pVgroupHashmap), sizeof(void*)); if (NULL == pBufArray) { - return NULL; + return terrno; } int32_t code = TSDB_CODE_SUCCESS; @@ -13146,10 +13575,20 @@ SArray* serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap) { break; } - serializeVgroupCreateTableBatch(pTbBatch, pBufArray); + code = serializeVgroupCreateTableBatch(pTbBatch, pBufArray); + if (TSDB_CODE_SUCCESS != code) { + taosHashCancelIterate(pVgroupHashmap, pTbBatch); + break; + } } while (true); - return pBufArray; + if (TSDB_CODE_SUCCESS != code) { + (void)taosArrayDestroy(pBufArray); + } else { + *pOut = pBufArray; + } + + return code; } static int32_t rewriteCreateMultiTable(STranslateContext* pCxt, SQuery* pQuery) { @@ -13172,10 +13611,11 @@ static int32_t rewriteCreateMultiTable(STranslateContext* pCxt, SQuery* pQuery) } } - SArray* pBufArray = serializeVgroupsCreateTableBatch(pVgroupHashmap); + SArray* pBufArray = NULL; + code = serializeVgroupsCreateTableBatch(pVgroupHashmap, &pBufArray); taosHashCleanup(pVgroupHashmap); - if (NULL == pBufArray) { - return TSDB_CODE_OUT_OF_MEMORY; + if (TSDB_CODE_SUCCESS != code) { + return code; } return rewriteToVnodeModifyOpStmt(pQuery, pBufArray); @@ -13209,11 +13649,12 @@ static int32_t rewriteCreateTableFromFile(STranslateContext* pCxt, SQuery* pQuer return code; } - SArray* pBufArray = serializeVgroupsCreateTableBatch(pModifyStmt->pVgroupsHashObj); + SArray* pBufArray = NULL; + code = serializeVgroupsCreateTableBatch(pModifyStmt->pVgroupsHashObj, &pBufArray); taosHashClear(pModifyStmt->pVgroupsHashObj); - if (NULL == pBufArray) { + if (TSDB_CODE_SUCCESS != code) { taosHashCleanup(pModifyStmt->pVgroupsHashObj); - return TSDB_CODE_OUT_OF_MEMORY; + return code; } pModifyStmt->pDataBlocks = pBufArray; @@ -13231,10 +13672,10 @@ int32_t continueCreateTbFromFile(SParseContext* pParseCxt, SQuery** pQuery) { int32_t code = createSubTableFromFile(&tmpBuf, pParseCxt, pModifyStmt); if (TSDB_CODE_SUCCESS != code) goto _OUT; - SArray* pBufArray = serializeVgroupsCreateTableBatch(pModifyStmt->pVgroupsHashObj); + SArray* pBufArray = NULL; + code = serializeVgroupsCreateTableBatch(pModifyStmt->pVgroupsHashObj, &pBufArray); taosHashClear(pModifyStmt->pVgroupsHashObj); - if (NULL == pBufArray) { - code = TSDB_CODE_OUT_OF_MEMORY; + if (TSDB_CODE_SUCCESS != code) { goto _OUT; } @@ -13256,18 +13697,31 @@ typedef struct SVgroupDropTableBatch { char dbName[TSDB_DB_NAME_LEN]; } SVgroupDropTableBatch; -static void addDropTbReqIntoVgroup(SHashObj* pVgroupHashmap, SVgroupInfo* pVgInfo, SVDropTbReq* pReq) { +static int32_t addDropTbReqIntoVgroup(SHashObj* pVgroupHashmap, SVgroupInfo* pVgInfo, SVDropTbReq* pReq) { SVgroupDropTableBatch* pTableBatch = taosHashGet(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId)); + int32_t code = TSDB_CODE_SUCCESS; if (NULL == pTableBatch) { SVgroupDropTableBatch tBatch = {0}; tBatch.info = *pVgInfo; tBatch.req.pArray = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SVDropTbReq)); - taosArrayPush(tBatch.req.pArray, pReq); + if (NULL == taosArrayPush(tBatch.req.pArray, pReq)) { + (void)taosArrayDestroy(tBatch.req.pArray); + tBatch.req.pArray = NULL; + return TSDB_CODE_OUT_OF_MEMORY; + } - taosHashPut(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId), &tBatch, sizeof(tBatch)); + code = taosHashPut(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId), &tBatch, sizeof(tBatch)); + if (TSDB_CODE_SUCCESS != code) { + (void)taosArrayDestroy(tBatch.req.pArray); + tBatch.req.pArray = NULL; + return code; + } } else { // add to the correct vgroup - taosArrayPush(pTableBatch->req.pArray, pReq); + if (NULL == taosArrayPush(pTableBatch->req.pArray, pReq)) { + return TSDB_CODE_OUT_OF_MEMORY; + } } + return code; } static int32_t buildDropTableVgroupHashmap(STranslateContext* pCxt, SDropTableClause* pClause, const SName* name, @@ -13295,7 +13749,7 @@ static int32_t buildDropTableVgroupHashmap(STranslateContext* pCxt, SDropTableCl if (TSDB_CODE_SUCCESS == code) { SVDropTbReq req = {.suid = pTableMeta->suid, .igNotExists = pClause->ignoreNotExists}; req.name = pClause->tableName; - addDropTbReqIntoVgroup(pVgroupHashmap, &info, &req); + code = addDropTbReqIntoVgroup(pVgroupHashmap, &info, &req); } over: @@ -13305,7 +13759,7 @@ over: static void destroyDropTbReqBatch(void* data) { SVgroupDropTableBatch* pTbBatch = (SVgroupDropTableBatch*)data; - taosArrayDestroy(pTbBatch->req.pArray); + (void)taosArrayDestroy(pTbBatch->req.pArray); } static int32_t serializeVgroupDropTableBatch(SVgroupDropTableBatch* pTbBatch, SArray* pBufArray) { @@ -13314,6 +13768,7 @@ static int32_t serializeVgroupDropTableBatch(SVgroupDropTableBatch* pTbBatch, SA int32_t ret = 0; tEncodeSize(tEncodeSVDropTbBatchReq, &pTbBatch->req, tlen, ret); + if (TSDB_CODE_SUCCESS != ret) return ret; tlen += sizeof(SMsgHead); void* buf = taosMemoryMalloc(tlen); if (NULL == buf) { @@ -13324,26 +13779,35 @@ static int32_t serializeVgroupDropTableBatch(SVgroupDropTableBatch* pTbBatch, SA void* pBuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); tEncoderInit(&coder, pBuf, tlen - sizeof(SMsgHead)); - tEncodeSVDropTbBatchReq(&coder, &pTbBatch->req); + ret = tEncodeSVDropTbBatchReq(&coder, &pTbBatch->req); tEncoderClear(&coder); + if (TSDB_CODE_SUCCESS != ret) { + taosMemoryFreeClear(buf); + return ret; + } SVgDataBlocks* pVgData = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); if (NULL == pVgData) { + taosMemoryFreeClear(buf); return TSDB_CODE_OUT_OF_MEMORY; } pVgData->vg = pTbBatch->info; pVgData->pData = buf; pVgData->size = tlen; pVgData->numOfTables = (int32_t)taosArrayGetSize(pTbBatch->req.pArray); - taosArrayPush(pBufArray, &pVgData); + if (NULL == taosArrayPush(pBufArray, &pVgData)) { + ret = TSDB_CODE_OUT_OF_MEMORY; + taosMemoryFreeClear(pVgData); + taosMemoryFreeClear(buf); + } - return TSDB_CODE_SUCCESS; + return ret; } -SArray* serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap) { +int32_t serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap, SArray** pOut) { SArray* pBufArray = taosArrayInit(taosHashGetSize(pVgroupHashmap), sizeof(void*)); if (NULL == pBufArray) { - return NULL; + return terrno; } int32_t code = TSDB_CODE_SUCCESS; @@ -13354,10 +13818,16 @@ SArray* serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap) { break; } - serializeVgroupDropTableBatch(pTbBatch, pBufArray); + code = serializeVgroupDropTableBatch(pTbBatch, pBufArray); + if (TSDB_CODE_SUCCESS != code) { + taosHashCancelIterate(pVgroupHashmap, pTbBatch); + (void)taosArrayDestroy(pBufArray); + break; + } } while (true); - return pBufArray; + *pOut = pBufArray; + return code; } static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) { @@ -13375,7 +13845,7 @@ static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) { FOREACH(pNode, pStmt->pTables) { SDropTableClause* pClause = (SDropTableClause*)pNode; SName name; - toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &name); + (void)toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &name); int32_t code = buildDropTableVgroupHashmap(pCxt, pClause, &name, &tableType, pVgroupHashmap); if (TSDB_CODE_SUCCESS != code) { taosHashCleanup(pVgroupHashmap); @@ -13420,20 +13890,26 @@ static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) { SMDropTbReqsOnSingleVg reqOnVg = {0}; reqOnVg.vgInfo = pTbBatch->info; reqOnVg.pTbs = pTbBatch->req.pArray; - taosArrayPush(req.pVgReqs, &reqOnVg); + if (NULL == taosArrayPush(req.pVgReqs, &reqOnVg)) { + taosHashCancelIterate(pVgroupHashmap, pTbBatch); + code = TSDB_CODE_OUT_OF_MEMORY; + break; + } } while (true); - - code = buildCmdMsg(pCxt, TDMT_MND_DROP_TB_WITH_TSMA, (FSerializeFunc)tSerializeSMDropTbsReq, &req); - taosArrayDestroy(req.pVgReqs); + if (TSDB_CODE_SUCCESS == code) { + code = buildCmdMsg(pCxt, TDMT_MND_DROP_TB_WITH_TSMA, (FSerializeFunc)tSerializeSMDropTbsReq, &req); + } + (void)taosArrayDestroy(req.pVgReqs); } taosHashCleanup(pVgroupHashmap); return code; } - SArray* pBufArray = serializeVgroupsDropTableBatch(pVgroupHashmap); + SArray* pBufArray = NULL; + code = serializeVgroupsDropTableBatch(pVgroupHashmap, &pBufArray); taosHashCleanup(pVgroupHashmap); - if (NULL == pBufArray) { - return TSDB_CODE_OUT_OF_MEMORY; + if (TSDB_CODE_SUCCESS != code) { + return code; } return rewriteToVnodeModifyOpStmt(pQuery, pBufArray); @@ -13445,7 +13921,7 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS SArray* pTsmas = NULL; int32_t code = TSDB_CODE_SUCCESS; if (pCxt->pMetaCache) { - toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tbName); + (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tbName); code = getTableTsmasFromCache(pCxt->pMetaCache, &tbName, &pTsmas); if (code != TSDB_CODE_SUCCESS) return code; if (pTsmas && pTsmas->size > 0) return TSDB_CODE_TSMA_MUST_BE_DROPPED; @@ -13629,7 +14105,7 @@ static int32_t buildRenameColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt SArray* pTsmas = NULL; SName tbName; int32_t code = 0; - toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tbName); + (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tbName); if (pCxt->pMetaCache) code = getTableTsmasFromCache(pCxt->pMetaCache, &tbName, &pTsmas); if (TSDB_CODE_SUCCESS != code) return code; if (pTsmas && pTsmas->size > 0) { @@ -13754,7 +14230,10 @@ static int32_t serializeAlterTbReq(STranslateContext* pCxt, SAlterTableStmt* pSt void* pBuf = POINTER_SHIFT(pMsg, sizeof(SMsgHead)); SEncoder coder = {0}; tEncoderInit(&coder, pBuf, tlen - sizeof(SMsgHead)); - tEncodeSVAlterTbReq(&coder, pReq); + if (TSDB_CODE_SUCCESS != tEncodeSVAlterTbReq(&coder, pReq)) { + taosMemoryFree(pMsg); + return terrno; + } tEncoderClear(&coder); SVgDataBlocks* pVgData = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); @@ -13766,7 +14245,9 @@ static int32_t serializeAlterTbReq(STranslateContext* pCxt, SAlterTableStmt* pSt pVgData->pData = pMsg; pVgData->size = tlen; pVgData->numOfTables = 1; - taosArrayPush(pArray, &pVgData); + if (NULL == taosArrayPush(pArray, &pVgData)) { + code = TSDB_CODE_OUT_OF_MEMORY; + } } return code; @@ -13783,7 +14264,7 @@ static int32_t buildModifyVnodeArray(STranslateContext* pCxt, SAlterTableStmt* p if (TSDB_CODE_SUCCESS == code) { *pArray = pTmpArray; } else { - taosArrayDestroy(pTmpArray); + (void)taosArrayDestroy(pTmpArray); } return code; @@ -13801,7 +14282,7 @@ static void destoryAlterTbReq(SVAlterTbReq* pReq) { taosMemoryFreeClear(p->pData); } } - taosArrayDestroy(pReq->pTagArray); + (void)taosArrayDestroy(pReq->pTagArray); if (pReq->tagFree) tTagFree((STag*)pReq->pTagVal); } @@ -13853,6 +14334,7 @@ static int32_t rewriteAlterTable(STranslateContext* pCxt, SQuery* pQuery) { static int32_t serializeFlushVgroup(SVgroupInfo* pVg, SArray* pBufArray) { int32_t len = sizeof(SMsgHead); void* buf = taosMemoryMalloc(len); + int32_t code = TSDB_CODE_SUCCESS; if (NULL == buf) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -13867,9 +14349,11 @@ static int32_t serializeFlushVgroup(SVgroupInfo* pVg, SArray* pBufArray) { pVgData->vg = *pVg; pVgData->pData = buf; pVgData->size = len; - taosArrayPush(pBufArray, &pVgData); + if (NULL == taosArrayPush(pBufArray, &pVgData)) { + code = TSDB_CODE_OUT_OF_MEMORY; + } - return TSDB_CODE_SUCCESS; + return code; } static int32_t serializeFlushDb(SArray* pVgs, SArray** pOutput) { @@ -13883,7 +14367,7 @@ static int32_t serializeFlushDb(SArray* pVgs, SArray** pOutput) { for (int32_t i = 0; i < numOfVgs; ++i) { int32_t code = serializeFlushVgroup((SVgroupInfo*)taosArrayGet(pVgs, i), pBufArray); if (TSDB_CODE_SUCCESS != code) { - taosArrayDestroy(pBufArray); + (void)taosArrayDestroy(pBufArray); return code; } } @@ -13905,9 +14389,9 @@ static int32_t rewriteFlushDatabase(STranslateContext* pCxt, SQuery* pQuery) { code = rewriteToVnodeModifyOpStmt(pQuery, pBufArray); } if (TSDB_CODE_SUCCESS != code) { - taosArrayDestroy(pBufArray); + (void)taosArrayDestroy(pBufArray); } - taosArrayDestroy(pVgs); + (void)taosArrayDestroy(pVgs); return code; } @@ -14026,9 +14510,9 @@ static int32_t rewriteShowAliveStmt(STranslateContext* pCxt, SQuery* pQuery) { SNode* pTemp1 = NULL; SNode* pTemp2 = NULL; SNode* pFullCond = NULL; - CHECK_RES_OUT_OF_MEM(createLogicCondNode(pCond1, pCond2, &pTemp1, LOGIC_COND_TYPE_OR)); - CHECK_RES_OUT_OF_MEM(createLogicCondNode(pTemp1, pCond3, &pTemp2, LOGIC_COND_TYPE_OR)); - CHECK_RES_OUT_OF_MEM(createLogicCondNode(pTemp2, pCond4, &pFullCond, LOGIC_COND_TYPE_OR)); + CHECK_RES_OUT_OF_MEM(createLogicCondNode(&pCond1, &pCond2, &pTemp1, LOGIC_COND_TYPE_OR)); + CHECK_RES_OUT_OF_MEM(createLogicCondNode(&pTemp1, &pCond3, &pTemp2, LOGIC_COND_TYPE_OR)); + CHECK_RES_OUT_OF_MEM(createLogicCondNode(&pTemp2, &pCond4, &pFullCond, LOGIC_COND_TYPE_OR)); SNode* pThen = nodesMakeValueNodeFromInt32(1); CHECK_POINTER_OUT_OF_MEM(pThen); @@ -14093,7 +14577,7 @@ static int32_t rewriteShowAliveStmt(STranslateContext* pCxt, SQuery* pQuery) { CHECK_RES_OUT_OF_MEM(createOperatorNode(OP_TYPE_GREATER_THAN, pSumColAlias, pTempVal, &pCond2)); // leader_col = count_col and leader_col > 0 pTemp1 = NULL; - CHECK_RES_OUT_OF_MEM(createLogicCondNode(pCond1, pCond2, &pTemp1, LOGIC_COND_TYPE_AND)); + CHECK_RES_OUT_OF_MEM(createLogicCondNode(&pCond1, &pCond2, &pTemp1, LOGIC_COND_TYPE_AND)); pThen = nodesMakeValueNodeFromInt32(1); CHECK_POINTER_OUT_OF_MEM(pThen); @@ -14108,7 +14592,7 @@ static int32_t rewriteShowAliveStmt(STranslateContext* pCxt, SQuery* pQuery) { CHECK_RES_OUT_OF_MEM(createOperatorNode(OP_TYPE_GREATER_THAN, pSumColAlias, pTempVal, &pCond2)); // leader_col < count_col and leader_col > 0 pTemp2 = NULL; - CHECK_RES_OUT_OF_MEM(createLogicCondNode(pCond1, pCond2, &pTemp2, LOGIC_COND_TYPE_AND)); + CHECK_RES_OUT_OF_MEM(createLogicCondNode(&pCond1, &pCond2, &pTemp2, LOGIC_COND_TYPE_AND)); nodesDestroyNode((SNode*)pTempVal); pThen = nodesMakeValueNodeFromInt32(2); @@ -14247,40 +14731,49 @@ static int32_t toMsgType(ENodeType type) { static int32_t setRefreshMeta(STranslateContext* pCxt, SQuery* pQuery) { if (NULL != pCxt->pDbs) { - taosArrayDestroy(pQuery->pDbList); + (void)taosArrayDestroy(pQuery->pDbList); pQuery->pDbList = taosArrayInit(taosHashGetSize(pCxt->pDbs), TSDB_DB_FNAME_LEN); if (NULL == pQuery->pDbList) { return TSDB_CODE_OUT_OF_MEMORY; } SFullDatabaseName* pDb = taosHashIterate(pCxt->pDbs, NULL); while (NULL != pDb) { - taosArrayPush(pQuery->pDbList, pDb->fullDbName); + if (NULL == taosArrayPush(pQuery->pDbList, pDb->fullDbName)) { + taosHashCancelIterate(pCxt->pDbs, pDb); + return TSDB_CODE_OUT_OF_MEMORY; + } pDb = taosHashIterate(pCxt->pDbs, pDb); } } if (NULL != pCxt->pTables) { - taosArrayDestroy(pQuery->pTableList); + (void)taosArrayDestroy(pQuery->pTableList); pQuery->pTableList = taosArrayInit(taosHashGetSize(pCxt->pTables), sizeof(SName)); if (NULL == pQuery->pTableList) { return TSDB_CODE_OUT_OF_MEMORY; } SName* pTable = taosHashIterate(pCxt->pTables, NULL); while (NULL != pTable) { - taosArrayPush(pQuery->pTableList, pTable); + if (NULL == taosArrayPush(pQuery->pTableList, pTable)) { + taosHashCancelIterate(pCxt->pTables, pTable); + return TSDB_CODE_OUT_OF_MEMORY; + } pTable = taosHashIterate(pCxt->pTables, pTable); } } if (NULL != pCxt->pTargetTables) { - taosArrayDestroy(pQuery->pTargetTableList); + (void)taosArrayDestroy(pQuery->pTargetTableList); pQuery->pTargetTableList = taosArrayInit(taosHashGetSize(pCxt->pTargetTables), sizeof(SName)); if (NULL == pQuery->pTargetTableList) { return TSDB_CODE_OUT_OF_MEMORY; } SName* pTable = taosHashIterate(pCxt->pTargetTables, NULL); while (NULL != pTable) { - taosArrayPush(pQuery->pTargetTableList, pTable); + if (NULL == taosArrayPush(pQuery->pTargetTableList, pTable)) { + taosHashCancelIterate(pCxt->pTargetTables, pTable); + return TSDB_CODE_OUT_OF_MEMORY; + } pTable = taosHashIterate(pCxt->pTargetTables, pTable); } } @@ -14381,7 +14874,8 @@ int32_t translate(SParseContext* pParseCxt, SQuery* pQuery, SParseMetaCache* pMe if (TSDB_CODE_SUCCESS == code) { code = setQuery(&cxt, pQuery); } - setRefreshMeta(&cxt, pQuery); + int32_t tmpCode = setRefreshMeta(&cxt, pQuery); + if (TSDB_CODE_SUCCESS == code) code = tmpCode; destroyTranslateContext(&cxt); return code; }