From 3027e377fa2c0c155026eb606a1ab6d9cd95eb18 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 23 Nov 2024 22:18:30 +0800 Subject: [PATCH 01/25] support update multi tag --- include/common/tmsg.h | 40 +- include/libs/nodes/cmdnodes.h | 34 +- source/common/src/tmsg.c | 55 +- source/dnode/vnode/src/meta/metaTable.c | 4 + source/libs/nodes/src/nodesUtilFuncs.c | 675 +++++++++++++++--------- source/libs/parser/inc/parAst.h | 2 + source/libs/parser/inc/sql.y | 11 +- source/libs/parser/src/parAstCreater.c | 34 +- source/libs/parser/src/parAstParser.c | 18 +- source/libs/parser/src/parTranslater.c | 206 ++++++-- 10 files changed, 758 insertions(+), 321 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 70a32cd266..27169b0a4e 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -178,6 +178,7 @@ typedef enum _mgmt_table { #define TSDB_ALTER_TABLE_DROP_TAG_INDEX 12 #define TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS 13 #define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION 14 +#define TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL 15 #define TSDB_FILL_NONE 0 #define TSDB_FILL_NULL 1 @@ -351,6 +352,7 @@ typedef enum ENodeType { QUERY_NODE_CREATE_ANODE_STMT, QUERY_NODE_DROP_ANODE_STMT, QUERY_NODE_UPDATE_ANODE_STMT, + QUERY_NODE_ALTER_TABLE_MULTI_STMT, // show statement nodes // see 'sysTableShowAdapter', 'SYSTABLE_SHOW_TYPE_OFFSET' @@ -421,7 +423,7 @@ typedef enum ENodeType { // physical plan node QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN = 1100, QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN, - QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN, // INACTIVE + QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN, // INACTIVE QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN, @@ -435,7 +437,7 @@ typedef enum ENodeType { QUERY_NODE_PHYSICAL_PLAN_SORT, QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT, QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL, - QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL, // INACTIVE + QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL, // INACTIVE QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL, QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL, QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL, @@ -985,7 +987,6 @@ typedef struct SEpSet { SEp eps[TSDB_MAX_REPLICA]; } SEpSet; - int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp); int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp); int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp); @@ -3259,6 +3260,16 @@ int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp); int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp); // TDMT_VND_ALTER_TABLE ===================== +typedef struct SMultiTagUpateVal { + char* tagName; + int32_t colId; + int8_t tagType; + int8_t tagFree; + uint32_t nTagVal; + uint8_t* pTagVal; + int8_t isNull; + SArray* pTagArray; +} SMultiTagUpateVal; typedef struct { char* tbName; int8_t action; @@ -3285,9 +3296,10 @@ typedef struct { int32_t newTTL; int32_t newCommentLen; char* newComment; - int64_t ctimeMs; // fill by vnode - int8_t source; // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient - uint32_t compress; // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS + int64_t ctimeMs; // fill by vnode + int8_t source; // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient + uint32_t compress; // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS + SArray* pMultiTag; // TSDB_ALTER_TABLE_ADD_MULTI_TAGS } SVAlterTbReq; int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq); @@ -4143,20 +4155,20 @@ typedef struct { SArray* blockTbName; SArray* blockSchema; - union{ - struct{ - int64_t sleepTime; + union { + struct { + int64_t sleepTime; }; - struct{ - int32_t createTableNum; - SArray* createTableLen; - SArray* createTableReq; + struct { + int32_t createTableNum; + SArray* createTableLen; + SArray* createTableReq; }; }; } SMqDataRsp; -int32_t tEncodeMqDataRsp(SEncoder *pEncoder, const SMqDataRsp *pObj); +int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj); int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp); void tDeleteMqDataRsp(SMqDataRsp* pRsp); diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 867f8c8efc..6623811712 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -264,8 +264,30 @@ typedef struct SAlterTableStmt { SDataType dataType; SValueNode* pVal; SColumnOptions* pColOptions; + SNodeList* pNodeListTagValue; } SAlterTableStmt; + +typedef struct SAlterTableStmt2 { + ENodeType type; + int8_t alterType; + char colName[TSDB_COL_NAME_LEN]; + STableOptions* pOptions; + SDataType dataType; + SValueNode* pVal; + SColumnOptions* pColOptions; + +} SAlterTableStmt2; + +typedef struct SAlterTableMultiStmt { + ENodeType type; + char dbName[TSDB_DB_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; + int8_t alterType; + + SNodeList* pNodeListTagValue; +} SAlterTableMultiStmt; + typedef struct SCreateUserStmt { ENodeType type; char userName[TSDB_USER_LEN]; @@ -341,7 +363,7 @@ typedef struct SShowStmt { SNode* pTbName; // SValueNode EOperatorType tableCondType; EShowKind showKind; // show databases: user/system, show tables: normal/child, others NULL - bool withFull; // for show users full; + bool withFull; // for show users full; } SShowStmt; typedef struct SShowCreateDatabaseStmt { @@ -651,7 +673,7 @@ typedef struct SCreateTSMAStmt { bool ignoreExists; char tsmaName[TSDB_TABLE_NAME_LEN]; char dbName[TSDB_DB_NAME_LEN]; - char tableName[TSDB_TABLE_NAME_LEN]; // base tb name or base tsma name + char tableName[TSDB_TABLE_NAME_LEN]; // base tb name or base tsma name char originalTbName[TSDB_TABLE_NAME_LEN]; STSMAOptions* pOptions; SNode* pPrevQuery; @@ -660,10 +682,10 @@ typedef struct SCreateTSMAStmt { } SCreateTSMAStmt; typedef struct SDropTSMAStmt { - ENodeType type; - bool ignoreNotExists; - char dbName[TSDB_DB_NAME_LEN]; - char tsmaName[TSDB_TABLE_NAME_LEN]; + ENodeType type; + bool ignoreNotExists; + char dbName[TSDB_DB_NAME_LEN]; + char tsmaName[TSDB_TABLE_NAME_LEN]; } SDropTSMAStmt; #ifdef __cplusplus diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 814ec4a626..134a5cf8c5 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -2166,9 +2166,9 @@ int32_t tSerializeRetrieveAnalAlgoRsp(void *buf, int32_t bufLen, SRetrieveAnalAl int32_t numOfAlgos = 0; void *pIter = taosHashIterate(pRsp->hash, NULL); while (pIter != NULL) { - SAnalyticsUrl *pUrl = pIter; - size_t nameLen = 0; - const char *name = taosHashGetKey(pIter, &nameLen); + SAnalyticsUrl *pUrl = pIter; + size_t nameLen = 0; + const char *name = taosHashGetKey(pIter, &nameLen); if (nameLen > 0 && nameLen <= TSDB_ANALYTIC_ALGO_KEY_LEN && pUrl->urlLen > 0) { numOfAlgos++; } @@ -2181,9 +2181,9 @@ int32_t tSerializeRetrieveAnalAlgoRsp(void *buf, int32_t bufLen, SRetrieveAnalAl pIter = taosHashIterate(pRsp->hash, NULL); while (pIter != NULL) { - SAnalyticsUrl *pUrl = pIter; - size_t nameLen = 0; - const char *name = taosHashGetKey(pIter, &nameLen); + SAnalyticsUrl *pUrl = pIter; + size_t nameLen = 0; + const char *name = taosHashGetKey(pIter, &nameLen); if (nameLen > 0 && pUrl->urlLen > 0) { TAOS_CHECK_EXIT(tEncodeI32(&encoder, nameLen)); TAOS_CHECK_EXIT(tEncodeBinary(&encoder, (const uint8_t *)name, nameLen)); @@ -2221,10 +2221,10 @@ int32_t tDeserializeRetrieveAnalAlgoRsp(void *buf, int32_t bufLen, SRetrieveAnal int32_t lino; tDecoderInit(&decoder, buf, bufLen); - int32_t numOfAlgos = 0; - int32_t nameLen; - int32_t type; - char name[TSDB_ANALYTIC_ALGO_KEY_LEN]; + int32_t numOfAlgos = 0; + int32_t nameLen; + int32_t type; + char name[TSDB_ANALYTIC_ALGO_KEY_LEN]; SAnalyticsUrl url = {0}; TAOS_CHECK_EXIT(tStartDecode(&decoder)); @@ -10511,6 +10511,20 @@ int32_t tEncodeSVAlterTbReq(SEncoder *pEncoder, const SVAlterTbReq *pReq) { TAOS_CHECK_EXIT(tEncodeBinary(pEncoder, pReq->pTagVal, pReq->nTagVal)); } break; + case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL: + int32_t nTags = taosArrayGetSize(pReq->pMultiTag); + TAOS_CHECK_EXIT(tEncodeI32v(pEncoder, nTags)); + for (int32_t i = 0; i < nTags; i++) { + SMultiTagUpateVal *pTag = taosArrayGet(pReq->pMultiTag, i); + TAOS_CHECK_EXIT(tEncodeI32v(pEncoder, pTag->colId)); + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pTag->tagName)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTag->isNull)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTag->tagType)); + if (!pTag->isNull) { + TAOS_CHECK_EXIT(tEncodeBinary(pEncoder, pTag->pTagVal, pReq->nTagVal)); + } + } + break; case TSDB_ALTER_TABLE_UPDATE_OPTIONS: TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pReq->updateTTL)); if (pReq->updateTTL) { @@ -10577,6 +10591,27 @@ static int32_t tDecodeSVAlterTbReqCommon(SDecoder *pDecoder, SVAlterTbReq *pReq) TAOS_CHECK_EXIT(tDecodeBinary(pDecoder, &pReq->pTagVal, &pReq->nTagVal)); } break; + case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL: + int32_t nTags; + TAOS_CHECK_EXIT(tDecodeI32v(pDecoder, &nTags)); + pReq->pMultiTag = taosArrayInit(nTags, sizeof(SMultiTagUpateVal)); + if (pReq->pMultiTag == NULL) { + TAOS_CHECK_EXIT(terrno); + } + for (int32_t i = 0; i < nTags; i++) { + SMultiTagUpateVal tag; + TAOS_CHECK_EXIT(tDecodeI32v(pDecoder, &tag.colId)); + TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &tag.tagName)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &tag.isNull)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &tag.tagType)); + if (!tag.isNull) { + TAOS_CHECK_EXIT(tDecodeBinary(pDecoder, &tag.pTagVal, &tag.nTagVal)); + } + if (taosArrayPush(pReq->pMultiTag, &tag) == NULL) { + TAOS_CHECK_EXIT(terrno); + } + } + break; case TSDB_ALTER_TABLE_UPDATE_OPTIONS: TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pReq->updateTTL)); if (pReq->updateTTL) { diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 5c3516a962..03b8bdd93f 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -2011,6 +2011,7 @@ _err: return terrno != 0 ? terrno : TSDB_CODE_FAILED; } +static int metaUpdateTableMultiTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) { return 0; } static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) { SMetaEntry ctbEntry = {0}; SMetaEntry stbEntry = {0}; @@ -2736,6 +2737,9 @@ int metaAlterTable(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMeta return metaAlterTableColumn(pMeta, version, pReq, pMetaRsp); case TSDB_ALTER_TABLE_UPDATE_TAG_VAL: return metaUpdateTableTagVal(pMeta, version, pReq); + case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL: + return metaUpdateTableMultiTagVal(pMeta, version, pReq); + return terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION; case TSDB_ALTER_TABLE_UPDATE_OPTIONS: return metaUpdateTableOptions(pMeta, version, pReq); case TSDB_ALTER_TABLE_ADD_TAG_INDEX: diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 30cc552761..25d1ecd6f9 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -14,6 +14,7 @@ */ #include "cmdnodes.h" +#include "functionMgt.h" #include "nodesUtil.h" #include "plannodes.h" #include "querynodes.h" @@ -22,7 +23,6 @@ #include "tdatablock.h" #include "thash.h" #include "tref.h" -#include "functionMgt.h" typedef struct SNodeMemChunk { int32_t availableSize; @@ -56,15 +56,13 @@ char* getJoinSTypeString(EJoinSubType type) { char* getFullJoinTypeString(EJoinType type, EJoinSubType stype) { static char* joinFullType[][8] = { - {"INNER", "INNER", "INNER", "INNER", "INNER", "INNER ANY", "INNER", "INNER"}, - {"LEFT", "LEFT", "LEFT OUTER", "LEFT SEMI", "LEFT ANTI", "LEFT ANY", "LEFT ASOF", "LEFT WINDOW"}, - {"RIGHT", "RIGHT", "RIGHT OUTER", "RIGHT SEMI", "RIGHT ANTI", "RIGHT ANY", "RIGHT ASOF", "RIGHT WINDOW"}, - {"FULL", "FULL", "FULL OUTER", "FULL", "FULL", "FULL ANY", "FULL", "FULL"} - }; + {"INNER", "INNER", "INNER", "INNER", "INNER", "INNER ANY", "INNER", "INNER"}, + {"LEFT", "LEFT", "LEFT OUTER", "LEFT SEMI", "LEFT ANTI", "LEFT ANY", "LEFT ASOF", "LEFT WINDOW"}, + {"RIGHT", "RIGHT", "RIGHT OUTER", "RIGHT SEMI", "RIGHT ANTI", "RIGHT ANY", "RIGHT ASOF", "RIGHT WINDOW"}, + {"FULL", "FULL", "FULL OUTER", "FULL", "FULL", "FULL ANY", "FULL", "FULL"}}; return joinFullType[type][stype]; } - int32_t mergeJoinConds(SNode** ppDst, SNode** ppSrc) { if (NULL == *ppSrc) { return TSDB_CODE_SUCCESS; @@ -74,14 +72,16 @@ int32_t mergeJoinConds(SNode** ppDst, SNode** ppSrc) { *ppSrc = NULL; return TSDB_CODE_SUCCESS; } - if (QUERY_NODE_LOGIC_CONDITION == nodeType(*ppSrc) && ((SLogicConditionNode*)(*ppSrc))->condType == LOGIC_COND_TYPE_AND) { + if (QUERY_NODE_LOGIC_CONDITION == nodeType(*ppSrc) && + ((SLogicConditionNode*)(*ppSrc))->condType == LOGIC_COND_TYPE_AND) { TSWAP(*ppDst, *ppSrc); } int32_t code = 0; if (QUERY_NODE_LOGIC_CONDITION == nodeType(*ppDst)) { SLogicConditionNode* pDst = (SLogicConditionNode*)*ppDst; if (pDst->condType == LOGIC_COND_TYPE_AND) { - if (QUERY_NODE_LOGIC_CONDITION == nodeType(*ppSrc) && ((SLogicConditionNode*)(*ppSrc))->condType == LOGIC_COND_TYPE_AND) { + if (QUERY_NODE_LOGIC_CONDITION == nodeType(*ppSrc) && + ((SLogicConditionNode*)(*ppSrc))->condType == LOGIC_COND_TYPE_AND) { code = nodesListStrictAppendList(pDst->pParameterList, ((SLogicConditionNode*)(*ppSrc))->pParameterList); ((SLogicConditionNode*)(*ppSrc))->pParameterList = NULL; } else { @@ -109,13 +109,12 @@ int32_t mergeJoinConds(SNode** ppDst, SNode** ppSrc) { *ppSrc = NULL; code = nodesListMakeStrictAppend(&pLogicCond->pParameterList, *ppDst); } - if (TSDB_CODE_SUCCESS == code) { + if (TSDB_CODE_SUCCESS == code) { *ppDst = (SNode*)pLogicCond; } return code; } - static int32_t callocNodeChunk(SNodeAllocator* pAllocator, SNodeMemChunk** pOutChunk) { SNodeMemChunk* pNewChunk = taosMemoryCalloc(1, sizeof(SNodeMemChunk) + pAllocator->chunkSize); if (NULL == pNewChunk) { @@ -155,11 +154,12 @@ static int32_t nodesCallocImpl(int32_t size, void** pOut) { void* p = g_pNodeAllocator->pCurrChunk->pBuf + g_pNodeAllocator->pCurrChunk->usedSize; g_pNodeAllocator->pCurrChunk->usedSize += size; *pOut = p; - return TSDB_CODE_SUCCESS;; + return TSDB_CODE_SUCCESS; + ; } static int32_t nodesCalloc(int32_t num, int32_t size, void** pOut) { - void* p = NULL; + void* p = NULL; int32_t code = nodesCallocImpl(num * size + 1, &p); if (TSDB_CODE_SUCCESS != code) { return code; @@ -237,7 +237,8 @@ void nodesDestroyAllocatorSet() { refId = pAllocator->self; int32_t code = taosRemoveRef(g_allocatorReqRefPool, refId); if (TSDB_CODE_SUCCESS != code) { - nodesError("failed to remove ref at: %s:%d, rsetId:%d, refId:%"PRId64, __func__, __LINE__, g_allocatorReqRefPool, refId); + nodesError("failed to remove ref at: %s:%d, rsetId:%d, refId:%" PRId64, __func__, __LINE__, + g_allocatorReqRefPool, refId); } pAllocator = taosIterateRef(g_allocatorReqRefPool, refId); } @@ -333,7 +334,8 @@ void nodesDestroyAllocator(int64_t allocatorId) { int32_t code = taosRemoveRef(g_allocatorReqRefPool, allocatorId); if (TSDB_CODE_SUCCESS != code) { - nodesError("failed to remove ref at: %s:%d, rsetId:%d, refId:%"PRId64, __func__, __LINE__, g_allocatorReqRefPool, allocatorId); + nodesError("failed to remove ref at: %s:%d, rsetId:%d, refId:%" PRId64, __func__, __LINE__, g_allocatorReqRefPool, + allocatorId); } } @@ -348,202 +350,297 @@ static int32_t makeNode(ENodeType type, int32_t size, SNode** ppNode) { } int32_t nodesMakeNode(ENodeType type, SNode** ppNodeOut) { - SNode* pNode = NULL; + SNode* pNode = NULL; int32_t code = 0; switch (type) { case QUERY_NODE_COLUMN: - code = makeNode(type, sizeof(SColumnNode), &pNode); break; + code = makeNode(type, sizeof(SColumnNode), &pNode); + break; case QUERY_NODE_VALUE: - code = makeNode(type, sizeof(SValueNode), &pNode); break; + code = makeNode(type, sizeof(SValueNode), &pNode); + break; case QUERY_NODE_OPERATOR: - code = makeNode(type, sizeof(SOperatorNode), &pNode); break; + code = makeNode(type, sizeof(SOperatorNode), &pNode); + break; case QUERY_NODE_LOGIC_CONDITION: - code = makeNode(type, sizeof(SLogicConditionNode), &pNode); break; + code = makeNode(type, sizeof(SLogicConditionNode), &pNode); + break; case QUERY_NODE_FUNCTION: - code = makeNode(type, sizeof(SFunctionNode), &pNode); break; + code = makeNode(type, sizeof(SFunctionNode), &pNode); + break; case QUERY_NODE_REAL_TABLE: - code = makeNode(type, sizeof(SRealTableNode), &pNode); break; + code = makeNode(type, sizeof(SRealTableNode), &pNode); + break; case QUERY_NODE_TEMP_TABLE: - code = makeNode(type, sizeof(STempTableNode), &pNode); break; + code = makeNode(type, sizeof(STempTableNode), &pNode); + break; case QUERY_NODE_JOIN_TABLE: - code = makeNode(type, sizeof(SJoinTableNode), &pNode); break; + code = makeNode(type, sizeof(SJoinTableNode), &pNode); + break; case QUERY_NODE_GROUPING_SET: - code = makeNode(type, sizeof(SGroupingSetNode), &pNode); break; + code = makeNode(type, sizeof(SGroupingSetNode), &pNode); + break; case QUERY_NODE_ORDER_BY_EXPR: - code = makeNode(type, sizeof(SOrderByExprNode), &pNode); break; + code = makeNode(type, sizeof(SOrderByExprNode), &pNode); + break; case QUERY_NODE_LIMIT: - code = makeNode(type, sizeof(SLimitNode), &pNode); break; + code = makeNode(type, sizeof(SLimitNode), &pNode); + break; case QUERY_NODE_STATE_WINDOW: - code = makeNode(type, sizeof(SStateWindowNode), &pNode); break; + code = makeNode(type, sizeof(SStateWindowNode), &pNode); + break; case QUERY_NODE_SESSION_WINDOW: - code = makeNode(type, sizeof(SSessionWindowNode), &pNode); break; + code = makeNode(type, sizeof(SSessionWindowNode), &pNode); + break; case QUERY_NODE_INTERVAL_WINDOW: - code = makeNode(type, sizeof(SIntervalWindowNode), &pNode); break; + code = makeNode(type, sizeof(SIntervalWindowNode), &pNode); + break; case QUERY_NODE_NODE_LIST: - code = makeNode(type, sizeof(SNodeListNode), &pNode); break; + code = makeNode(type, sizeof(SNodeListNode), &pNode); + break; case QUERY_NODE_FILL: - code = makeNode(type, sizeof(SFillNode), &pNode); break; + code = makeNode(type, sizeof(SFillNode), &pNode); + break; case QUERY_NODE_RAW_EXPR: - code = makeNode(type, sizeof(SRawExprNode), &pNode); break; + code = makeNode(type, sizeof(SRawExprNode), &pNode); + break; case QUERY_NODE_TARGET: - code = makeNode(type, sizeof(STargetNode), &pNode); break; + code = makeNode(type, sizeof(STargetNode), &pNode); + break; case QUERY_NODE_DATABLOCK_DESC: - code = makeNode(type, sizeof(SDataBlockDescNode), &pNode); break; + code = makeNode(type, sizeof(SDataBlockDescNode), &pNode); + break; case QUERY_NODE_SLOT_DESC: - code = makeNode(type, sizeof(SSlotDescNode), &pNode); break; + code = makeNode(type, sizeof(SSlotDescNode), &pNode); + break; case QUERY_NODE_COLUMN_DEF: - code = makeNode(type, sizeof(SColumnDefNode), &pNode); break; + code = makeNode(type, sizeof(SColumnDefNode), &pNode); + break; case QUERY_NODE_DOWNSTREAM_SOURCE: - code = makeNode(type, sizeof(SDownstreamSourceNode), &pNode); break; + code = makeNode(type, sizeof(SDownstreamSourceNode), &pNode); + break; case QUERY_NODE_DATABASE_OPTIONS: - code = makeNode(type, sizeof(SDatabaseOptions), &pNode); break; + code = makeNode(type, sizeof(SDatabaseOptions), &pNode); + break; case QUERY_NODE_TABLE_OPTIONS: - code = makeNode(type, sizeof(STableOptions), &pNode); break; + code = makeNode(type, sizeof(STableOptions), &pNode); + break; case QUERY_NODE_COLUMN_OPTIONS: - code = makeNode(type, sizeof(SColumnOptions), &pNode); break; + code = makeNode(type, sizeof(SColumnOptions), &pNode); + break; case QUERY_NODE_INDEX_OPTIONS: - code = makeNode(type, sizeof(SIndexOptions), &pNode); break; + code = makeNode(type, sizeof(SIndexOptions), &pNode); + break; case QUERY_NODE_EXPLAIN_OPTIONS: - code = makeNode(type, sizeof(SExplainOptions), &pNode); break; + code = makeNode(type, sizeof(SExplainOptions), &pNode); + break; case QUERY_NODE_STREAM_OPTIONS: - code = makeNode(type, sizeof(SStreamOptions), &pNode); break; + code = makeNode(type, sizeof(SStreamOptions), &pNode); + break; case QUERY_NODE_LEFT_VALUE: - code = makeNode(type, sizeof(SLeftValueNode), &pNode); break; + code = makeNode(type, sizeof(SLeftValueNode), &pNode); + break; case QUERY_NODE_COLUMN_REF: - code = makeNode(type, sizeof(SColumnRefNode), &pNode); break; + code = makeNode(type, sizeof(SColumnRefNode), &pNode); + break; case QUERY_NODE_WHEN_THEN: - code = makeNode(type, sizeof(SWhenThenNode), &pNode); break; + code = makeNode(type, sizeof(SWhenThenNode), &pNode); + break; case QUERY_NODE_CASE_WHEN: - code = makeNode(type, sizeof(SCaseWhenNode), &pNode); break; + code = makeNode(type, sizeof(SCaseWhenNode), &pNode); + break; case QUERY_NODE_EVENT_WINDOW: - code = makeNode(type, sizeof(SEventWindowNode), &pNode); break; + code = makeNode(type, sizeof(SEventWindowNode), &pNode); + break; case QUERY_NODE_COUNT_WINDOW: - code = makeNode(type, sizeof(SCountWindowNode), &pNode); break; + code = makeNode(type, sizeof(SCountWindowNode), &pNode); + break; case QUERY_NODE_ANOMALY_WINDOW: - code = makeNode(type, sizeof(SAnomalyWindowNode), &pNode); break; + code = makeNode(type, sizeof(SAnomalyWindowNode), &pNode); + break; case QUERY_NODE_HINT: - code = makeNode(type, sizeof(SHintNode), &pNode); break; + code = makeNode(type, sizeof(SHintNode), &pNode); + break; case QUERY_NODE_VIEW: - code = makeNode(type, sizeof(SViewNode), &pNode); break; + code = makeNode(type, sizeof(SViewNode), &pNode); + break; case QUERY_NODE_WINDOW_OFFSET: - code = makeNode(type, sizeof(SWindowOffsetNode), &pNode); break; + code = makeNode(type, sizeof(SWindowOffsetNode), &pNode); + break; case QUERY_NODE_SET_OPERATOR: - code = makeNode(type, sizeof(SSetOperator), &pNode); break; + code = makeNode(type, sizeof(SSetOperator), &pNode); + break; case QUERY_NODE_SELECT_STMT: - code = makeNode(type, sizeof(SSelectStmt), &pNode); break; + code = makeNode(type, sizeof(SSelectStmt), &pNode); + break; case QUERY_NODE_VNODE_MODIFY_STMT: - code = makeNode(type, sizeof(SVnodeModifyOpStmt), &pNode); break; + code = makeNode(type, sizeof(SVnodeModifyOpStmt), &pNode); + break; case QUERY_NODE_CREATE_DATABASE_STMT: - code = makeNode(type, sizeof(SCreateDatabaseStmt), &pNode); break; + code = makeNode(type, sizeof(SCreateDatabaseStmt), &pNode); + break; case QUERY_NODE_DROP_DATABASE_STMT: - code = makeNode(type, sizeof(SDropDatabaseStmt), &pNode); break; + code = makeNode(type, sizeof(SDropDatabaseStmt), &pNode); + break; case QUERY_NODE_ALTER_DATABASE_STMT: - code = makeNode(type, sizeof(SAlterDatabaseStmt), &pNode); break; + code = makeNode(type, sizeof(SAlterDatabaseStmt), &pNode); + break; case QUERY_NODE_FLUSH_DATABASE_STMT: - code = makeNode(type, sizeof(SFlushDatabaseStmt), &pNode); break; + code = makeNode(type, sizeof(SFlushDatabaseStmt), &pNode); + break; case QUERY_NODE_TRIM_DATABASE_STMT: - code = makeNode(type, sizeof(STrimDatabaseStmt), &pNode); break; + code = makeNode(type, sizeof(STrimDatabaseStmt), &pNode); + break; case QUERY_NODE_S3MIGRATE_DATABASE_STMT: - code = makeNode(type, sizeof(SS3MigrateDatabaseStmt), &pNode); break; + code = makeNode(type, sizeof(SS3MigrateDatabaseStmt), &pNode); + break; case QUERY_NODE_CREATE_TABLE_STMT: - code = makeNode(type, sizeof(SCreateTableStmt), &pNode); break; + code = makeNode(type, sizeof(SCreateTableStmt), &pNode); + break; case QUERY_NODE_CREATE_SUBTABLE_CLAUSE: - code = makeNode(type, sizeof(SCreateSubTableClause), &pNode); break; + code = makeNode(type, sizeof(SCreateSubTableClause), &pNode); + break; case QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE: - code = makeNode(type, sizeof(SCreateSubTableFromFileClause), &pNode); break; + code = makeNode(type, sizeof(SCreateSubTableFromFileClause), &pNode); + break; case QUERY_NODE_CREATE_MULTI_TABLES_STMT: - code = makeNode(type, sizeof(SCreateMultiTablesStmt), &pNode); break; + code = makeNode(type, sizeof(SCreateMultiTablesStmt), &pNode); + break; case QUERY_NODE_DROP_TABLE_CLAUSE: - code = makeNode(type, sizeof(SDropTableClause), &pNode); break; + code = makeNode(type, sizeof(SDropTableClause), &pNode); + break; case QUERY_NODE_DROP_TABLE_STMT: - code = makeNode(type, sizeof(SDropTableStmt), &pNode); break; + code = makeNode(type, sizeof(SDropTableStmt), &pNode); + break; case QUERY_NODE_DROP_SUPER_TABLE_STMT: - code = makeNode(type, sizeof(SDropSuperTableStmt), &pNode); break; + code = makeNode(type, sizeof(SDropSuperTableStmt), &pNode); + break; case QUERY_NODE_ALTER_TABLE_STMT: case QUERY_NODE_ALTER_SUPER_TABLE_STMT: - code = makeNode(type, sizeof(SAlterTableStmt), &pNode); break; + code = makeNode(type, sizeof(SAlterTableStmt), &pNode); + break; + case QUERY_NODE_ALTER_TABLE_MULTI_STMT: + code = makeNode(type, sizeof(SAlterTableMultiStmt), &pNode); + break; case QUERY_NODE_CREATE_USER_STMT: - code = makeNode(type, sizeof(SCreateUserStmt), &pNode); break; + code = makeNode(type, sizeof(SCreateUserStmt), &pNode); + break; case QUERY_NODE_ALTER_USER_STMT: - code = makeNode(type, sizeof(SAlterUserStmt), &pNode); break; + code = makeNode(type, sizeof(SAlterUserStmt), &pNode); + break; case QUERY_NODE_DROP_USER_STMT: - code = makeNode(type, sizeof(SDropUserStmt), &pNode); break; + code = makeNode(type, sizeof(SDropUserStmt), &pNode); + break; case QUERY_NODE_USE_DATABASE_STMT: - code = makeNode(type, sizeof(SUseDatabaseStmt), &pNode); break; + code = makeNode(type, sizeof(SUseDatabaseStmt), &pNode); + break; case QUERY_NODE_CREATE_DNODE_STMT: - code = makeNode(type, sizeof(SCreateDnodeStmt), &pNode); break; + code = makeNode(type, sizeof(SCreateDnodeStmt), &pNode); + break; case QUERY_NODE_DROP_DNODE_STMT: - code = makeNode(type, sizeof(SDropDnodeStmt), &pNode); break; + code = makeNode(type, sizeof(SDropDnodeStmt), &pNode); + break; case QUERY_NODE_ALTER_DNODE_STMT: - code = makeNode(type, sizeof(SAlterDnodeStmt), &pNode); break; + code = makeNode(type, sizeof(SAlterDnodeStmt), &pNode); + break; case QUERY_NODE_CREATE_ANODE_STMT: - code = makeNode(type, sizeof(SCreateAnodeStmt), &pNode); break; + code = makeNode(type, sizeof(SCreateAnodeStmt), &pNode); + break; case QUERY_NODE_DROP_ANODE_STMT: - code = makeNode(type, sizeof(SDropAnodeStmt), &pNode); break; + code = makeNode(type, sizeof(SDropAnodeStmt), &pNode); + break; case QUERY_NODE_UPDATE_ANODE_STMT: - code = makeNode(type, sizeof(SUpdateAnodeStmt), &pNode); break; + code = makeNode(type, sizeof(SUpdateAnodeStmt), &pNode); + break; case QUERY_NODE_CREATE_INDEX_STMT: - code = makeNode(type, sizeof(SCreateIndexStmt), &pNode); break; + code = makeNode(type, sizeof(SCreateIndexStmt), &pNode); + break; case QUERY_NODE_DROP_INDEX_STMT: - code = makeNode(type, sizeof(SDropIndexStmt), &pNode); break; + code = makeNode(type, sizeof(SDropIndexStmt), &pNode); + break; case QUERY_NODE_CREATE_QNODE_STMT: case QUERY_NODE_CREATE_BNODE_STMT: case QUERY_NODE_CREATE_SNODE_STMT: case QUERY_NODE_CREATE_MNODE_STMT: - code = makeNode(type, sizeof(SCreateComponentNodeStmt), &pNode); break; + code = makeNode(type, sizeof(SCreateComponentNodeStmt), &pNode); + break; case QUERY_NODE_DROP_QNODE_STMT: case QUERY_NODE_DROP_BNODE_STMT: case QUERY_NODE_DROP_SNODE_STMT: case QUERY_NODE_DROP_MNODE_STMT: - code = makeNode(type, sizeof(SDropComponentNodeStmt), &pNode); break; + code = makeNode(type, sizeof(SDropComponentNodeStmt), &pNode); + break; case QUERY_NODE_CREATE_TOPIC_STMT: - code = makeNode(type, sizeof(SCreateTopicStmt), &pNode); break; + code = makeNode(type, sizeof(SCreateTopicStmt), &pNode); + break; case QUERY_NODE_DROP_TOPIC_STMT: - code = makeNode(type, sizeof(SDropTopicStmt), &pNode); break; + code = makeNode(type, sizeof(SDropTopicStmt), &pNode); + break; case QUERY_NODE_DROP_CGROUP_STMT: - code = makeNode(type, sizeof(SDropCGroupStmt), &pNode); break; + code = makeNode(type, sizeof(SDropCGroupStmt), &pNode); + break; case QUERY_NODE_ALTER_LOCAL_STMT: - code = makeNode(type, sizeof(SAlterLocalStmt), &pNode); break; + code = makeNode(type, sizeof(SAlterLocalStmt), &pNode); + break; case QUERY_NODE_EXPLAIN_STMT: - code = makeNode(type, sizeof(SExplainStmt), &pNode); break; + code = makeNode(type, sizeof(SExplainStmt), &pNode); + break; case QUERY_NODE_DESCRIBE_STMT: - code = makeNode(type, sizeof(SDescribeStmt), &pNode); break; + code = makeNode(type, sizeof(SDescribeStmt), &pNode); + break; case QUERY_NODE_RESET_QUERY_CACHE_STMT: - code = makeNode(type, sizeof(SNode), &pNode); break; + code = makeNode(type, sizeof(SNode), &pNode); + break; case QUERY_NODE_COMPACT_DATABASE_STMT: - code = makeNode(type, sizeof(SCompactDatabaseStmt), &pNode); break; + code = makeNode(type, sizeof(SCompactDatabaseStmt), &pNode); + break; case QUERY_NODE_CREATE_FUNCTION_STMT: - code = makeNode(type, sizeof(SCreateFunctionStmt), &pNode); break; + code = makeNode(type, sizeof(SCreateFunctionStmt), &pNode); + break; case QUERY_NODE_DROP_FUNCTION_STMT: - code = makeNode(type, sizeof(SDropFunctionStmt), &pNode); break; + code = makeNode(type, sizeof(SDropFunctionStmt), &pNode); + break; case QUERY_NODE_CREATE_STREAM_STMT: - code = makeNode(type, sizeof(SCreateStreamStmt), &pNode); break; + code = makeNode(type, sizeof(SCreateStreamStmt), &pNode); + break; case QUERY_NODE_DROP_STREAM_STMT: - code = makeNode(type, sizeof(SDropStreamStmt), &pNode); break; + code = makeNode(type, sizeof(SDropStreamStmt), &pNode); + break; case QUERY_NODE_PAUSE_STREAM_STMT: - code = makeNode(type, sizeof(SPauseStreamStmt), &pNode); break; + code = makeNode(type, sizeof(SPauseStreamStmt), &pNode); + break; case QUERY_NODE_RESUME_STREAM_STMT: - code = makeNode(type, sizeof(SResumeStreamStmt), &pNode); break; + code = makeNode(type, sizeof(SResumeStreamStmt), &pNode); + break; case QUERY_NODE_BALANCE_VGROUP_STMT: - code = makeNode(type, sizeof(SBalanceVgroupStmt), &pNode); break; + code = makeNode(type, sizeof(SBalanceVgroupStmt), &pNode); + break; case QUERY_NODE_BALANCE_VGROUP_LEADER_STMT: - code = makeNode(type, sizeof(SBalanceVgroupLeaderStmt), &pNode); break; + code = makeNode(type, sizeof(SBalanceVgroupLeaderStmt), &pNode); + break; case QUERY_NODE_BALANCE_VGROUP_LEADER_DATABASE_STMT: - code = makeNode(type, sizeof(SBalanceVgroupLeaderStmt), &pNode); break; + code = makeNode(type, sizeof(SBalanceVgroupLeaderStmt), &pNode); + break; case QUERY_NODE_MERGE_VGROUP_STMT: - code = makeNode(type, sizeof(SMergeVgroupStmt), &pNode); break; + code = makeNode(type, sizeof(SMergeVgroupStmt), &pNode); + break; case QUERY_NODE_REDISTRIBUTE_VGROUP_STMT: - code = makeNode(type, sizeof(SRedistributeVgroupStmt), &pNode); break; + code = makeNode(type, sizeof(SRedistributeVgroupStmt), &pNode); + break; case QUERY_NODE_SPLIT_VGROUP_STMT: - code = makeNode(type, sizeof(SSplitVgroupStmt), &pNode); break; + code = makeNode(type, sizeof(SSplitVgroupStmt), &pNode); + break; case QUERY_NODE_SYNCDB_STMT: break; case QUERY_NODE_GRANT_STMT: - code = makeNode(type, sizeof(SGrantStmt), &pNode); break; + code = makeNode(type, sizeof(SGrantStmt), &pNode); + break; case QUERY_NODE_REVOKE_STMT: - code = makeNode(type, sizeof(SRevokeStmt), &pNode); break; + code = makeNode(type, sizeof(SRevokeStmt), &pNode); + break; case QUERY_NODE_ALTER_CLUSTER_STMT: - code = makeNode(type, sizeof(SAlterClusterStmt), &pNode); break; + code = makeNode(type, sizeof(SAlterClusterStmt), &pNode); + break; case QUERY_NODE_SHOW_DNODES_STMT: case QUERY_NODE_SHOW_MNODES_STMT: case QUERY_NODE_SHOW_MODULES_STMT: @@ -583,191 +680,280 @@ int32_t nodesMakeNode(ENodeType type, SNode** ppNodeOut) { case QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT: case QUERY_NODE_SHOW_ENCRYPTIONS_STMT: case QUERY_NODE_SHOW_TSMAS_STMT: - code = makeNode(type, sizeof(SShowStmt), &pNode); break; + code = makeNode(type, sizeof(SShowStmt), &pNode); + break; case QUERY_NODE_SHOW_TABLE_TAGS_STMT: - code = makeNode(type, sizeof(SShowTableTagsStmt), &pNode); break; + code = makeNode(type, sizeof(SShowTableTagsStmt), &pNode); + break; case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT: - code = makeNode(type, sizeof(SShowDnodeVariablesStmt), &pNode); break; + code = makeNode(type, sizeof(SShowDnodeVariablesStmt), &pNode); + break; case QUERY_NODE_SHOW_CREATE_DATABASE_STMT: - code = makeNode(type, sizeof(SShowCreateDatabaseStmt), &pNode); break; + code = makeNode(type, sizeof(SShowCreateDatabaseStmt), &pNode); + break; case QUERY_NODE_SHOW_DB_ALIVE_STMT: case QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT: - code = makeNode(type, sizeof(SShowAliveStmt), &pNode); break; + code = makeNode(type, sizeof(SShowAliveStmt), &pNode); + break; case QUERY_NODE_SHOW_CREATE_TABLE_STMT: case QUERY_NODE_SHOW_CREATE_STABLE_STMT: - code = makeNode(type, sizeof(SShowCreateTableStmt), &pNode); break; + code = makeNode(type, sizeof(SShowCreateTableStmt), &pNode); + break; case QUERY_NODE_SHOW_CREATE_VIEW_STMT: - code = makeNode(type, sizeof(SShowCreateViewStmt), &pNode); break; + code = makeNode(type, sizeof(SShowCreateViewStmt), &pNode); + break; case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT: - code = makeNode(type, sizeof(SShowTableDistributedStmt), &pNode); break; + code = makeNode(type, sizeof(SShowTableDistributedStmt), &pNode); + break; case QUERY_NODE_SHOW_COMPACTS_STMT: - code = makeNode(type, sizeof(SShowCompactsStmt), &pNode); break; + code = makeNode(type, sizeof(SShowCompactsStmt), &pNode); + break; case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT: - code = makeNode(type, sizeof(SShowCompactDetailsStmt), &pNode); break; + code = makeNode(type, sizeof(SShowCompactDetailsStmt), &pNode); + break; case QUERY_NODE_KILL_QUERY_STMT: - code = makeNode(type, sizeof(SKillQueryStmt), &pNode); break; + code = makeNode(type, sizeof(SKillQueryStmt), &pNode); + break; case QUERY_NODE_KILL_TRANSACTION_STMT: case QUERY_NODE_KILL_CONNECTION_STMT: case QUERY_NODE_KILL_COMPACT_STMT: - code = makeNode(type, sizeof(SKillStmt), &pNode); break; + code = makeNode(type, sizeof(SKillStmt), &pNode); + break; case QUERY_NODE_DELETE_STMT: - code = makeNode(type, sizeof(SDeleteStmt), &pNode); break; + code = makeNode(type, sizeof(SDeleteStmt), &pNode); + break; case QUERY_NODE_INSERT_STMT: - code = makeNode(type, sizeof(SInsertStmt), &pNode); break; + code = makeNode(type, sizeof(SInsertStmt), &pNode); + break; case QUERY_NODE_QUERY: - code = makeNode(type, sizeof(SQuery), &pNode); break; + code = makeNode(type, sizeof(SQuery), &pNode); + break; case QUERY_NODE_RESTORE_DNODE_STMT: case QUERY_NODE_RESTORE_QNODE_STMT: case QUERY_NODE_RESTORE_MNODE_STMT: case QUERY_NODE_RESTORE_VNODE_STMT: - code = makeNode(type, sizeof(SRestoreComponentNodeStmt), &pNode); break; + code = makeNode(type, sizeof(SRestoreComponentNodeStmt), &pNode); + break; case QUERY_NODE_CREATE_VIEW_STMT: - code = makeNode(type, sizeof(SCreateViewStmt), &pNode); break; + code = makeNode(type, sizeof(SCreateViewStmt), &pNode); + break; case QUERY_NODE_DROP_VIEW_STMT: - code = makeNode(type, sizeof(SDropViewStmt), &pNode); break; + code = makeNode(type, sizeof(SDropViewStmt), &pNode); + break; case QUERY_NODE_CREATE_TSMA_STMT: - code = makeNode(type, sizeof(SCreateTSMAStmt), &pNode); break; + code = makeNode(type, sizeof(SCreateTSMAStmt), &pNode); + break; case QUERY_NODE_DROP_TSMA_STMT: - code = makeNode(type, sizeof(SDropTSMAStmt), &pNode); break; + code = makeNode(type, sizeof(SDropTSMAStmt), &pNode); + break; case QUERY_NODE_TSMA_OPTIONS: - code = makeNode(type, sizeof(STSMAOptions), &pNode); break; + code = makeNode(type, sizeof(STSMAOptions), &pNode); + break; case QUERY_NODE_LOGIC_PLAN_SCAN: - code = makeNode(type, sizeof(SScanLogicNode), &pNode); break; + code = makeNode(type, sizeof(SScanLogicNode), &pNode); + break; case QUERY_NODE_LOGIC_PLAN_JOIN: - code = makeNode(type, sizeof(SJoinLogicNode), &pNode); break; + code = makeNode(type, sizeof(SJoinLogicNode), &pNode); + break; case QUERY_NODE_LOGIC_PLAN_AGG: - code = makeNode(type, sizeof(SAggLogicNode), &pNode); break; + code = makeNode(type, sizeof(SAggLogicNode), &pNode); + break; case QUERY_NODE_LOGIC_PLAN_PROJECT: - code = makeNode(type, sizeof(SProjectLogicNode), &pNode); break; + code = makeNode(type, sizeof(SProjectLogicNode), &pNode); + break; case QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY: - code = makeNode(type, sizeof(SVnodeModifyLogicNode), &pNode); break; + code = makeNode(type, sizeof(SVnodeModifyLogicNode), &pNode); + break; case QUERY_NODE_LOGIC_PLAN_EXCHANGE: - code = makeNode(type, sizeof(SExchangeLogicNode), &pNode); break; + code = makeNode(type, sizeof(SExchangeLogicNode), &pNode); + break; case QUERY_NODE_LOGIC_PLAN_MERGE: - code = makeNode(type, sizeof(SMergeLogicNode), &pNode); break; + code = makeNode(type, sizeof(SMergeLogicNode), &pNode); + break; case QUERY_NODE_LOGIC_PLAN_WINDOW: - code = makeNode(type, sizeof(SWindowLogicNode), &pNode); break; + code = makeNode(type, sizeof(SWindowLogicNode), &pNode); + break; case QUERY_NODE_LOGIC_PLAN_FILL: - code = makeNode(type, sizeof(SFillLogicNode), &pNode); break; + code = makeNode(type, sizeof(SFillLogicNode), &pNode); + break; case QUERY_NODE_LOGIC_PLAN_SORT: - code = makeNode(type, sizeof(SSortLogicNode), &pNode); break; + code = makeNode(type, sizeof(SSortLogicNode), &pNode); + break; case QUERY_NODE_LOGIC_PLAN_PARTITION: - code = makeNode(type, sizeof(SPartitionLogicNode), &pNode); break; + code = makeNode(type, sizeof(SPartitionLogicNode), &pNode); + break; case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC: - code = makeNode(type, sizeof(SIndefRowsFuncLogicNode), &pNode); break; + code = makeNode(type, sizeof(SIndefRowsFuncLogicNode), &pNode); + break; case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC: - code = makeNode(type, sizeof(SInterpFuncLogicNode), &pNode); break; + code = makeNode(type, sizeof(SInterpFuncLogicNode), &pNode); + break; case QUERY_NODE_LOGIC_PLAN_FORECAST_FUNC: - code = makeNode(type, sizeof(SForecastFuncLogicNode), &pNode); break; + code = makeNode(type, sizeof(SForecastFuncLogicNode), &pNode); + break; case QUERY_NODE_LOGIC_PLAN_GROUP_CACHE: - code = makeNode(type, sizeof(SGroupCacheLogicNode), &pNode); break; + code = makeNode(type, sizeof(SGroupCacheLogicNode), &pNode); + break; case QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL: - code = makeNode(type, sizeof(SDynQueryCtrlLogicNode), &pNode); break; + code = makeNode(type, sizeof(SDynQueryCtrlLogicNode), &pNode); + break; case QUERY_NODE_LOGIC_SUBPLAN: - code = makeNode(type, sizeof(SLogicSubplan), &pNode); break; + code = makeNode(type, sizeof(SLogicSubplan), &pNode); + break; case QUERY_NODE_LOGIC_PLAN: - code = makeNode(type, sizeof(SQueryLogicPlan), &pNode); break; + code = makeNode(type, sizeof(SQueryLogicPlan), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN: - code = makeNode(type, sizeof(STagScanPhysiNode), &pNode); break; + code = makeNode(type, sizeof(STagScanPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN: - code = makeNode(type, sizeof(STableScanPhysiNode), &pNode); break; + code = makeNode(type, sizeof(STableScanPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN: - code = makeNode(type, sizeof(STableSeqScanPhysiNode), &pNode); break; + code = makeNode(type, sizeof(STableSeqScanPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN: - code = makeNode(type, sizeof(STableMergeScanPhysiNode), &pNode); break; + code = makeNode(type, sizeof(STableMergeScanPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN: - code = makeNode(type, sizeof(SStreamScanPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SStreamScanPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN: - code = makeNode(type, sizeof(SSystemTableScanPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SSystemTableScanPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN: - code = makeNode(type, sizeof(SBlockDistScanPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SBlockDistScanPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN: - code = makeNode(type, sizeof(SLastRowScanPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SLastRowScanPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN: - code = makeNode(type, sizeof(STableCountScanPhysiNode), &pNode); break; + code = makeNode(type, sizeof(STableCountScanPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_PROJECT: - code = makeNode(type, sizeof(SProjectPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SProjectPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: - code = makeNode(type, sizeof(SSortMergeJoinPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SSortMergeJoinPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_HASH_JOIN: - code = makeNode(type, sizeof(SHashJoinPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SHashJoinPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG: - code = makeNode(type, sizeof(SAggPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SAggPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE: - code = makeNode(type, sizeof(SExchangePhysiNode), &pNode); break; + code = makeNode(type, sizeof(SExchangePhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_MERGE: - code = makeNode(type, sizeof(SMergePhysiNode), &pNode); break; + code = makeNode(type, sizeof(SMergePhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_SORT: - code = makeNode(type, sizeof(SSortPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SSortPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT: - code = makeNode(type, sizeof(SGroupSortPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SGroupSortPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL: - code = makeNode(type, sizeof(SIntervalPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SIntervalPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL: - code = makeNode(type, sizeof(SMergeIntervalPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SMergeIntervalPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL: - code = makeNode(type, sizeof(SMergeAlignedIntervalPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SMergeAlignedIntervalPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL: - code = makeNode(type, sizeof(SStreamIntervalPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SStreamIntervalPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL: - code = makeNode(type, sizeof(SStreamFinalIntervalPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SStreamFinalIntervalPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL: - code = makeNode(type, sizeof(SStreamSemiIntervalPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SStreamSemiIntervalPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_STREAM_MID_INTERVAL: - code = makeNode(type, sizeof(SStreamMidIntervalPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SStreamMidIntervalPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_FILL: case QUERY_NODE_PHYSICAL_PLAN_STREAM_FILL: - code = makeNode(type, sizeof(SFillPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SFillPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION: - code = makeNode(type, sizeof(SSessionWinodwPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SSessionWinodwPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION: - code = makeNode(type, sizeof(SStreamSessionWinodwPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SStreamSessionWinodwPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION: - code = makeNode(type, sizeof(SStreamSemiSessionWinodwPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SStreamSemiSessionWinodwPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION: - code = makeNode(type, sizeof(SStreamFinalSessionWinodwPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SStreamFinalSessionWinodwPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE: - code = makeNode(type, sizeof(SStateWinodwPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SStateWinodwPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE: - code = makeNode(type, sizeof(SStreamStateWinodwPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SStreamStateWinodwPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT: - code = makeNode(type, sizeof(SEventWinodwPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SEventWinodwPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_STREAM_EVENT: - code = makeNode(type, sizeof(SStreamEventWinodwPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SStreamEventWinodwPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_MERGE_COUNT: - code = makeNode(type, sizeof(SCountWinodwPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SCountWinodwPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_MERGE_ANOMALY: - code = makeNode(type, sizeof(SAnomalyWindowPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SAnomalyWindowPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_STREAM_COUNT: - code = makeNode(type, sizeof(SStreamCountWinodwPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SStreamCountWinodwPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_PARTITION: - code = makeNode(type, sizeof(SPartitionPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SPartitionPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION: - code = makeNode(type, sizeof(SStreamPartitionPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SStreamPartitionPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC: - code = makeNode(type, sizeof(SIndefRowsFuncPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SIndefRowsFuncPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC: - code = makeNode(type, sizeof(SInterpFuncLogicNode), &pNode); break; + code = makeNode(type, sizeof(SInterpFuncLogicNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_FORECAST_FUNC: - code = makeNode(type, sizeof(SForecastFuncLogicNode), &pNode); break; + code = makeNode(type, sizeof(SForecastFuncLogicNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: - code = makeNode(type, sizeof(SDataDispatcherNode), &pNode); break; + code = makeNode(type, sizeof(SDataDispatcherNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_INSERT: - code = makeNode(type, sizeof(SDataInserterNode), &pNode); break; + code = makeNode(type, sizeof(SDataInserterNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: - code = makeNode(type, sizeof(SQueryInserterNode), &pNode); break; + code = makeNode(type, sizeof(SQueryInserterNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_DELETE: - code = makeNode(type, sizeof(SDataDeleterNode), &pNode); break; + code = makeNode(type, sizeof(SDataDeleterNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE: - code = makeNode(type, sizeof(SGroupCachePhysiNode), &pNode); break; + code = makeNode(type, sizeof(SGroupCachePhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL: - code = makeNode(type, sizeof(SDynQueryCtrlPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SDynQueryCtrlPhysiNode), &pNode); + break; case QUERY_NODE_PHYSICAL_SUBPLAN: - code = makeNode(type, sizeof(SSubplan), &pNode); break; + code = makeNode(type, sizeof(SSubplan), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN: - code = makeNode(type, sizeof(SQueryPlan), &pNode); break; + code = makeNode(type, sizeof(SQueryPlan), &pNode); + break; case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERP_FUNC: - code = makeNode(type, sizeof(SStreamInterpFuncPhysiNode), &pNode); break; + code = makeNode(type, sizeof(SStreamInterpFuncPhysiNode), &pNode); + break; default: break; } @@ -957,7 +1143,7 @@ void nodesDestroyNode(SNode* pNode) { case QUERY_NODE_DATABLOCK_DESC: nodesDestroyList(((SDataBlockDescNode*)pNode)->pSlots); break; - case QUERY_NODE_SLOT_DESC: // no pointer field + case QUERY_NODE_SLOT_DESC: // no pointer field break; case QUERY_NODE_COLUMN_DEF: nodesDestroyNode(((SColumnDefNode*)pNode)->pOptions); @@ -1138,7 +1324,7 @@ void nodesDestroyNode(SNode* pNode) { case QUERY_NODE_FLUSH_DATABASE_STMT: // no pointer field case QUERY_NODE_TRIM_DATABASE_STMT: // no pointer field break; - case QUERY_NODE_S3MIGRATE_DATABASE_STMT: // no pointer field + case QUERY_NODE_S3MIGRATE_DATABASE_STMT: // no pointer field break; case QUERY_NODE_CREATE_TABLE_STMT: { SCreateTableStmt* pStmt = (SCreateTableStmt*)pNode; @@ -1176,6 +1362,13 @@ void nodesDestroyNode(SNode* pNode) { nodesDestroyNode((SNode*)pStmt->pVal); break; } + case QUERY_NODE_ALTER_TABLE_MULTI_STMT: { + SAlterTableMultiStmt* pStmt = (SAlterTableMultiStmt*)pNode; + // nodesDestroyList(pStmt->pTables); + // nodesDestroyNode((SNode*)pStmt->pOptions); + // nodesDestroyNode((SNode*)pStmt->pVal); + break; + } case QUERY_NODE_CREATE_USER_STMT: { SCreateUserStmt* pStmt = (SCreateUserStmt*)pNode; taosMemoryFree(pStmt->pIpRanges); @@ -1254,13 +1447,13 @@ void nodesDestroyNode(SNode* pNode) { taosMemoryFreeClear(pStmt->pReq); break; } - case QUERY_NODE_DROP_STREAM_STMT: // no pointer field - case QUERY_NODE_PAUSE_STREAM_STMT: // no pointer field - case QUERY_NODE_RESUME_STREAM_STMT: // no pointer field - case QUERY_NODE_BALANCE_VGROUP_STMT: // no pointer field - case QUERY_NODE_BALANCE_VGROUP_LEADER_STMT: // no pointer field + case QUERY_NODE_DROP_STREAM_STMT: // no pointer field + case QUERY_NODE_PAUSE_STREAM_STMT: // no pointer field + case QUERY_NODE_RESUME_STREAM_STMT: // no pointer field + case QUERY_NODE_BALANCE_VGROUP_STMT: // no pointer field + case QUERY_NODE_BALANCE_VGROUP_LEADER_STMT: // no pointer field case QUERY_NODE_BALANCE_VGROUP_LEADER_DATABASE_STMT: // no pointer field - case QUERY_NODE_MERGE_VGROUP_STMT: // no pointer field + case QUERY_NODE_MERGE_VGROUP_STMT: // no pointer field break; case QUERY_NODE_REDISTRIBUTE_VGROUP_STMT: nodesDestroyList(((SRedistributeVgroupStmt*)pNode)->pDnodes); @@ -1274,7 +1467,7 @@ void nodesDestroyNode(SNode* pNode) { case QUERY_NODE_REVOKE_STMT: nodesDestroyNode(((SRevokeStmt*)pNode)->pTagCond); break; - case QUERY_NODE_ALTER_CLUSTER_STMT: // no pointer field + case QUERY_NODE_ALTER_CLUSTER_STMT: // no pointer field break; case QUERY_NODE_SHOW_DNODES_STMT: case QUERY_NODE_SHOW_MNODES_STMT: @@ -1387,12 +1580,12 @@ void nodesDestroyNode(SNode* pNode) { nodesDestroyNode(pQuery->pPrepareRoot); break; } - case QUERY_NODE_RESTORE_DNODE_STMT: // no pointer field - case QUERY_NODE_RESTORE_QNODE_STMT: // no pointer field - case QUERY_NODE_RESTORE_MNODE_STMT: // no pointer field - case QUERY_NODE_RESTORE_VNODE_STMT: // no pointer field + case QUERY_NODE_RESTORE_DNODE_STMT: // no pointer field + case QUERY_NODE_RESTORE_QNODE_STMT: // no pointer field + case QUERY_NODE_RESTORE_MNODE_STMT: // no pointer field + case QUERY_NODE_RESTORE_VNODE_STMT: // no pointer field break; - case QUERY_NODE_CREATE_VIEW_STMT: { + case QUERY_NODE_CREATE_VIEW_STMT: { SCreateViewStmt* pStmt = (SCreateViewStmt*)pNode; taosMemoryFree(pStmt->pQuerySql); tFreeSCMCreateViewReq(&pStmt->createReq); @@ -1409,7 +1602,7 @@ void nodesDestroyNode(SNode* pNode) { taosMemoryFreeClear(pStmt->pReq); } break; - } + } case QUERY_NODE_LOGIC_PLAN_SCAN: { SScanLogicNode* pLogicNode = (SScanLogicNode*)pNode; destroyLogicNode((SLogicNode*)pLogicNode); @@ -1800,7 +1993,7 @@ void nodesDestroyNode(SNode* pNode) { int32_t nodesMakeList(SNodeList** ppListOut) { SNodeList* p = NULL; - int32_t code = nodesCalloc(1, sizeof(SNodeList), (void**)&p); + int32_t code = nodesCalloc(1, sizeof(SNodeList), (void**)&p); if (TSDB_CODE_SUCCESS == code) { *ppListOut = p; } @@ -1812,7 +2005,7 @@ int32_t nodesListAppend(SNodeList* pList, SNode* pNode) { return TSDB_CODE_FAILED; } SListCell* p = NULL; - int32_t code = nodesCalloc(1, sizeof(SListCell), (void**)&p); + int32_t code = nodesCalloc(1, sizeof(SListCell), (void**)&p); if (TSDB_CODE_SUCCESS != code) { return code; } @@ -1891,7 +2084,6 @@ int32_t nodesListStrictAppendList(SNodeList* pTarget, SNodeList* pSrc) { return code; } - int32_t nodesListMakeStrictAppendList(SNodeList** pTarget, SNodeList* pSrc) { if (NULL == *pTarget) { int32_t code = nodesMakeList(pTarget); @@ -1902,7 +2094,7 @@ int32_t nodesListMakeStrictAppendList(SNodeList** pTarget, SNodeList* pSrc) { return nodesListStrictAppendList(*pTarget, pSrc); } -int32_t nodesListMakePushFront(SNodeList** pList, SNode* pNode) { +int32_t nodesListMakePushFront(SNodeList** pList, SNode* pNode) { if (*pList == NULL) { int32_t code = nodesMakeList(pList); if (*pList == NULL) { @@ -1917,7 +2109,7 @@ int32_t nodesListPushFront(SNodeList* pList, SNode* pNode) { return TSDB_CODE_FAILED; } SListCell* p = NULL; - int32_t code = nodesCalloc(1, sizeof(SListCell), (void**)&p); + int32_t code = nodesCalloc(1, sizeof(SListCell), (void**)&p); if (TSDB_CODE_SUCCESS != code) { return code; } @@ -2350,7 +2542,8 @@ static EDealRes doCollect(SCollectColumnsCxt* pCxt, SColumnNode* pCol, SNode* pN static bool isCollectType(ECollectColType collectType, EColumnType colType) { return COLLECT_COL_TYPE_ALL == collectType ? true - : (COLLECT_COL_TYPE_TAG == collectType ? COLUMN_TYPE_TAG == colType : (COLUMN_TYPE_TAG != colType && COLUMN_TYPE_TBNAME != colType)); + : (COLLECT_COL_TYPE_TAG == collectType ? COLUMN_TYPE_TAG == colType + : (COLUMN_TYPE_TAG != colType && COLUMN_TYPE_TBNAME != colType)); } static EDealRes collectColumns(SNode* pNode, void* pContext) { @@ -2370,7 +2563,9 @@ static EDealRes collectColumnsExt(SNode* pNode, void* pContext) { if (QUERY_NODE_COLUMN == nodeType(pNode)) { SColumnNode* pCol = (SColumnNode*)pNode; if (isCollectType(pCxt->collectType, pCol->colType) && 0 != strcmp(pCol->colName, "*") && - (NULL == pCxt->pMultiTableAlias || NULL != (pCxt->pTableAlias = tSimpleHashGet(pCxt->pMultiTableAlias, pCol->tableAlias, strlen(pCol->tableAlias))))) { + (NULL == pCxt->pMultiTableAlias || + NULL != (pCxt->pTableAlias = + tSimpleHashGet(pCxt->pMultiTableAlias, pCol->tableAlias, strlen(pCol->tableAlias))))) { return doCollect(pCxt, pCol, pNode); } } @@ -2382,7 +2577,7 @@ int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char* if (NULL == pSelect || NULL == pCols) { return TSDB_CODE_FAILED; } - SNodeList * pList = NULL; + SNodeList* pList = NULL; if (!*pCols) { int32_t code = nodesMakeList(&pList); if (TSDB_CODE_SUCCESS != code) { @@ -2414,13 +2609,13 @@ int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char* return TSDB_CODE_SUCCESS; } -int32_t nodesCollectColumnsExt(SSelectStmt* pSelect, ESqlClause clause, SSHashObj* pMultiTableAlias, ECollectColType type, - SNodeList** pCols) { +int32_t nodesCollectColumnsExt(SSelectStmt* pSelect, ESqlClause clause, SSHashObj* pMultiTableAlias, + ECollectColType type, SNodeList** pCols) { if (NULL == pSelect || NULL == pCols) { return TSDB_CODE_FAILED; } - SNodeList * pList = NULL; + SNodeList* pList = NULL; if (!*pCols) { int32_t code = nodesMakeList(&pList); if (TSDB_CODE_SUCCESS != code) { @@ -2458,7 +2653,7 @@ int32_t nodesCollectColumnsFromNode(SNode* node, const char* pTableAlias, EColle if (NULL == pCols) { return TSDB_CODE_FAILED; } - SNodeList * pList = NULL; + SNodeList* pList = NULL; if (!*pCols) { int32_t code = nodesMakeList(&pList); if (TSDB_CODE_SUCCESS != code) { @@ -2511,7 +2706,7 @@ static EDealRes collectFuncs(SNode* pNode, void* pContext) { } } - bool bFound = false; + bool bFound = false; SNode* pn = NULL; FOREACH(pn, pCxt->pFuncs) { if (nodesEqualNode(pn, pNode)) { @@ -2543,21 +2738,21 @@ static int32_t funcNodeEqual(const void* pLeft, const void* pRight, size_t len) return nodesEqualNode(*(const SNode**)pLeft, *(const SNode**)pRight) ? 0 : 1; } -int32_t nodesCollectSelectFuncs(SSelectStmt* pSelect, ESqlClause clause, char* tableAlias, FFuncClassifier classifier, SNodeList* pFuncs) { +int32_t nodesCollectSelectFuncs(SSelectStmt* pSelect, ESqlClause clause, char* tableAlias, FFuncClassifier classifier, + SNodeList* pFuncs) { if (NULL == pSelect || NULL == pFuncs) { return TSDB_CODE_FAILED; } - SCollectFuncsCxt cxt = {.errCode = TSDB_CODE_SUCCESS, - .classifier = classifier, - .tableAlias = tableAlias, - .pFuncs = pFuncs}; + SCollectFuncsCxt cxt = { + .errCode = TSDB_CODE_SUCCESS, .classifier = classifier, .tableAlias = tableAlias, .pFuncs = pFuncs}; nodesWalkSelectStmt(pSelect, clause, collectFuncs, &cxt); return cxt.errCode; } -int32_t nodesCollectFuncs(SSelectStmt* pSelect, ESqlClause clause, char* tableAlias, FFuncClassifier classifier, SNodeList** pFuncs) { +int32_t nodesCollectFuncs(SSelectStmt* pSelect, ESqlClause clause, char* tableAlias, FFuncClassifier classifier, + SNodeList** pFuncs) { if (NULL == pSelect || NULL == pFuncs) { return TSDB_CODE_FAILED; } @@ -2783,7 +2978,7 @@ int32_t nodesMergeConds(SNode** pDst, SNodeList** pSrc) { nodesClearList(*pSrc); } else { SLogicConditionNode* pLogicCond = NULL; - int32_t code = nodesMakeNode(QUERY_NODE_LOGIC_CONDITION, (SNode**)&pLogicCond); + int32_t code = nodesMakeNode(QUERY_NODE_LOGIC_CONDITION, (SNode**)&pLogicCond); if (TSDB_CODE_SUCCESS != code) { return code; } @@ -2815,13 +3010,13 @@ const char* dataOrderStr(EDataOrderLevel order) { } int32_t nodesMakeValueNodeFromString(char* literal, SValueNode** ppValNode) { - int32_t lenStr = strlen(literal); + int32_t lenStr = strlen(literal); SValueNode* pValNode = NULL; - int32_t code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pValNode); + int32_t code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pValNode); if (pValNode) { pValNode->node.resType.type = TSDB_DATA_TYPE_VARCHAR; pValNode->node.resType.bytes = lenStr + VARSTR_HEADER_SIZE; - char* p = taosMemoryMalloc(lenStr + 1 + VARSTR_HEADER_SIZE); + char* p = taosMemoryMalloc(lenStr + 1 + VARSTR_HEADER_SIZE); if (p == NULL) { return terrno; } @@ -2838,7 +3033,7 @@ int32_t nodesMakeValueNodeFromString(char* literal, SValueNode** ppValNode) { int32_t nodesMakeValueNodeFromBool(bool b, SValueNode** ppValNode) { SValueNode* pValNode = NULL; - int32_t code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pValNode); + int32_t code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pValNode); if (TSDB_CODE_SUCCESS == code) { pValNode->node.resType.type = TSDB_DATA_TYPE_BOOL; pValNode->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes; @@ -2856,7 +3051,7 @@ int32_t nodesMakeValueNodeFromBool(bool b, SValueNode** ppValNode) { int32_t nodesMakeValueNodeFromInt32(int32_t value, SNode** ppNode) { SValueNode* pValNode = NULL; - int32_t code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pValNode); + int32_t code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pValNode); if (TSDB_CODE_SUCCESS == code) { pValNode->node.resType.type = TSDB_DATA_TYPE_INT; pValNode->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_INT].bytes; @@ -2885,7 +3080,7 @@ bool nodesIsTableStar(SNode* pNode) { void nodesSortList(SNodeList** pList, int32_t (*comp)(SNode* pNode1, SNode* pNode2)) { if ((*pList)->length == 1) return; - uint32_t inSize = 1; + uint32_t inSize = 1; SListCell* pHead = (*pList)->pHead; while (1) { SListCell* p = pHead; @@ -2896,7 +3091,7 @@ void nodesSortList(SNodeList** pList, int32_t (*comp)(SNode* pNode1, SNode* pNod while (p) { ++nMerges; SListCell* q = p; - uint32_t pSize = 0; + uint32_t pSize = 0; for (uint32_t i = 0; i < inSize; ++i) { ++pSize; q = q->pNext; @@ -2971,7 +3166,7 @@ int32_t nodesListDeduplicate(SNodeList** ppList) { return TSDB_CODE_SUCCESS; } SNodeList* pTmp = NULL; - int32_t code = nodesMakeList(&pTmp); + int32_t code = nodesMakeList(&pTmp); if (TSDB_CODE_SUCCESS == code) { SNode* pNode = NULL; FOREACH(pNode, *ppList) { diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index 3caa8da80f..fb0529e6d1 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -165,6 +165,7 @@ SNode* createInterpTimeRange(SAstCreateContext* pCxt, SNode* pStart, SNode* SNode* createInterpTimePoint(SAstCreateContext* pCxt, SNode* pPoint); SNode* createWhenThenNode(SAstCreateContext* pCxt, SNode* pWhen, SNode* pThen); SNode* createCaseWhenNode(SAstCreateContext* pCxt, SNode* pCase, SNodeList* pWhenThenList, SNode* pElse); +SNode* createAlterSingleTagColumnNode(SAstCreateContext* pCtx, SToken* token, SNode* pVal); SNode* addWhereClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pWhere); SNode* addPartitionByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pPartitionByList); @@ -228,6 +229,7 @@ SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_ SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pOldColName, SToken* pNewColName); SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, SToken* pTagName, SNode* pVal); +SNode* createAlterTableSetMultiTagValue(SAstCreateContext* pCxt, SNode* pRealTable, SNodeList* singleNode); SNode* setAlterSuperTableType(SNode* pStmt); SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName); SNode* setShowKind(SAstCreateContext* pCxt, SNode* pStmt, EShowKind showKind); diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index e1c3456e3f..9c76aa7f7a 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -370,6 +370,7 @@ cmd ::= DROP STABLE with_opt(A) exists_opt(B) full_table_name(C). cmd ::= ALTER TABLE alter_table_clause(A). { pCxt->pRootNode = A; } cmd ::= ALTER STABLE alter_table_clause(A). { pCxt->pRootNode = setAlterSuperTableType(A); } + alter_table_clause(A) ::= full_table_name(B) alter_table_options(C). { A = createAlterTableModifyOptions(pCxt, B, C); } alter_table_clause(A) ::= full_table_name(B) ADD COLUMN column_name(C) type_name(D) column_options(E). { A = createAlterTableAddModifyColOptions2(pCxt, B, TSDB_ALTER_TABLE_ADD_COLUMN, &C, D, E); } @@ -387,8 +388,16 @@ alter_table_clause(A) ::= full_table_name(B) MODIFY TAG column_name(C) type_name(D). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &C, D); } alter_table_clause(A) ::= full_table_name(B) RENAME TAG column_name(C) column_name(D). { A = createAlterTableRenameCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &C, &D); } + + +%type column_eq_value_list { SNodeList* } +%destructor column_eq_value_list { nodesDestroyList($$); } +column_eq_value(A) ::= column_name(C) NK_EQ tags_literal(D). { A = createAlterSingleTagColumnNode(pCxt, &C, D); } +column_eq_value_list(A) ::= column_eq_value(B). { A = createNodeList(pCxt, B); } +column_eq_value_list(A) ::= column_eq_value_list(B) NK_COMMA column_eq_value(C). { A = addNodeToList(pCxt, B, C);} + alter_table_clause(A) ::= - full_table_name(B) SET TAG column_name(C) NK_EQ tags_literal(D). { A = createAlterTableSetTag(pCxt, B, &C, D); } + full_table_name(B) SET TAG column_eq_value_list(C). { A = createAlterTableSetMultiTagValue(pCxt, B, C); } %type multi_create_clause { SNodeList* } %destructor multi_create_clause { nodesDestroyList($$); } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 1a5e3444c0..b41dad0b18 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -1976,7 +1976,7 @@ static SNode* setDatabaseOptionImpl(SAstCreateContext* pCxt, SNode* pOptions, ED case DB_OPTION_S3_COMPACT: pDbOptions->s3Compact = taosStr2Int8(((SToken*)pVal)->z, NULL, 10); break; - case DB_OPTION_KEEP_TIME_OFFSET: + case DB_OPTION_KEEP_TIME_OFFSET: pDbOptions->keepTimeOffset = taosStr2Int32(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_ENCRYPT_ALGORITHM: @@ -2427,6 +2427,12 @@ static SNode* createAlterTableStmtFinalize(SNode* pRealTable, SAlterTableStmt* p nodesDestroyNode(pRealTable); return (SNode*)pStmt; } +static SNode* createAlterTableMultiStmtFinalize(SNode* pRealTable, SAlterTableMultiStmt* pStmt) { + strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); + strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName); + nodesDestroyNode(pRealTable); + return (SNode*)pStmt; +} SNode* createAlterTableModifyOptions(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions) { CHECK_PARSER_STATUS(pCxt); @@ -2541,6 +2547,19 @@ _err: return NULL; } +SNode* createAlterSingleTagColumnNode(SAstCreateContext* pCtx, SToken* pTagName, SNode* pVal) { + CHECK_PARSER_STATUS(pCtx); + SAlterTableStmt* pStmt = NULL; + pCtx->errCode = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT, (SNode**)&pStmt); + CHECK_MAKE_NODE(pStmt); + pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_TAG_VAL; + COPY_STRING_FORM_ID_TOKEN(pStmt->colName, pTagName); + pStmt->pVal = (SValueNode*)pVal; + return (SNode*)pStmt; +_err: + return NULL; +} + SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, SToken* pTagName, SNode* pVal) { CHECK_PARSER_STATUS(pCxt); CHECK_NAME(checkColumnName(pCxt, pTagName)); @@ -2557,6 +2576,19 @@ _err: return NULL; } +SNode* createAlterTableSetMultiTagValue(SAstCreateContext* pCxt, SNode* pRealTable, SNodeList* pList) { + CHECK_PARSER_STATUS(pCxt); + SAlterTableStmt* pStmt = NULL; + pCxt->errCode = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT, (SNode**)&pStmt); + + CHECK_MAKE_NODE(pStmt); + pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL; + pStmt->pNodeListTagValue = pList; + return createAlterTableStmtFinalize(pRealTable, pStmt); +_err: + return NULL; +} + SNode* setAlterSuperTableType(SNode* pStmt) { if (!pStmt) return NULL; setNodeType(pStmt, QUERY_NODE_ALTER_SUPER_TABLE_STMT); diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index b78e10768f..39b142881f 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -46,7 +46,7 @@ int32_t buildQueryAfterParse(SQuery** pQuery, SNode* pRootNode, int16_t placehol int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) { SAstCreateContext cxt; initAstCreateContext(pParseCxt, &cxt); - void* pParser = ParseAlloc((FMalloc)taosMemoryMalloc); + void* pParser = ParseAlloc((FMalloc)taosMemoryMalloc); if (!pParser) return terrno; int32_t i = 0; while (1) { @@ -210,15 +210,15 @@ static int32_t isTbnameEqCondOperator(SOperatorNode* pOperator, char** ppTableNa if (pOperator->opType != OP_TYPE_EQUAL) { return TSDB_CODE_SUCCESS; } - - SValueNode* pValueNode = NULL; + + SValueNode* pValueNode = NULL; if (nodeType(pOperator->pLeft) == QUERY_NODE_FUNCTION && 0 == strcasecmp(((SFunctionNode*)(pOperator->pLeft))->functionName, "tbname") && nodeType(pOperator->pRight) == QUERY_NODE_VALUE) { pValueNode = (SValueNode*)pOperator->pRight; } else if (nodeType(pOperator->pRight) == QUERY_NODE_FUNCTION && - 0 == strcasecmp(((SFunctionNode*)(pOperator->pRight))->functionName, "tbname") && - nodeType(pOperator->pLeft) == QUERY_NODE_VALUE) { + 0 == strcasecmp(((SFunctionNode*)(pOperator->pRight))->functionName, "tbname") && + nodeType(pOperator->pLeft) == QUERY_NODE_VALUE) { pValueNode = (SValueNode*)pOperator->pLeft; } else { return TSDB_CODE_SUCCESS; @@ -233,13 +233,14 @@ static EDealRes collectMetaKeyFromOperator(SCollectMetaKeyFromExprCxt* pCxt, SOp if (!pCxt->tbnameCollect) { return DEAL_RES_CONTINUE; } - + char* pTableName = NULL; int32_t code = isTbnameEqCondOperator((SOperatorNode*)pOpNode, &pTableName); if (TSDB_CODE_SUCCESS != code) return DEAL_RES_CONTINUE; if (pTableName) { SSelectStmt* pSelect = (SSelectStmt*)pCxt->pComCxt->pStmt; - pCxt->errCode = collectMetaKeyFromRealTableImpl(pCxt->pComCxt, ((SRealTableNode*)pSelect->pFromTable)->table.dbName, pTableName, AUTH_TYPE_READ); + pCxt->errCode = collectMetaKeyFromRealTableImpl(pCxt->pComCxt, ((SRealTableNode*)pSelect->pFromTable)->table.dbName, + pTableName, AUTH_TYPE_READ); } return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR; @@ -500,7 +501,7 @@ static int32_t collectMetaKeyFromCreateStream(SCollectMetaKeyCxt* pCxt, SCreateS reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->targetDbName, pStmt->targetTabName, pCxt->pMetaCache); if (TSDB_CODE_SUCCESS == code && NULL != pStmt->pSubtable && NULL != pStmt->pQuery) { SSelectStmt* pSelect = (SSelectStmt*)pStmt->pQuery; - int32_t code = nodesCloneNode(pStmt->pSubtable, &pSelect->pSubtable); + int32_t code = nodesCloneNode(pStmt->pSubtable, &pSelect->pSubtable); if (NULL == pSelect->pSubtable) { return code; } @@ -969,6 +970,7 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) { case QUERY_NODE_DROP_SUPER_TABLE_STMT: return collectMetaKeyFromDropStable(pCxt, (SDropSuperTableStmt*)pStmt); case QUERY_NODE_ALTER_TABLE_STMT: + case QUERY_NODE_ALTER_TABLE_MULTI_STMT: return collectMetaKeyFromAlterTable(pCxt, (SAlterTableStmt*)pStmt); case QUERY_NODE_ALTER_SUPER_TABLE_STMT: return collectMetaKeyFromAlterStable(pCxt, (SAlterTableStmt*)pStmt); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index fcb6361a6b..3d0c3d7c00 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -97,6 +97,7 @@ static const SSysTableShowAdapter sysTableShowAdapter[] = { .showType = QUERY_NODE_SHOW_DNODES_STMT, .pDbName = TSDB_INFORMATION_SCHEMA_DB, .pTableName = TSDB_INS_TABLE_DNODES, + .numOfShowCols = 1, .pShowCols = {"*"} }, @@ -1853,7 +1854,7 @@ static bool clauseSupportAlias(ESqlClause clause) { return SQL_CLAUSE_GROUP_BY == clause || SQL_CLAUSE_PARTITION_BY == clause || SQL_CLAUSE_ORDER_BY == clause; } -static EDealRes translateColumnInGroupByClause(STranslateContext* pCxt, SColumnNode** pCol, bool *translateAsAlias) { +static EDealRes translateColumnInGroupByClause(STranslateContext* pCxt, SColumnNode** pCol, bool* translateAsAlias) { *translateAsAlias = false; // count(*)/first(*)/last(*) and so on if (0 == strcmp((*pCol)->colName, "*")) { @@ -1862,7 +1863,7 @@ static EDealRes translateColumnInGroupByClause(STranslateContext* pCxt, SColumnN if (pCxt->pParseCxt->biMode) { SNode** ppNode = (SNode**)pCol; - bool ret; + bool ret; pCxt->errCode = biRewriteToTbnameFunc(pCxt, ppNode, &ret); if (TSDB_CODE_SUCCESS != pCxt->errCode) return DEAL_RES_ERROR; if (ret) { @@ -1876,9 +1877,8 @@ static EDealRes translateColumnInGroupByClause(STranslateContext* pCxt, SColumnN } else { bool found = false; res = translateColumnWithoutPrefix(pCxt, pCol); - if (!(*pCol)->node.asParam && - res != DEAL_RES_CONTINUE && - res != DEAL_RES_END && pCxt->errCode != TSDB_CODE_PAR_AMBIGUOUS_COLUMN) { + if (!(*pCol)->node.asParam && res != DEAL_RES_CONTINUE && res != DEAL_RES_END && + pCxt->errCode != TSDB_CODE_PAR_AMBIGUOUS_COLUMN) { res = translateColumnUseAlias(pCxt, pCol, &found); *translateAsAlias = true; } @@ -3321,9 +3321,11 @@ static int32_t selectCommonType(SDataType* commonType, const SDataType* newType) return TSDB_CODE_SUCCESS; } - if ((resultType == TSDB_DATA_TYPE_VARCHAR) && (IS_MATHABLE_TYPE(commonType->type) || IS_MATHABLE_TYPE(newType->type))) { + if ((resultType == TSDB_DATA_TYPE_VARCHAR) && + (IS_MATHABLE_TYPE(commonType->type) || IS_MATHABLE_TYPE(newType->type))) { commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), QUERY_NUMBER_MAX_DISPLAY_LEN); - } else if ((resultType == TSDB_DATA_TYPE_NCHAR) && (IS_MATHABLE_TYPE(commonType->type) || IS_MATHABLE_TYPE(newType->type))) { + } else if ((resultType == TSDB_DATA_TYPE_NCHAR) && + (IS_MATHABLE_TYPE(commonType->type) || IS_MATHABLE_TYPE(newType->type))) { commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), QUERY_NUMBER_MAX_DISPLAY_LEN * TSDB_NCHAR_SIZE); } else { commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), TYPE_BYTES[resultType]); @@ -5480,7 +5482,7 @@ static EDealRes translateGroupPartitionByImpl(SNode** pNode, void* pContext) { int32_t code = TSDB_CODE_SUCCESS; STranslateContext* pTransCxt = pCxt->pTranslateCxt; if (QUERY_NODE_VALUE == nodeType(*pNode)) { - SValueNode* pVal = (SValueNode*) *pNode; + SValueNode* pVal = (SValueNode*)*pNode; if (DEAL_RES_ERROR == translateValue(pTransCxt, pVal)) { return DEAL_RES_CONTINUE; } @@ -5528,8 +5530,7 @@ static int32_t translateGroupByList(STranslateContext* pCxt, SSelectStmt* pSelec if (NULL == pSelect->pGroupByList) { return TSDB_CODE_SUCCESS; } - SReplaceGroupByAliasCxt cxt = { - .pTranslateCxt = pCxt, .pProjectionList = pSelect->pProjectionList}; + SReplaceGroupByAliasCxt cxt = {.pTranslateCxt = pCxt, .pProjectionList = pSelect->pProjectionList}; nodesRewriteExprsPostOrder(pSelect->pGroupByList, translateGroupPartitionByImpl, &cxt); return pCxt->errCode; @@ -5540,8 +5541,7 @@ static int32_t translatePartitionByList(STranslateContext* pCxt, SSelectStmt* pS return TSDB_CODE_SUCCESS; } - SReplaceGroupByAliasCxt cxt = { - .pTranslateCxt = pCxt, .pProjectionList = pSelect->pProjectionList}; + SReplaceGroupByAliasCxt cxt = {.pTranslateCxt = pCxt, .pProjectionList = pSelect->pProjectionList}; nodesRewriteExprsPostOrder(pSelect->pPartitionByList, translateGroupPartitionByImpl, &cxt); return pCxt->errCode; @@ -9495,7 +9495,8 @@ static int32_t checkAlterSuperTableBySchema(STranslateContext* pCxt, SAlterTable } static int32_t checkAlterSuperTable(STranslateContext* pCxt, SAlterTableStmt* pStmt) { - if (TSDB_ALTER_TABLE_UPDATE_TAG_VAL == pStmt->alterType) { + if (TSDB_ALTER_TABLE_UPDATE_TAG_VAL == pStmt->alterType || + TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL == pStmt->alterType) { return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE, "Set tag value only available for child table"); } @@ -10521,7 +10522,8 @@ static void getSourceDatabase(SNode* pStmt, int32_t acctId, char* pDbFName) { (void)tNameGetFullDbName(&name, pDbFName); } -static void getStreamQueryFirstProjectAliasName(SHashObj* pUserAliasSet, char* aliasName, int32_t len, char* defaultName[]) { +static void getStreamQueryFirstProjectAliasName(SHashObj* pUserAliasSet, char* aliasName, int32_t len, + char* defaultName[]) { for (int32_t i = 0; defaultName[i] != NULL; i++) { if (NULL == taosHashGet(pUserAliasSet, defaultName[i], strlen(defaultName[i]))) { snprintf(aliasName, len, "%s", defaultName[i]); @@ -10547,8 +10549,8 @@ static int32_t setColumnDefNodePrimaryKey(SColumnDefNode* pNode, bool isPk) { return code; } -static int32_t addIrowTsToCreateStreamQueryImpl(STranslateContext* pCxt, SSelectStmt* pSelect, - SHashObj* pUserAliasSet, SNodeList* pCols, SCMCreateStreamReq* pReq) { +static int32_t addIrowTsToCreateStreamQueryImpl(STranslateContext* pCxt, SSelectStmt* pSelect, SHashObj* pUserAliasSet, + SNodeList* pCols, SCMCreateStreamReq* pReq) { SNode* pProj = nodesListGetNode(pSelect->pProjectionList, 0); if (!pSelect->hasInterpFunc || (QUERY_NODE_FUNCTION == nodeType(pProj) && 0 == strcmp("_irowts", ((SFunctionNode*)pProj)->functionName))) { @@ -10595,7 +10597,7 @@ static int32_t addWstartTsToCreateStreamQueryImpl(STranslateContext* pCxt, SSele return TSDB_CODE_SUCCESS; } SFunctionNode* pFunc = NULL; - int32_t code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&pFunc); + int32_t code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&pFunc); if (NULL == pFunc) { return code; } @@ -10627,7 +10629,7 @@ static int32_t addWstartTsToCreateStreamQueryImpl(STranslateContext* pCxt, SSele } static int32_t addTsKeyToCreateStreamQuery(STranslateContext* pCxt, SNode* pStmt, SNodeList* pCols, - SCMCreateStreamReq* pReq) { + SCMCreateStreamReq* pReq) { SSelectStmt* pSelect = (SSelectStmt*)pStmt; SHashObj* pUserAliasSet = NULL; int32_t code = checkProjectAlias(pCxt, pSelect->pProjectionList, &pUserAliasSet); @@ -10990,21 +10992,18 @@ static int32_t checkStreamQuery(STranslateContext* pCxt, SCreateStreamStmt* pStm if (pStmt->pOptions->triggerType == STREAM_TRIGGER_FORCE_WINDOW_CLOSE) { if (pStmt->pOptions->fillHistory) { - return generateSyntaxErrMsgExt( - &pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY, - "When trigger was force window close, Stream unsupported Fill history"); + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY, + "When trigger was force window close, Stream unsupported Fill history"); } if (pStmt->pOptions->ignoreExpired != 1) { - return generateSyntaxErrMsgExt( - &pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY, - "When trigger was force window close, Stream must not set ignore expired 0"); + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY, + "When trigger was force window close, Stream must not set ignore expired 0"); } if (pStmt->pOptions->ignoreUpdate != 1) { - return generateSyntaxErrMsgExt( - &pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY, - "When trigger was force window close, Stream must not set ignore update 0"); + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY, + "When trigger was force window close, Stream must not set ignore update 0"); } if (pSelect->pWindow != NULL && QUERY_NODE_INTERVAL_WINDOW == nodeType(pSelect->pWindow)) { @@ -13127,7 +13126,7 @@ static int32_t extractShowCreateViewResultSchema(int32_t* numOfCols, SSchema** p } static int32_t extractShowVariablesResultSchema(int32_t* numOfCols, SSchema** pSchema) { - *numOfCols = SHOW_LOCAL_VARIABLES_RESULT_COLS; // SHOW_VARIABLES_RESULT_COLS + *numOfCols = SHOW_LOCAL_VARIABLES_RESULT_COLS; // SHOW_VARIABLES_RESULT_COLS *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { return terrno; @@ -15183,24 +15182,90 @@ static int32_t rewriteDropSuperTable(STranslateContext* pCxt, SQuery* pQuery) { TAOS_RETURN(0); } -static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta, - SVAlterTbReq* pReq) { - SName tbName = {0}; - SArray* pTsmas = NULL; +static int32_t buildUpdateTagValReqImpl2(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta, + char* colName, SMultiTagUpateVal* pReq) { int32_t code = TSDB_CODE_SUCCESS; - if (pCxt->pMetaCache) { - 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; + if (NULL == pReq->tagName) { + return terrno; } - SSchema* pSchema = getTagSchema(pTableMeta, pStmt->colName); + SSchema* pSchema = getTagSchema(pTableMeta, colName); if (NULL == pSchema) { - return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE, "Invalid tag name: %s", - pStmt->colName); + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE, "Invalid tag name: %s", colName); } - pReq->tagName = taosStrdup(pStmt->colName); + + pReq->tagName = taosStrdup(colName); + if (NULL == pReq->tagName) { + return terrno; + } + pReq->pTagArray = taosArrayInit(1, sizeof(STagVal)); + if (NULL == pReq->pTagArray) { + return terrno; + } + pReq->colId = pSchema->colId; + pReq->tagType = pSchema->type; + + STag* pTag = NULL; + SToken token; + char tokenBuf[TSDB_MAX_TAGS_LEN]; + const char* tagStr = pStmt->pVal->literal; + NEXT_TOKEN_WITH_PREV(tagStr, token); + if (TSDB_CODE_SUCCESS == code) { + code = checkAndTrimValue(&token, tokenBuf, &pCxt->msgBuf, pSchema->type); + if (TSDB_CODE_SUCCESS == code && TK_NK_VARIABLE == token.type) { + code = buildSyntaxErrMsg(&pCxt->msgBuf, "not expected tags values", token.z); + } + } + + if (TSDB_CODE_SUCCESS == code) { + code = parseTagValue(&pCxt->msgBuf, &tagStr, pTableMeta->tableInfo.precision, pSchema, &token, NULL, + pReq->pTagArray, &pTag); + if (pSchema->type == TSDB_DATA_TYPE_JSON && token.type == TK_NULL && code == TSDB_CODE_SUCCESS) { + pReq->tagFree = true; + } + } + if (TSDB_CODE_SUCCESS == code && tagStr) { + NEXT_VALID_TOKEN(tagStr, token); + if (token.n != 0) { + code = buildSyntaxErrMsg(&pCxt->msgBuf, "not expected tags values", token.z); + } + } + + if (TSDB_CODE_SUCCESS == code) { + if (pSchema->type == TSDB_DATA_TYPE_JSON) { + code = buildSyntaxErrMsg(&pCxt->msgBuf, "not expected tags values ", token.z); + } else { + STagVal* pTagVal = taosArrayGet(pReq->pTagArray, 0); + if (pTagVal) { + pReq->isNull = false; + if (IS_VAR_DATA_TYPE(pSchema->type)) { + pReq->nTagVal = pTagVal->nData; + pReq->pTagVal = pTagVal->pData; + } else { + pReq->nTagVal = pSchema->bytes; + pReq->pTagVal = (uint8_t*)&pTagVal->i64; + } + } else { + pReq->isNull = true; + } + } + } + + return code; +} +static int32_t buildUpdateTagValReqImpl(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta, + char* colName, SVAlterTbReq* pReq) { + int32_t code = TSDB_CODE_SUCCESS; + // if (NULL == pReq->tagName) { + // return terrno; + // } + + SSchema* pSchema = getTagSchema(pTableMeta, colName); + if (NULL == pSchema) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE, "Invalid tag name: %s", colName); + } + + pReq->tagName = taosStrdup(colName); if (NULL == pReq->tagName) { return terrno; } @@ -15261,6 +15326,62 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS return code; } +static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta, + SVAlterTbReq* pReq) { + SName tbName = {0}; + SArray* pTsmas = NULL; + int32_t code = TSDB_CODE_SUCCESS; + if (pCxt->pMetaCache) { + 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; + } + return buildUpdateTagValReqImpl(pCxt, pStmt, pTableMeta, pStmt->colName, pReq); +} + +static int32_t buildUpdateMultiTagValReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta, + SVAlterTbReq* pReq) { + SName tbName = {0}; + SArray* pTsmas = NULL; + int32_t code = TSDB_CODE_SUCCESS; + if (pCxt->pMetaCache) { + 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; + } + SNodeList* pNodeList = pStmt->pNodeListTagValue; + if (pNodeList == NULL) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE); + } + + int32_t nTagValues = pNodeList->length; + if (nTagValues == 1) { + SAlterTableStmt* head = (SAlterTableStmt*)pNodeList->pHead->pNode; + pReq->action = TSDB_ALTER_TABLE_UPDATE_TAG_VAL; + return buildUpdateTagValReqImpl(pCxt, head, pTableMeta, head->colName, pReq); + } else { + pReq->pMultiTag = taosArrayInit(nTagValues, sizeof(SMultiTagUpateVal)); + if (NULL == pReq->pTagArray) { + return terrno; + } + + SAlterTableStmt* pTagStmt = NULL; + SNode* pNode = NULL; + FOREACH(pNode, pNodeList) { + SMultiTagUpateVal val; + pTagStmt = (SAlterTableStmt*)pNode; + code = buildUpdateTagValReqImpl2(pCxt, pTagStmt, pTableMeta, pTagStmt->colName, &val); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + TAOS_UNUSED(taosArrayPush(pReq->pMultiTag, &val)); + } + } + + return code; +} static int32_t buildAddColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta, SVAlterTbReq* pReq) { @@ -15449,6 +15570,8 @@ static int32_t buildAlterTbReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, case TSDB_ALTER_TABLE_UPDATE_TAG_NAME: case TSDB_ALTER_TABLE_UPDATE_TAG_BYTES: return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE); + case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL: + return buildUpdateMultiTagValReq(pCxt, pStmt, pTableMeta, pReq); case TSDB_ALTER_TABLE_UPDATE_TAG_VAL: return buildUpdateTagValReq(pCxt, pStmt, pTableMeta, pReq); case TSDB_ALTER_TABLE_ADD_COLUMN: @@ -16254,6 +16377,7 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { case QUERY_NODE_DROP_SUPER_TABLE_STMT: code = rewriteDropSuperTable(pCxt, pQuery); break; + case QUERY_NODE_ALTER_TABLE_MULTI_STMT: case QUERY_NODE_ALTER_TABLE_STMT: code = rewriteAlterTable(pCxt, pQuery); break; From 97e08abe8ca6cd09293cdba12a0432da5a23c89d Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 25 Nov 2024 10:55:28 +0800 Subject: [PATCH 02/25] support update multi tag --- source/dnode/vnode/src/meta/metaTable.c | 253 +++++++++++++++++++++++- source/libs/parser/src/parTranslater.c | 3 - 2 files changed, 252 insertions(+), 4 deletions(-) diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 03b8bdd93f..f51b641640 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -2011,7 +2011,257 @@ _err: return terrno != 0 ? terrno : TSDB_CODE_FAILED; } -static int metaUpdateTableMultiTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) { return 0; } +static int metaUpdateTableMultiTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) { + SMetaEntry ctbEntry = {0}; + SMetaEntry stbEntry = {0}; + void *pVal = NULL; + int nVal = 0; + int ret; + int c; + tb_uid_t uid; + int64_t oversion; + const void *pData = NULL; + int nData = 0; + SHashObj *pTagTable = NULL; + SArray *updateTagColumnIds = NULL; + + // search name index + ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal); + if (ret < 0) { + return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST; + } + + uid = *(tb_uid_t *)pVal; + tdbFree(pVal); + pVal = NULL; + + // search uid index + TBC *pUidIdxc = NULL; + + TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL)); + if (tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c) < 0) { + metaTrace("meta/table: failed to move to uid index, uid:%" PRId64, uid); + } + if (c != 0) { + tdbTbcClose(pUidIdxc); + metaError("meta/table: invalide c: %" PRId32 " update tb tag val failed.", c); + return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST; + } + + if (tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData) != 0) { + metaError("meta/table: failed to get uid index, uid:%" PRId64, uid); + } + oversion = ((SUidIdxVal *)pData)[0].version; + + // search table.db + TBC *pTbDbc = NULL; + SDecoder dc1 = {0}; + SDecoder dc2 = {0}; + + /* get ctbEntry */ + TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL)); + if (tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c) != 0) { + metaError("meta/table: failed to move to tb db, uid:%" PRId64, uid); + } + if (c != 0) { + tdbTbcClose(pUidIdxc); + tdbTbcClose(pTbDbc); + metaError("meta/table: invalide c: %" PRId32 " update tb tag val failed.", c); + return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST; + } + + if (tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData) != 0) { + metaError("meta/table: failed to get tb db, uid:%" PRId64, uid); + } + + if ((ctbEntry.pBuf = taosMemoryMalloc(nData)) == NULL) { + tdbTbcClose(pUidIdxc); + tdbTbcClose(pTbDbc); + return terrno; + } + memcpy(ctbEntry.pBuf, pData, nData); + tDecoderInit(&dc1, ctbEntry.pBuf, nData); + ret = metaDecodeEntry(&dc1, &ctbEntry); + if (ret < 0) { + terrno = ret; + goto _err; + } + + /* get stbEntry*/ + if (tdbTbGet(pMeta->pUidIdx, &ctbEntry.ctbEntry.suid, sizeof(tb_uid_t), &pVal, &nVal) != 0) { + metaError("meta/table: failed to get uid index, uid:%" PRId64, ctbEntry.ctbEntry.suid); + } + if (!pVal) { + terrno = TSDB_CODE_INVALID_MSG; + goto _err; + } + + if (tdbTbGet(pMeta->pTbDb, &((STbDbKey){.uid = ctbEntry.ctbEntry.suid, .version = ((SUidIdxVal *)pVal)[0].version}), + sizeof(STbDbKey), (void **)&stbEntry.pBuf, &nVal) != 0) { + metaError("meta/table: failed to get tb db, uid:%" PRId64, ctbEntry.ctbEntry.suid); + } + tdbFree(pVal); + tDecoderInit(&dc2, stbEntry.pBuf, nVal); + ret = metaDecodeEntry(&dc2, &stbEntry); + if (ret < 0) { + terrno = ret; + goto _err; + } + + int32_t nTagVals = taosArrayGetSize(pAlterTbReq->pMultiTag); + pTagTable = taosHashInit(nTagVals, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); + if (pTagTable == NULL) { + ret = terrno; + goto _err; + } + + // remove duplicate tag name + for (int i = 0; i < nTagVals; i++) { + SMultiTagUpateVal *pTagVal = taosArrayGet(pAlterTbReq->pMultiTag, i); + ret = taosHashPut(pTagTable, pTagVal->tagName, strlen(pTagVal->tagName), pTagVal, sizeof(*pTagVal)); + if (ret != 0) { + goto _err; + } + } + int32_t nUpdateTagVal = taosHashGetSize(pTagTable); + updateTagColumnIds = taosArrayInit(nUpdateTagVal, sizeof(int32_t)); + + SSchemaWrapper *pTagSchema = &stbEntry.stbEntry.schemaTag; + SSchema *pColumn = NULL; + int32_t iCol = 0; + + for (;;) { + pColumn = NULL; + + if (iCol >= pTagSchema->nCols) break; + pColumn = &pTagSchema->pSchema[iCol]; + if (taosHashGet(pTagTable, pColumn->name, strlen(pColumn->name)) != NULL) { + if (taosArrayPush(updateTagColumnIds, &iCol) == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + } + iCol++; + } + if (taosArrayGetSize(updateTagColumnIds) == nUpdateTagVal) { + terrno = TSDB_CODE_VND_COL_NOT_EXISTS; + goto _err; + } + + ctbEntry.version = version; + if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) { + terrno = TSDB_CODE_VND_COL_NOT_EXISTS; + goto _err; + } else { + const STag *pOldTag = (const STag *)ctbEntry.ctbEntry.pTags; + STag *pNewTag = NULL; + SArray *pTagArray = taosArrayInit(pTagSchema->nCols, sizeof(STagVal)); + if (!pTagArray) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + for (int32_t i = 0; i < pTagSchema->nCols; i++) { + SSchema *pCol = &pTagSchema->pSchema[i]; + SMultiTagUpateVal *pTagVal = taosHashGet(pTagTable, pCol->name, strlen(pCol->name)); + if (pTagVal == NULL) { + STagVal val = {.cid = pCol->colId}; + if (tTagGet(pOldTag, &val)) { + if (taosArrayPush(pTagArray, &val) == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + taosArrayDestroy(pTagArray); + goto _err; + } + } + } else { + STagVal val = {0}; + val.type = pCol->type; + val.cid = pCol->colId; + if (pTagVal->isNull) continue; + + if (IS_VAR_DATA_TYPE(pCol->type)) { + val.pData = pTagVal->pTagVal; + val.nData = pTagVal->nTagVal; + } else { + memcpy(&val.i64, pTagVal->pTagVal, pTagVal->nTagVal); + } + if (taosArrayPush(pTagArray, &val) == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + taosArrayDestroy(pTagArray); + goto _err; + } + } + } + if ((terrno = tTagNew(pTagArray, pTagSchema->version, false, &pNewTag)) < 0) { + taosArrayDestroy(pTagArray); + goto _err; + } + ctbEntry.ctbEntry.pTags = (uint8_t *)pNewTag; + taosArrayDestroy(pTagArray); + } + + metaWLock(pMeta); + + // save to table.db + if (metaSaveToTbDb(pMeta, &ctbEntry) < 0) { + metaError("meta/table: failed to save to tb db:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid); + } + + // save to uid.idx + if (metaUpdateUidIdx(pMeta, &ctbEntry) < 0) { + metaError("meta/table: failed to update uid idx:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid); + } + + if (metaUpdateTagIdx(pMeta, &ctbEntry) < 0) { + metaError("meta/table: failed to update tag idx:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid); + } + + if (NULL == ctbEntry.ctbEntry.pTags) { + metaError("meta/table: null tags, update tag val failed."); + goto _err; + } + + SCtbIdxKey ctbIdxKey = {.suid = ctbEntry.ctbEntry.suid, .uid = uid}; + if (tdbTbUpsert(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), ctbEntry.ctbEntry.pTags, + ((STag *)(ctbEntry.ctbEntry.pTags))->len, pMeta->txn) < 0) { + metaError("meta/table: failed to upsert ctb idx:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid); + } + + if (metaUidCacheClear(pMeta, ctbEntry.ctbEntry.suid) < 0) { + metaError("meta/table: failed to clear uid cache:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid); + } + + if (metaTbGroupCacheClear(pMeta, ctbEntry.ctbEntry.suid) < 0) { + metaError("meta/table: failed to clear group cache:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid); + } + + if (metaUpdateChangeTime(pMeta, ctbEntry.uid, pAlterTbReq->ctimeMs) < 0) { + metaError("meta/table: failed to update change time:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid); + } + + metaULock(pMeta); + + tDecoderClear(&dc1); + tDecoderClear(&dc2); + taosMemoryFree((void *)ctbEntry.ctbEntry.pTags); + if (ctbEntry.pBuf) taosMemoryFree(ctbEntry.pBuf); + if (stbEntry.pBuf) tdbFree(stbEntry.pBuf); + tdbTbcClose(pTbDbc); + tdbTbcClose(pUidIdxc); + taosHashCleanup(pTagTable); + taosArrayDestroy(updateTagColumnIds); + return 0; + +_err: + tDecoderClear(&dc1); + tDecoderClear(&dc2); + if (ctbEntry.pBuf) taosMemoryFree(ctbEntry.pBuf); + if (stbEntry.pBuf) tdbFree(stbEntry.pBuf); + tdbTbcClose(pTbDbc); + tdbTbcClose(pUidIdxc); + taosHashCleanup(pTagTable); + taosArrayDestroy(updateTagColumnIds); + return -1; +} static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) { SMetaEntry ctbEntry = {0}; SMetaEntry stbEntry = {0}; @@ -2114,6 +2364,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA SSchemaWrapper *pTagSchema = &stbEntry.stbEntry.schemaTag; SSchema *pColumn = NULL; int32_t iCol = 0; + for (;;) { pColumn = NULL; diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 3d0c3d7c00..3543ee1a53 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -15256,9 +15256,6 @@ static int32_t buildUpdateTagValReqImpl2(STranslateContext* pCxt, SAlterTableStm static int32_t buildUpdateTagValReqImpl(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta, char* colName, SVAlterTbReq* pReq) { int32_t code = TSDB_CODE_SUCCESS; - // if (NULL == pReq->tagName) { - // return terrno; - // } SSchema* pSchema = getTagSchema(pTableMeta, colName); if (NULL == pSchema) { From 4d857b01498ca29aefa5c4aeee3c68d32db8069d Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 25 Nov 2024 15:22:53 +0800 Subject: [PATCH 03/25] fix mem leak --- include/common/tmsg.h | 1 - include/libs/nodes/cmdnodes.h | 12 ---------- source/common/src/tmsg.c | 2 +- source/dnode/vnode/src/meta/metaTable.c | 4 ++-- source/dnode/vnode/src/vnd/vnodeSvr.c | 14 +++++++----- source/libs/nodes/src/nodesUtilFuncs.c | 19 ++++++++-------- source/libs/parser/inc/sql.y | 12 +++++----- source/libs/parser/src/parAstCreater.c | 1 + source/libs/parser/src/parAstParser.c | 1 - source/libs/parser/src/parTranslater.c | 29 ++++++++++++++++++------- 10 files changed, 49 insertions(+), 46 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 27169b0a4e..bcbae641f2 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -352,7 +352,6 @@ typedef enum ENodeType { QUERY_NODE_CREATE_ANODE_STMT, QUERY_NODE_DROP_ANODE_STMT, QUERY_NODE_UPDATE_ANODE_STMT, - QUERY_NODE_ALTER_TABLE_MULTI_STMT, // show statement nodes // see 'sysTableShowAdapter', 'SYSTABLE_SHOW_TYPE_OFFSET' diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 6623811712..defacf4cd3 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -267,18 +267,6 @@ typedef struct SAlterTableStmt { SNodeList* pNodeListTagValue; } SAlterTableStmt; - -typedef struct SAlterTableStmt2 { - ENodeType type; - int8_t alterType; - char colName[TSDB_COL_NAME_LEN]; - STableOptions* pOptions; - SDataType dataType; - SValueNode* pVal; - SColumnOptions* pColOptions; - -} SAlterTableStmt2; - typedef struct SAlterTableMultiStmt { ENodeType type; char dbName[TSDB_DB_NAME_LEN]; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 134a5cf8c5..fd3af20ac1 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -10521,7 +10521,7 @@ int32_t tEncodeSVAlterTbReq(SEncoder *pEncoder, const SVAlterTbReq *pReq) { TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTag->isNull)); TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTag->tagType)); if (!pTag->isNull) { - TAOS_CHECK_EXIT(tEncodeBinary(pEncoder, pTag->pTagVal, pReq->nTagVal)); + TAOS_CHECK_EXIT(tEncodeBinary(pEncoder, pTag->pTagVal, pTag->nTagVal)); } } break; diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index f51b641640..54476d339f 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -2109,7 +2109,7 @@ static int metaUpdateTableMultiTagVal(SMeta *pMeta, int64_t version, SVAlterTbRe } int32_t nTagVals = taosArrayGetSize(pAlterTbReq->pMultiTag); - pTagTable = taosHashInit(nTagVals, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); + pTagTable = taosHashInit(nTagVals, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (pTagTable == NULL) { ret = terrno; goto _err; @@ -2143,7 +2143,7 @@ static int metaUpdateTableMultiTagVal(SMeta *pMeta, int64_t version, SVAlterTbRe } iCol++; } - if (taosArrayGetSize(updateTagColumnIds) == nUpdateTagVal) { + if (taosArrayGetSize(updateTagColumnIds) != nUpdateTagVal) { terrno = TSDB_CODE_VND_COL_NOT_EXISTS; goto _err; } diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index dd13c975cf..546cd6c3ae 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -145,8 +145,12 @@ static int32_t vnodePreProcessAlterTableMsg(SVnode *pVnode, SRpcMsg *pMsg) { SVAlterTbReq vAlterTbReq = {0}; int64_t ctimeMs = taosGetTimestampMs(); if (tDecodeSVAlterTbReqSetCtime(&dc, &vAlterTbReq, ctimeMs) < 0) { + taosArrayDestroy(vAlterTbReq.pMultiTag); + vAlterTbReq.pMultiTag = NULL; goto _exit; } + taosArrayDestroy(vAlterTbReq.pMultiTag); + vAlterTbReq.pMultiTag = NULL; code = 0; @@ -666,10 +670,9 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg } } break; case TDMT_VND_STREAM_TASK_RESET: { - if (pVnode->restored && vnodeIsLeader(pVnode) && - (code = tqProcessTaskResetReq(pVnode->pTq, pMsg)) < 0) { - goto _err; - } + if (pVnode->restored && vnodeIsLeader(pVnode) && (code = tqProcessTaskResetReq(pVnode->pTq, pMsg)) < 0) { + goto _err; + } } break; case TDMT_VND_ALTER_CONFIRM: @@ -690,7 +693,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg case TDMT_VND_DROP_INDEX: vnodeProcessDropIndexReq(pVnode, ver, pReq, len, pRsp); break; - case TDMT_VND_STREAM_CHECK_POINT_SOURCE: // always return true + case TDMT_VND_STREAM_CHECK_POINT_SOURCE: // always return true tqProcessTaskCheckPointSourceReq(pVnode->pTq, pMsg, pRsp); break; case TDMT_VND_STREAM_TASK_UPDATE: // always return true @@ -1367,6 +1370,7 @@ static int32_t vnodeProcessAlterTbReq(SVnode *pVnode, int64_t ver, void *pReq, i } _exit: + taosArrayDestroy(vAlterTbReq.pMultiTag); tEncodeSize(tEncodeSVAlterTbRsp, &vAlterTbRsp, pRsp->contLen, ret); pRsp->pCont = rpcMallocCont(pRsp->contLen); tEncoderInit(&ec, pRsp->pCont, pRsp->contLen); diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 25d1ecd6f9..ac29021e83 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -519,9 +519,6 @@ int32_t nodesMakeNode(ENodeType type, SNode** ppNodeOut) { case QUERY_NODE_ALTER_SUPER_TABLE_STMT: code = makeNode(type, sizeof(SAlterTableStmt), &pNode); break; - case QUERY_NODE_ALTER_TABLE_MULTI_STMT: - code = makeNode(type, sizeof(SAlterTableMultiStmt), &pNode); - break; case QUERY_NODE_CREATE_USER_STMT: code = makeNode(type, sizeof(SCreateUserStmt), &pNode); break; @@ -1360,13 +1357,15 @@ void nodesDestroyNode(SNode* pNode) { SAlterTableStmt* pStmt = (SAlterTableStmt*)pNode; nodesDestroyNode((SNode*)pStmt->pOptions); nodesDestroyNode((SNode*)pStmt->pVal); - break; - } - case QUERY_NODE_ALTER_TABLE_MULTI_STMT: { - SAlterTableMultiStmt* pStmt = (SAlterTableMultiStmt*)pNode; - // nodesDestroyList(pStmt->pTables); - // nodesDestroyNode((SNode*)pStmt->pOptions); - // nodesDestroyNode((SNode*)pStmt->pVal); + if (pStmt->pNodeListTagValue != NULL) { + SNodeList* pNodeList = pStmt->pNodeListTagValue; + SNode* pSubNode = NULL; + FOREACH(pSubNode, pNodeList) { + SAlterTableStmt* pSubAlterTable = (SAlterTableStmt*)pSubNode; + nodesDestroyNode((SNode*)pSubAlterTable->pOptions); + nodesDestroyNode((SNode*)pSubAlterTable->pVal); + } + } break; } case QUERY_NODE_CREATE_USER_STMT: { diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 9c76aa7f7a..b8a5e6f98f 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -390,14 +390,14 @@ alter_table_clause(A) ::= full_table_name(B) RENAME TAG column_name(C) column_name(D). { A = createAlterTableRenameCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &C, &D); } -%type column_eq_value_list { SNodeList* } -%destructor column_eq_value_list { nodesDestroyList($$); } -column_eq_value(A) ::= column_name(C) NK_EQ tags_literal(D). { A = createAlterSingleTagColumnNode(pCxt, &C, D); } -column_eq_value_list(A) ::= column_eq_value(B). { A = createNodeList(pCxt, B); } -column_eq_value_list(A) ::= column_eq_value_list(B) NK_COMMA column_eq_value(C). { A = addNodeToList(pCxt, B, C);} +%type column_tag_value_list { SNodeList* } +%destructor column_tag_value_list { nodesDestroyList($$); } +column_tag_value(A) ::= column_name(C) NK_EQ tags_literal(D). { A = createAlterSingleTagColumnNode(pCxt, &C, D); } +column_tag_value_list(A) ::= column_tag_value(B). { A = createNodeList(pCxt, B); } +column_tag_value_list(A) ::= column_tag_value_list(B) NK_COMMA column_tag_value(C). { A = addNodeToList(pCxt, B, C);} alter_table_clause(A) ::= - full_table_name(B) SET TAG column_eq_value_list(C). { A = createAlterTableSetMultiTagValue(pCxt, B, C); } + full_table_name(B) SET TAG column_tag_value_list(C). { A = createAlterTableSetMultiTagValue(pCxt, B, C); } %type multi_create_clause { SNodeList* } %destructor multi_create_clause { nodesDestroyList($$); } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index b41dad0b18..8b0fc19739 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -2555,6 +2555,7 @@ SNode* createAlterSingleTagColumnNode(SAstCreateContext* pCtx, SToken* pTagName, pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_TAG_VAL; COPY_STRING_FORM_ID_TOKEN(pStmt->colName, pTagName); pStmt->pVal = (SValueNode*)pVal; + pStmt->pNodeListTagValue = NULL; return (SNode*)pStmt; _err: return NULL; diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index 39b142881f..657deb43d0 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -970,7 +970,6 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) { case QUERY_NODE_DROP_SUPER_TABLE_STMT: return collectMetaKeyFromDropStable(pCxt, (SDropSuperTableStmt*)pStmt); case QUERY_NODE_ALTER_TABLE_STMT: - case QUERY_NODE_ALTER_TABLE_MULTI_STMT: return collectMetaKeyFromAlterTable(pCxt, (SAlterTableStmt*)pStmt); case QUERY_NODE_ALTER_SUPER_TABLE_STMT: return collectMetaKeyFromAlterStable(pCxt, (SAlterTableStmt*)pStmt); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 3543ee1a53..ebb6693508 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -15184,11 +15184,7 @@ static int32_t rewriteDropSuperTable(STranslateContext* pCxt, SQuery* pQuery) { static int32_t buildUpdateTagValReqImpl2(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta, char* colName, SMultiTagUpateVal* pReq) { - int32_t code = TSDB_CODE_SUCCESS; - if (NULL == pReq->tagName) { - return terrno; - } - + int32_t code = TSDB_CODE_SUCCESS; SSchema* pSchema = getTagSchema(pTableMeta, colName); if (NULL == pSchema) { return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE, "Invalid tag name: %s", colName); @@ -15360,7 +15356,7 @@ static int32_t buildUpdateMultiTagValReq(STranslateContext* pCxt, SAlterTableStm return buildUpdateTagValReqImpl(pCxt, head, pTableMeta, head->colName, pReq); } else { pReq->pMultiTag = taosArrayInit(nTagValues, sizeof(SMultiTagUpateVal)); - if (NULL == pReq->pTagArray) { + if (pReq->pMultiTag == NULL) { return terrno; } @@ -15373,7 +15369,9 @@ static int32_t buildUpdateMultiTagValReq(STranslateContext* pCxt, SAlterTableStm if (TSDB_CODE_SUCCESS != code) { return code; } - TAOS_UNUSED(taosArrayPush(pReq->pMultiTag, &val)); + if (taosArrayPush(pReq->pMultiTag, &val) == NULL) { + return terrno; + } } } @@ -15658,6 +15656,18 @@ static int32_t buildModifyVnodeArray(STranslateContext* pCxt, SAlterTableStmt* p return code; } +static void deleTagVal(void* val) { + SMultiTagUpateVal* pTag = val; + taosMemoryFree(pTag->tagName); + for (int i = 0; i < taosArrayGetSize(pTag->pTagArray); ++i) { + STagVal* p = (STagVal*)taosArrayGet(pTag->pTagArray, i); + if (IS_VAR_DATA_TYPE(p->type)) { + taosMemoryFreeClear(p->pData); + } + } + + taosArrayDestroy(pTag->pTagArray); +} static void destoryAlterTbReq(SVAlterTbReq* pReq) { taosMemoryFree(pReq->tbName); taosMemoryFree(pReq->colName); @@ -15670,6 +15680,10 @@ static void destoryAlterTbReq(SVAlterTbReq* pReq) { taosMemoryFreeClear(p->pData); } } + if (pReq->action == TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL) { + taosArrayDestroyEx(pReq->pMultiTag, deleTagVal); + } + taosArrayDestroy(pReq->pTagArray); if (pReq->tagFree) tTagFree((STag*)pReq->pTagVal); } @@ -16374,7 +16388,6 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { case QUERY_NODE_DROP_SUPER_TABLE_STMT: code = rewriteDropSuperTable(pCxt, pQuery); break; - case QUERY_NODE_ALTER_TABLE_MULTI_STMT: case QUERY_NODE_ALTER_TABLE_STMT: code = rewriteAlterTable(pCxt, pQuery); break; From ac012b83ec1fa6aa4dcaded9282c9e5240558ffa Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 25 Nov 2024 16:04:47 +0800 Subject: [PATCH 04/25] fix mem leak --- source/client/src/clientRawBlockWrite.c | 87 +++++++++++++------------ 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/source/client/src/clientRawBlockWrite.c b/source/client/src/clientRawBlockWrite.c index 1799f29eb4..30d4cdb573 100644 --- a/source/client/src/clientRawBlockWrite.c +++ b/source/client/src/clientRawBlockWrite.c @@ -762,6 +762,11 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) { RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colValueNull", isNullCJson)); break; } + case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL: { + + break; + } + case TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS: { cJSON* colName = cJSON_CreateString(vAlterTbReq.colName); RAW_NULL_CHECK(colName); @@ -1855,19 +1860,19 @@ end: typedef int32_t _raw_decode_func_(SDecoder* pDecoder, SMqDataRsp* pRsp); static int32_t decodeRawData(SDecoder* decoder, void* data, int32_t dataLen, _raw_decode_func_ func, SMqRspObj* rspObj) { - int8_t dataVersion = *(int8_t*)data; - if (dataVersion >= MQ_DATA_RSP_VERSION) { - data = POINTER_SHIFT(data, sizeof(int8_t) + sizeof(int32_t)); - dataLen -= sizeof(int8_t) + sizeof(int32_t); + int8_t dataVersion = *(int8_t*)data; + if (dataVersion >= MQ_DATA_RSP_VERSION) { + data = POINTER_SHIFT(data, sizeof(int8_t) + sizeof(int32_t)); + dataLen -= sizeof(int8_t) + sizeof(int32_t); } - rspObj->resIter = -1; - tDecoderInit(decoder, data, dataLen); - int32_t code = func(decoder, &rspObj->dataRsp); - if (code != 0) { - SET_ERROR_MSG("decode mq taosx data rsp failed"); + rspObj->resIter = -1; + tDecoderInit(decoder, data, dataLen); + int32_t code = func(decoder, &rspObj->dataRsp); + if (code != 0) { + SET_ERROR_MSG("decode mq taosx data rsp failed"); } - return code; + return code; } static int32_t processCacheMeta(SHashObj* pVgHash, SHashObj* pNameHash, SHashObj* pMetaHash, @@ -2195,44 +2200,44 @@ static int32_t getOffSetLen(const SMqDataRsp* pRsp) { typedef int32_t __encode_func__(SEncoder* pEncoder, const SMqDataRsp* pRsp); static int32_t encodeMqDataRsp(__encode_func__* encodeFunc, SMqDataRsp* rspObj, tmq_raw_data* raw) { - int32_t len = 0; - int32_t code = 0; - SEncoder encoder = {0}; - void* buf = NULL; - tEncodeSize(encodeFunc, rspObj, len, code); - if (code < 0) { - code = TSDB_CODE_INVALID_MSG; - goto FAILED; + int32_t len = 0; + int32_t code = 0; + SEncoder encoder = {0}; + void* buf = NULL; + tEncodeSize(encodeFunc, rspObj, len, code); + if (code < 0) { + code = TSDB_CODE_INVALID_MSG; + goto FAILED; } - len += sizeof(int8_t) + sizeof(int32_t); - buf = taosMemoryCalloc(1, len); - if (buf == NULL) { - code = terrno; - goto FAILED; + len += sizeof(int8_t) + sizeof(int32_t); + buf = taosMemoryCalloc(1, len); + if (buf == NULL) { + code = terrno; + goto FAILED; } - tEncoderInit(&encoder, buf, len); - if (tEncodeI8(&encoder, MQ_DATA_RSP_VERSION) < 0) { - code = TSDB_CODE_INVALID_MSG; - goto FAILED; + tEncoderInit(&encoder, buf, len); + if (tEncodeI8(&encoder, MQ_DATA_RSP_VERSION) < 0) { + code = TSDB_CODE_INVALID_MSG; + goto FAILED; } - int32_t offsetLen = getOffSetLen(rspObj); - if (offsetLen <= 0) { - code = TSDB_CODE_INVALID_MSG; - goto FAILED; + int32_t offsetLen = getOffSetLen(rspObj); + if (offsetLen <= 0) { + code = TSDB_CODE_INVALID_MSG; + goto FAILED; } - if (tEncodeI32(&encoder, offsetLen) < 0) { - code = TSDB_CODE_INVALID_MSG; - goto FAILED; + if (tEncodeI32(&encoder, offsetLen) < 0) { + code = TSDB_CODE_INVALID_MSG; + goto FAILED; } - if (encodeFunc(&encoder, rspObj) < 0) { - code = TSDB_CODE_INVALID_MSG; - goto FAILED; + if (encodeFunc(&encoder, rspObj) < 0) { + code = TSDB_CODE_INVALID_MSG; + goto FAILED; } - tEncoderClear(&encoder); + tEncoderClear(&encoder); - raw->raw = buf; - raw->raw_len = len; - return code; + raw->raw = buf; + raw->raw_len = len; + return code; FAILED: tEncoderClear(&encoder); taosMemoryFree(buf); From 28aae929d4e72d2ecf096ea3ee5441726a70eb5e Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 25 Nov 2024 17:03:02 +0800 Subject: [PATCH 05/25] support subscript --- source/client/src/clientRawBlockWrite.c | 45 ++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/source/client/src/clientRawBlockWrite.c b/source/client/src/clientRawBlockWrite.c index 30d4cdb573..924b1ce202 100644 --- a/source/client/src/clientRawBlockWrite.c +++ b/source/client/src/clientRawBlockWrite.c @@ -763,7 +763,50 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) { break; } case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL: { - + int32_t nTags = taosArrayGetSize(vAlterTbReq.pMultiTag); + if (nTags <= 0) { + uError("processAlterTable parse multi tags error"); + goto end; + } + + cJSON* tags = cJSON_CreateArray(); + RAW_NULL_CHECK(tags); + for (int32_t i = 0; i < nTags; i++) { + SMultiTagUpateVal* pTagVal = taosArrayGet(vAlterTbReq.pMultiTag, i); + cJSON* tagName = cJSON_CreateString(pTagVal->tagName); + RAW_NULL_CHECK(tagName); + RAW_FALSE_CHECK(cJSON_AddItemToObject(tags, "colName", tagName)); + + if (pTagVal->tagType == TSDB_DATA_TYPE_JSON) { + uError("processAlterTable isJson false"); + goto end; + } + bool isNull = pTagVal->isNull; + if (!isNull) { + char* buf = NULL; + int64_t bufSize = 0; + if (pTagVal->tagType == TSDB_DATA_TYPE_VARBINARY) { + bufSize = pTagVal->nTagVal * 2 + 2 + 3; + } else { + bufSize = pTagVal->nTagVal + 3; + } + buf = taosMemoryCalloc(bufSize, 1); + RAW_NULL_CHECK(buf); + if (dataConverToStr(buf, bufSize, pTagVal->tagType, pTagVal->pTagVal, pTagVal->nTagVal, NULL) != + TSDB_CODE_SUCCESS) { + taosMemoryFree(buf); + goto end; + } + cJSON* colValue = cJSON_CreateString(buf); + RAW_NULL_CHECK(colValue); + RAW_FALSE_CHECK(cJSON_AddItemToObject(tags, "colValue", colValue)); + taosMemoryFree(buf); + } + cJSON* isNullCJson = cJSON_CreateBool(isNull); + RAW_NULL_CHECK(isNullCJson); + RAW_FALSE_CHECK(cJSON_AddItemToObject(tags, "colValueNull", isNullCJson)); + } + RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tags", tags)); break; } From c2ca865f2c5d0b212bbfef257a765f6588c74afe Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 25 Nov 2024 18:52:34 +0800 Subject: [PATCH 06/25] support subscript --- source/common/src/tmsg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index fd3af20ac1..b6912f457a 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -10511,7 +10511,7 @@ int32_t tEncodeSVAlterTbReq(SEncoder *pEncoder, const SVAlterTbReq *pReq) { TAOS_CHECK_EXIT(tEncodeBinary(pEncoder, pReq->pTagVal, pReq->nTagVal)); } break; - case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL: + case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL: { int32_t nTags = taosArrayGetSize(pReq->pMultiTag); TAOS_CHECK_EXIT(tEncodeI32v(pEncoder, nTags)); for (int32_t i = 0; i < nTags; i++) { @@ -10525,6 +10525,7 @@ int32_t tEncodeSVAlterTbReq(SEncoder *pEncoder, const SVAlterTbReq *pReq) { } } break; + } case TSDB_ALTER_TABLE_UPDATE_OPTIONS: TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pReq->updateTTL)); if (pReq->updateTTL) { From 81d177d52d832adfe73756cd3f77963f1159a44f Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 25 Nov 2024 19:17:56 +0800 Subject: [PATCH 07/25] support subscript --- source/libs/parser/src/parTranslater.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index ebb6693508..b4452172d8 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -15192,11 +15192,12 @@ static int32_t buildUpdateTagValReqImpl2(STranslateContext* pCxt, SAlterTableStm pReq->tagName = taosStrdup(colName); if (NULL == pReq->tagName) { - return terrno; + TAOS_CHECK_GOTO(terrno, NULL, _err); } + pReq->pTagArray = taosArrayInit(1, sizeof(STagVal)); if (NULL == pReq->pTagArray) { - return terrno; + TAOS_CHECK_GOTO(terrno, NULL, _err); } pReq->colId = pSchema->colId; pReq->tagType = pSchema->type; @@ -15246,7 +15247,11 @@ static int32_t buildUpdateTagValReqImpl2(STranslateContext* pCxt, SAlterTableStm } } } - +_err: + if (code != 0) { + taosArrayDestroy(pReq->pTagArray); + taosMemoryFree(pReq->tagName); + } return code; } static int32_t buildUpdateTagValReqImpl(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta, @@ -15363,7 +15368,7 @@ static int32_t buildUpdateMultiTagValReq(STranslateContext* pCxt, SAlterTableStm SAlterTableStmt* pTagStmt = NULL; SNode* pNode = NULL; FOREACH(pNode, pNodeList) { - SMultiTagUpateVal val; + SMultiTagUpateVal val = {0}; pTagStmt = (SAlterTableStmt*)pNode; code = buildUpdateTagValReqImpl2(pCxt, pTagStmt, pTableMeta, pTagStmt->colName, &val); if (TSDB_CODE_SUCCESS != code) { From 8a10fd4f7ef004e47aa6c101cc4a07f958a3ef58 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 25 Nov 2024 20:27:48 +0800 Subject: [PATCH 08/25] refactor code --- include/common/tmsg.h | 1 + source/common/src/tmsg.c | 12 +++++++ source/libs/parser/src/parTranslater.c | 47 ++++++++++++++------------ 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index bcbae641f2..26b15c2b76 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -3304,6 +3304,7 @@ typedef struct { int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq); int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq); int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs); +void tfreeMultiTagUpateVal(void* pMultiTag); typedef struct { int32_t code; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index b6912f457a..a9883e7f6c 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -10678,6 +10678,18 @@ _exit: return code; } +void tfreeMultiTagUpateVal(void *val) { + SMultiTagUpateVal *pTag = val; + taosMemoryFree(pTag->tagName); + for (int i = 0; i < taosArrayGetSize(pTag->pTagArray); ++i) { + STagVal *p = (STagVal *)taosArrayGet(pTag->pTagArray, i); + if (IS_VAR_DATA_TYPE(p->type)) { + taosMemoryFreeClear(p->pData); + } + } + + taosArrayDestroy(pTag->pTagArray); +} int32_t tEncodeSVAlterTbRsp(SEncoder *pEncoder, const SVAlterTbRsp *pRsp) { int32_t code = 0; int32_t lino; diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index b4452172d8..c0f6ab124a 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -15340,9 +15340,10 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS static int32_t buildUpdateMultiTagValReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta, SVAlterTbReq* pReq) { - SName tbName = {0}; - SArray* pTsmas = NULL; - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; + SName tbName = {0}; + SArray* pTsmas = NULL; + SHashObj* pUnique = NULL; if (pCxt->pMetaCache) { toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tbName); code = getTableTsmasFromCache(pCxt->pMetaCache, &tbName, &pTsmas); @@ -15365,21 +15366,37 @@ static int32_t buildUpdateMultiTagValReq(STranslateContext* pCxt, SAlterTableStm return terrno; } + pUnique = taosHashInit(nTagValues, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); + if (pUnique == NULL) { + TAOS_CHECK_GOTO(terrno, NULL, _err); + } + SAlterTableStmt* pTagStmt = NULL; SNode* pNode = NULL; + int8_t dummpy = 0; FOREACH(pNode, pNodeList) { SMultiTagUpateVal val = {0}; pTagStmt = (SAlterTableStmt*)pNode; - code = buildUpdateTagValReqImpl2(pCxt, pTagStmt, pTableMeta, pTagStmt->colName, &val); - if (TSDB_CODE_SUCCESS != code) { - return code; + + SMultiTagUpateVal* p = taosHashGet(pUnique, pTagStmt->colName, strlen(pTagStmt->colName)); + if (p) { + code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_DUPLICATED_COLUMN); + TAOS_CHECK_GOTO(code, NULL, _err); } + + code = taosHashPut(pUnique, pTagStmt->colName, strlen(pTagStmt->colName), &dummpy, sizeof(dummpy)); + TAOS_CHECK_GOTO(code, NULL, _err); + + code = buildUpdateTagValReqImpl2(pCxt, pTagStmt, pTableMeta, pTagStmt->colName, &val); + TAOS_CHECK_GOTO(code, NULL, _err); + if (taosArrayPush(pReq->pMultiTag, &val) == NULL) { - return terrno; + TAOS_CHECK_GOTO(terrno, NULL, _err); } } } - +_err: + taosHashCleanup(pUnique); return code; } @@ -15661,18 +15678,6 @@ static int32_t buildModifyVnodeArray(STranslateContext* pCxt, SAlterTableStmt* p return code; } -static void deleTagVal(void* val) { - SMultiTagUpateVal* pTag = val; - taosMemoryFree(pTag->tagName); - for (int i = 0; i < taosArrayGetSize(pTag->pTagArray); ++i) { - STagVal* p = (STagVal*)taosArrayGet(pTag->pTagArray, i); - if (IS_VAR_DATA_TYPE(p->type)) { - taosMemoryFreeClear(p->pData); - } - } - - taosArrayDestroy(pTag->pTagArray); -} static void destoryAlterTbReq(SVAlterTbReq* pReq) { taosMemoryFree(pReq->tbName); taosMemoryFree(pReq->colName); @@ -15686,7 +15691,7 @@ static void destoryAlterTbReq(SVAlterTbReq* pReq) { } } if (pReq->action == TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL) { - taosArrayDestroyEx(pReq->pMultiTag, deleTagVal); + taosArrayDestroyEx(pReq->pMultiTag, tfreeMultiTagUpateVal); } taosArrayDestroy(pReq->pTagArray); From 5a65b1977ed39a54c518f5bc5ae85e1fddafc5c0 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 26 Nov 2024 09:03:00 +0800 Subject: [PATCH 09/25] refactor code --- source/common/src/tmsg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index a9883e7f6c..d51c981331 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -10592,7 +10592,7 @@ static int32_t tDecodeSVAlterTbReqCommon(SDecoder *pDecoder, SVAlterTbReq *pReq) TAOS_CHECK_EXIT(tDecodeBinary(pDecoder, &pReq->pTagVal, &pReq->nTagVal)); } break; - case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL: + case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL: { int32_t nTags; TAOS_CHECK_EXIT(tDecodeI32v(pDecoder, &nTags)); pReq->pMultiTag = taosArrayInit(nTags, sizeof(SMultiTagUpateVal)); @@ -10613,6 +10613,7 @@ static int32_t tDecodeSVAlterTbReqCommon(SDecoder *pDecoder, SVAlterTbReq *pReq) } } break; + } case TSDB_ALTER_TABLE_UPDATE_OPTIONS: TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pReq->updateTTL)); if (pReq->updateTTL) { From 3bae6751080befee710a4e3b48d27d1581743ef8 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 26 Nov 2024 09:45:04 +0800 Subject: [PATCH 10/25] refactor code --- tests/script/tsim/tag/change_multi_tag.sim | 846 +++++++++++++++++++++ 1 file changed, 846 insertions(+) create mode 100644 tests/script/tsim/tag/change_multi_tag.sim diff --git a/tests/script/tsim/tag/change_multi_tag.sim b/tests/script/tsim/tag/change_multi_tag.sim new file mode 100644 index 0000000000..93ed8e633d --- /dev/null +++ b/tests/script/tsim/tag/change_multi_tag.sim @@ -0,0 +1,846 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sql connect + +print ======================== dnode1 start + +$dbPrefix = ta_ad_db +$tbPrefix = ta_ad_tb +$mtPrefix = ta_ad_mt +$tbNum = 10 +$rowNum = 20 +$totalNum = 200 + +print =============== step1 +$i = 0 +$db = $dbPrefix . $i + +sql create database $db +sql use $db + +print =============== step2 +$i = 2 +$mt = $mtPrefix . $i +$tb = $tbPrefix . $i +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 bool, tagCol2 tinyint, tagCol3 smallint, tagCol4 int, tagCol5 bigint, tagCol6 nchar(10), tagCol7 binary(8)) +sql create table $tb using $mt tags( 1, 2, 3, 5, "test", "test") +sql insert into $tb values(now, 1) +sql select * from $mt where tgcol2 = 2 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 2 then + return -1 +endi +sql alter table +sql alter table $mt drop tag tgcol2 +sql alter table $mt add tag tgcol4 int +sql reset query cache +sql alter table $tb set tag tgcol4 =4 +sql reset query cache + +sql select * from $mt where tgcol4 = 4 +print $data01 $data02 $data03 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 4 then + return -1 +endi + +sql select * from $mt where tgcol2 = 1 -x step2 + return -1 +step2: + +print =============== step3 +$i = 3 +$mt = $mtPrefix . $i +$tb = $tbPrefix . $i +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 smallint, tgcol2 tinyint) +sql create table $tb using $mt tags( 1, 2 ) +sql insert into $tb values(now, 1) +sql select * from $mt where tgcol2 = 2 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 2 then + return -1 +endi + +sql alter table $mt drop tag tgcol2 +sql alter table $mt add tag tgcol4 tinyint +sql reset query cache +sql alter table $tb set tag tgcol4=4 +sql reset query cache + +sql select * from $mt where tgcol4 = 4 +print $data01 $data02 $data03 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 4 then + return -1 +endi + +sql select * from $mt where tgcol2 = 1 -x step3 + return -1 +step3: + +print =============== step4 +$i = 4 +$mt = $mtPrefix . $i +$tb = $tbPrefix . $i +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 bigint, tgcol2 float) +sql create table $tb using $mt tags( 1, 2 ) +sql insert into $tb values(now, 1) +sql select * from $mt where tgcol2 = 2 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 2.00000 then + return -1 +endi + +sql describe $tb +print sql describe $tb +if $data21 != BIGINT then + return -1 +endi +if $data31 != FLOAT then + return -1 +endi +if $data23 != TAG then + return -1 +endi +if $data33 != TAG then + return -1 +endi + +sql alter table $mt drop tag tgcol2 +sql alter table $mt add tag tgcol4 float +sql reset query cache +sql alter table $tb set tag tgcol4=4 +sql reset query cache + +sql select * from $mt where tgcol4 = 4 +print $data01 $data02 $data03 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 4.00000 then + return -1 +endi + +sql select * from $mt where tgcol2 = 1 -x step4 + return -1 +step4: + +print =============== step5 +$i = 5 +$mt = $mtPrefix . $i +$tb = $tbPrefix . $i +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 double, tgcol2 binary(10)) +sql create table $tb using $mt tags( 1, '2' ) +sql insert into $tb values(now, 1) +sql select * from $mt where tgcol2 = '2' +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1.000000000 then + return -1 +endi +if $data03 != 2 then + return -1 +endi + +sql alter table $mt drop tag tgcol2 +sql alter table $mt add tag tgcol4 smallint +sql reset query cache +sql alter table $tb set tag tgcol4=4 +sql reset query cache + +sql select * from $mt where tgcol4 = 4 +print $data01 $data02 $data03 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1.000000000 then + return -1 +endi +if $data03 != 4 then + return -1 +endi + +sql select * from $mt where tgcol3 = '1' -x step5 + return -1 +step5: + +print =============== step6 +$i = 6 +$mt = $mtPrefix . $i +$tb = $tbPrefix . $i +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 bool, tgcol2 int, tgcol3 tinyint) +sql create table $tb using $mt tags( 1, 2, 3 ) +sql insert into $tb values(now, 1) +sql select * from $mt where tgcol2 = 2 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 2 then + return -1 +endi +if $data04 != 3 then + return -1 +endi + +sql alter table $mt rename tag tgcol1 tgcol4 +sql alter table $mt drop tag tgcol2 +sql alter table $mt drop tag tgcol3 +sql alter table $mt add tag tgcol5 binary(10) +sql alter table $mt add tag tgcol6 binary(10) + +sql reset query cache +sql alter table $tb set tag tgcol4=false +sql alter table $tb set tag tgcol5='5' +sql alter table $tb set tag tgcol6='6' +sql reset query cache + +sql select * from $mt where tgcol5 = '5' +print $data01 $data02 $data03 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data03 != 5 then + return -1 +endi +if $data04 != 6 then + return -1 +endi + +sql select * from $mt where tgcol6 = '6' +print $data01 $data02 $data03 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data03 != 5 then + return -1 +endi +if $data04 != 6 then + return -1 +endi + +sql select * from $mt where tgcol4 = 1 +if $rows != 0 then + return -1 +endi +sql select * from $mt where tgcol3 = 1 -x step52 + return -1 +step52: + +print =============== step7 +$i = 7 +$mt = $mtPrefix . $i +$tb = $tbPrefix . $i +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 smallint, tgcol2 tinyint, tgcol3 binary(10)) +sql create table $tb using $mt tags( 1, 2, '3' ) +sql insert into $tb values(now, 1) +sql select * from $mt where tgcol3 = '3' +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 2 then + return -1 +endi +if $data04 != 3 then + return -1 +endi + +sql alter table $mt rename tag tgcol1 tgcol4 +sql alter table $mt drop tag tgcol2 +sql alter table $mt drop tag tgcol3 +sql alter table $mt add tag tgcol5 bigint +sql alter table $mt add tag tgcol6 tinyint + +sql reset query cache +sql alter table $tb set tag tgcol4=4 +sql alter table $tb set tag tgcol5=5 +sql alter table $tb set tag tgcol6=6 +sql reset query cache + +sql select * from $mt where tgcol6 = 6 +print $data01 $data02 $data03 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 4 then + return -1 +endi +if $data03 != 5 then + return -1 +endi +if $data04 != 6 then + return -1 +endi + +sql select * from $mt where tgcol2 = 1 -x step71 + return -1 +step71: +sql select * from $mt where tgcol3 = 1 -x step72 + return -1 +step72: + +print =============== step8 +$i = 8 +$mt = $mtPrefix . $i +$tb = $tbPrefix . $i +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 bigint, tgcol2 float, tgcol3 binary(10)) +sql create table $tb using $mt tags( 1, 2, '3' ) +sql insert into $tb values(now, 1) +sql select * from $mt where tgcol3 = '3' +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 2.00000 then + return -1 +endi +if $data04 != 3 then + return -1 +endi + +sql alter table $mt rename tag tgcol1 tgcol4 +sql alter table $mt drop tag tgcol2 +sql alter table $mt drop tag tgcol3 +sql alter table $mt add tag tgcol5 binary(17) +sql alter table $mt add tag tgcol6 bool +sql reset query cache +sql alter table $tb set tag tgcol4=4 +sql alter table $tb set tag tgcol5='5' +sql alter table $tb set tag tgcol6='1' +sql reset query cache + +sql select * from $mt where tgcol5 = '5' +print select * from $mt where tgcol5 = 5 +print $data01 $data02 $data03 $data04 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 4 then + return -1 +endi +if $data03 != 5 then + return -1 +endi +if $data04 != 1 then + return -1 +endi + +sql select * from $mt where tgcol2 = 1 -x step81 + return -1 +step81: +sql select * from $mt where tgcol3 = 1 -x step82 + return -1 +step82: + +print =============== step9 +$i = 9 +$mt = $mtPrefix . $i +$tb = $tbPrefix . $i +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 double, tgcol2 binary(10), tgcol3 binary(10)) +sql create table $tb using $mt tags( 1, '2', '3' ) +sql insert into $tb values(now, 1) +sql select * from $mt where tgcol2 = '2' +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1.000000000 then + return -1 +endi +if $data03 != 2 then + return -1 +endi +if $data04 != 3 then + return -1 +endi + +sql alter table $mt rename tag tgcol1 tgcol4 +sql alter table $mt drop tag tgcol2 +sql alter table $mt drop tag tgcol3 +sql alter table $mt add tag tgcol5 bool +sql alter table $mt add tag tgcol6 float + +sql reset query cache +sql alter table $tb set tag tgcol4=4 +sql alter table $tb set tag tgcol5=1 +sql alter table $tb set tag tgcol6=6 +sql reset query cache + +sql select * from $mt where tgcol5 = 1 +print $data01 $data02 $data03 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 4.000000000 then + return -1 +endi +if $data03 != 1 then + return -1 +endi +if $data04 != 6.00000 then + return -1 +endi + +sql select * from $mt where tgcol3 = 1 -x step91 + return -1 +step91: +sql select * from $mt where tgcol2 = 1 -x step92 + return -1 +step92: + +print =============== step10 +$i = 10 +$mt = $mtPrefix . $i +$tb = $tbPrefix . $i +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 binary(10), tgcol2 binary(10), tgcol3 binary(10), tgcol4 binary(10)) +sql create table $tb using $mt tags( '1', '2', '3', '4' ) +sql insert into $tb values(now, 1) +sql select * from $mt where tgcol4 = '4' +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 2 then + return -1 +endi +if $data04 != 3 then + return -1 +endi +if $data05 != 4 then + return -1 +endi + +sql alter table $mt rename tag tgcol1 tgcol4 -x step103 + return -1 +step103: + +sql alter table $mt drop tag tgcol2 +sql alter table $mt drop tag tgcol3 +sql alter table $mt drop tag tgcol4 +sql reset query cache +sql alter table $mt add tag tgcol4 binary(10) +sql alter table $mt add tag tgcol5 bool + +sql reset query cache +sql alter table $tb set tag tgcol4='4' +sql alter table $tb set tag tgcol5=false +sql reset query cache + +sql select * from $mt where tgcol4 = '4' +print $data01 $data02 $data03 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 4 then + return -1 +endi +if $data04 != 0 then + return -1 +endi +if $data05 != null then + return -1 +endi + +sql select * from $mt where tgcol2 = 1 -x step101 + return -1 +step101: +sql select * from $mt where tgcol3 = 1 -x step102 + return -1 +step102: + +print =============== step11 +$i = 11 +$mt = $mtPrefix . $i +$tb = $tbPrefix . $i +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 bool, tgcol2 int, tgcol3 smallint, tgcol4 float, tgcol5 binary(10)) +sql create table $tb using $mt tags( 1, 2, 3, 4, '5' ) +sql insert into $tb values(now, 1) +sql select * from $mt where tgcol1 = 1 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 2 then + return -1 +endi +if $data04 != 3 then + return -1 +endi +if $data05 != 4.00000 then + return -1 +endi +if $data06 != 5 then + return -1 +endi + +sql alter table $mt rename tag tgcol1 tgcol4 -x step114 + return -1 +step114: + +sql alter table $mt drop tag tgcol2 +sql alter table $mt drop tag tgcol3 +sql alter table $mt drop tag tgcol4 +sql alter table $mt drop tag tgcol5 +sql reset query cache +sql alter table $mt add tag tgcol4 binary(10) +sql alter table $mt add tag tgcol5 int +sql alter table $mt add tag tgcol6 binary(10) +sql alter table $mt add tag tgcol7 bigint +sql alter table $mt add tag tgcol8 smallint + +sql reset query cache +sql alter table $tb set tag tgcol4='4' +sql alter table $tb set tag tgcol5=5 +sql alter table $tb set tag tgcol6='6' +sql alter table $tb set tag tgcol7=7 +sql alter table $tb set tag tgcol8=8 +sql reset query cache + +sql select * from $mt where tgcol5 =5 +print $data01 $data02 $data03 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 4 then + return -1 +endi +if $data04 != 5 then + return -1 +endi +if $data05 != 6 then + return -1 +endi +if $data06 != 7 then + return -1 +endi +if $data07 != 8 then + return -1 +endi + +sql select * from $mt where tgcol2 = 1 -x step111 + return -1 +step111: +sql select * from $mt where tgcol3 = 1 -x step112 + return -1 +step112: +sql select * from $mt where tgcol9 = 1 -x step113 + return -1 +step113: + +print =============== step12 +$i = 12 +$mt = $mtPrefix . $i +$tb = $tbPrefix . $i +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 bool, tgcol2 smallint, tgcol3 float, tgcol4 double, tgcol5 binary(10), tgcol6 binary(20)) +sql create table $tb using $mt tags( 1, 2, 3, 4, '5', '6' ) +sql insert into $tb values(now, 1) +sql select * from $mt where tgcol1 = 1 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 2 then + return -1 +endi +if $data04 != 3.00000 then + return -1 +endi +if $data05 != 4.000000000 then + return -1 +endi +if $data06 != 5 then + return -1 +endi +if $data07 != 6 then + return -1 +endi + +sql alter table $mt drop tag tgcol2 +sql alter table $mt drop tag tgcol3 +sql alter table $mt drop tag tgcol4 +sql alter table $mt drop tag tgcol5 +sql reset query cache +sql alter table $mt add tag tgcol2 binary(10) +sql alter table $mt add tag tgcol3 int +sql alter table $mt add tag tgcol4 binary(10) +sql alter table $mt add tag tgcol5 bigint + +sql reset query cache +sql alter table $tb set tag tgcol1=false +sql alter table $tb set tag tgcol2='5' +sql alter table $tb set tag tgcol3=4 +sql alter table $tb set tag tgcol4='3' +sql alter table $tb set tag tgcol5=2 +sql alter table $tb set tag tgcol6='1' +sql reset query cache + +sql select * from $mt where tgcol4 = '3' +print $data01 $data02 $data03 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data03 != 1 then + return -1 +endi +if $data04 != 5 then + return -1 +endi +if $data05 != 4 then + return -1 +endi +if $data06 != 3 then + return -1 +endi +if $data07 != 2 then + return -1 +endi + +sql select * from $mt where tgcol2 = '5' +if $rows != 1 then + return -1 +endi + +sql select * from $mt where tgcol3 = 4 +if $rows != 1 then + return -1 +endi + +sql select * from $mt where tgcol5 = 2 +if $rows != 1 then + return -1 +endi + +sql select * from $mt where tgcol6 = '1' +if $rows != 1 then + return -1 +endi + +print =============== step13 +$i = 13 +$mt = $mtPrefix . $i +$tb = $tbPrefix . $i +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 binary(10), tgcol2 int, tgcol3 smallint, tgcol4 binary(11), tgcol5 double, tgcol6 binary(20)) +sql create table $tb using $mt tags( '1', 2, 3, '4', 5, '6' ) +sql insert into $tb values(now, 1) +sql select * from $mt where tgcol1 = '1' +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 2 then + return -1 +endi +if $data04 != 3 then + return -1 +endi +if $data05 != 4 then + return -1 +endi +if $data06 != 5.000000000 then + return -1 +endi +if $data07 != 6 then + return -1 +endi + +sql alter table $mt drop tag tgcol2 +sql alter table $mt drop tag tgcol4 +sql alter table $mt drop tag tgcol6 +sql reset query cache +sql alter table $mt add tag tgcol2 binary(10) +sql alter table $mt add tag tgcol4 int +sql alter table $mt add tag tgcol6 bigint + +sql reset query cache +sql alter table $tb set tag tgcol1='7' +sql alter table $tb set tag tgcol2='8' +sql alter table $tb set tag tgcol3=9 +sql alter table $tb set tag tgcol4=10 +sql alter table $tb set tag tgcol5=11 +sql alter table $tb set tag tgcol6=12 +sql reset query cache + +sql select * from $mt where tgcol2 = '8' +print $data01 $data02 $data03 +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 7 then + return -1 +endi +if $data03 != 9 then + return -1 +endi +if $data04 != 11.000000000 then + return -1 +endi +if $data05 != 8 then + return -1 +endi +if $data06 != 10 then + return -1 +endi +if $data07 != 12 then + return -1 +endi + +print =============== step14 +$i = 14 +$mt = $mtPrefix . $i +$tb = $tbPrefix . $i +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 bool, tgcol2 bigint) +sql create table $tb using $mt tags( 1, 1 ) +sql insert into $tb values(now, 1) + +sql alter table $mt add tag tgcol3 binary(10) +sql alter table $mt add tag tgcol4 int +sql alter table $mt add tag tgcol5 bigint +sql alter table $mt add tag tgcol6 bigint + + sql reset query cache +sql alter table $mt drop tag tgcol6 +sql alter table $mt add tag tgcol7 bigint +sql alter table $mt add tag tgcol8 bigint + +print =============== clear +sql drop database $db +sql select * from information_schema.ins_databases +if $rows != 2 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT From 34ca4ca81f4ec3454f858cdb92eea4e84023933a Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 26 Nov 2024 11:17:01 +0800 Subject: [PATCH 11/25] update test case --- tests/parallel_test/cases.task | 1 + tests/script/tsim/tag/change_multi_tag.sim | 824 +-------------------- 2 files changed, 40 insertions(+), 785 deletions(-) diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 492dd11177..5dacf44ae8 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -1576,6 +1576,7 @@ ,,y,script,./test.sh -f tsim/tag/tinyint.sim ,,y,script,./test.sh -f tsim/tag/drop_tag.sim ,,y,script,./test.sh -f tsim/tag/tbNameIn.sim +,,y,script,./test.sh -f tsim/tag/change_multi_tag.sim ,,y,script,./test.sh -f tmp/monitor.sim ,,y,script,./test.sh -f tsim/tagindex/add_index.sim ,,n,script,./test.sh -f tsim/tagindex/sma_and_tag_index.sim diff --git a/tests/script/tsim/tag/change_multi_tag.sim b/tests/script/tsim/tag/change_multi_tag.sim index 93ed8e633d..b7d655ad1c 100644 --- a/tests/script/tsim/tag/change_multi_tag.sim +++ b/tests/script/tsim/tag/change_multi_tag.sim @@ -20,827 +20,81 @@ sql create database $db sql use $db print =============== step2 +$j = 3 $i = 2 $mt = $mtPrefix . $i $tb = $tbPrefix . $i -sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 bool, tagCol2 tinyint, tagCol3 smallint, tagCol4 int, tagCol5 bigint, tagCol6 nchar(10), tagCol7 binary(8)) -sql create table $tb using $mt tags( 1, 2, 3, 5, "test", "test") +$tbj = $tbPrefix . $j +$ntable = tb_normal_table + +sql create table $mt (ts timestamp, tbcol int) TAGS(tagCol1 bool, tagCol2 tinyint, tagCol3 smallint, tagCol4 int, tagCol5 bigint, tagCol6 nchar(10), tagCol7 binary(8)) +sql create table $tb using $mt tags( 1, 2, 3, 5,7, "test", "test") +sql create table $tbj using $mt tags( 2, 3, 4, 6,8, "testj", "testj") +sql create table $ntable (ts timestamp, f int) + sql insert into $tb values(now, 1) -sql select * from $mt where tgcol2 = 2 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -if $data03 != 2 then - return -1 -endi -sql alter table -sql alter table $mt drop tag tgcol2 -sql alter table $mt add tag tgcol4 int -sql reset query cache -sql alter table $tb set tag tgcol4 =4 -sql reset query cache - -sql select * from $mt where tgcol4 = 4 -print $data01 $data02 $data03 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -if $data03 != 4 then - return -1 -endi - -sql select * from $mt where tgcol2 = 1 -x step2 - return -1 -step2: - -print =============== step3 -$i = 3 -$mt = $mtPrefix . $i -$tb = $tbPrefix . $i -sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 smallint, tgcol2 tinyint) -sql create table $tb using $mt tags( 1, 2 ) sql insert into $tb values(now, 1) -sql select * from $mt where tgcol2 = 2 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -if $data03 != 2 then +sql_error alter table $mt set tag tgcol1 = 1,tagcol2 = 2, tag3 = 4 # set tag value on supertable +sql_error alter table $ntable set tag f = 10 # set normal table value +sql_error alter table $tbj set tag tagCol1=1,tagCol1 = 2 # dumplicate tag name +sql_error alter table $tbj set tag tagCol1=1,tagCol1 = 2 # not exist tag +sql_error alter table $tbj set tag tagCol1 = 1, tagCol5="xxxxxxxxxxxxxxxx" +sql_error alter table $tbj set tag tagCol1 = 1, tagCol5="xxxxxxxxxxxxxxxx", tagCol7="yyyyyyyyyyyyyyyyyyyyyyyyy" +sql alter table $tbj set tag tagCol1 = 100, tagCol2 = 100 + +sql select * from $mt where tagCol2 = 100 +if $rows != 0 then return -1 endi -sql alter table $mt drop tag tgcol2 -sql alter table $mt add tag tgcol4 tinyint -sql reset query cache -sql alter table $tb set tag tgcol4=4 -sql reset query cache - -sql select * from $mt where tgcol4 = 4 -print $data01 $data02 $data03 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -if $data03 != 4 then +sql select * from $mt where tagCol1 = 1 +if $rows != 2 then return -1 endi -sql select * from $mt where tgcol2 = 1 -x step3 - return -1 -step3: +sql alter table $tbj set tag tagCol1=true,tagCol2=-1,tagcol3=-10, tagcol4=-100,tagcol5=-1000,tagCol6="empty",tagCol7="empty" +sql alter table $tb set tag tagCol1=0 -print =============== step4 -$i = 4 -$mt = $mtPrefix . $i -$tb = $tbPrefix . $i -sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 bigint, tgcol2 float) -sql create table $tb using $mt tags( 1, 2 ) -sql insert into $tb values(now, 1) -sql select * from $mt where tgcol2 = 2 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -if $data03 != 2.00000 then +sql select * from $mt where tagCol1 = true +if $rows != 0 then return -1 endi -sql describe $tb -print sql describe $tb -if $data21 != BIGINT then - return -1 -endi -if $data31 != FLOAT then - return -1 -endi -if $data23 != TAG then - return -1 -endi -if $data33 != TAG then +sql select * from $mt where tagCol2 = -1 +if $rows != 0 then return -1 endi -sql alter table $mt drop tag tgcol2 -sql alter table $mt add tag tgcol4 float -sql reset query cache -sql alter table $tb set tag tgcol4=4 -sql reset query cache - -sql select * from $mt where tgcol4 = 4 -print $data01 $data02 $data03 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -if $data03 != 4.00000 then +sql select * from $mt where tagCol3 = -10 +if $rows != 0 then return -1 endi -sql select * from $mt where tgcol2 = 1 -x step4 - return -1 -step4: - -print =============== step5 -$i = 5 -$mt = $mtPrefix . $i -$tb = $tbPrefix . $i -sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 double, tgcol2 binary(10)) -sql create table $tb using $mt tags( 1, '2' ) -sql insert into $tb values(now, 1) -sql select * from $mt where tgcol2 = '2' -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1.000000000 then - return -1 -endi -if $data03 != 2 then +sql select * from $mt where tagCol4 = -100 +if $rows != 0 then return -1 endi -sql alter table $mt drop tag tgcol2 -sql alter table $mt add tag tgcol4 smallint -sql reset query cache -sql alter table $tb set tag tgcol4=4 -sql reset query cache - -sql select * from $mt where tgcol4 = 4 -print $data01 $data02 $data03 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1.000000000 then - return -1 -endi -if $data03 != 4 then +sql select * from $mt where tagCol4 = -1000 +if $rows != 0 then return -1 endi -sql select * from $mt where tgcol3 = '1' -x step5 - return -1 -step5: - -print =============== step6 -$i = 6 -$mt = $mtPrefix . $i -$tb = $tbPrefix . $i -sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 bool, tgcol2 int, tgcol3 tinyint) -sql create table $tb using $mt tags( 1, 2, 3 ) -sql insert into $tb values(now, 1) -sql select * from $mt where tgcol2 = 2 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -if $data03 != 2 then - return -1 -endi -if $data04 != 3 then +sql select * from $mt where tagCol5 = -10000 +if $rows != 0 then return -1 endi -sql alter table $mt rename tag tgcol1 tgcol4 -sql alter table $mt drop tag tgcol2 -sql alter table $mt drop tag tgcol3 -sql alter table $mt add tag tgcol5 binary(10) -sql alter table $mt add tag tgcol6 binary(10) - -sql reset query cache -sql alter table $tb set tag tgcol4=false -sql alter table $tb set tag tgcol5='5' -sql alter table $tb set tag tgcol6='6' -sql reset query cache - -sql select * from $mt where tgcol5 = '5' -print $data01 $data02 $data03 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 0 then - return -1 -endi -if $data03 != 5 then - return -1 -endi -if $data04 != 6 then +sql select * from $mt where tagCol6 = "empty" +if $rows != 0 then return -1 endi -sql select * from $mt where tgcol6 = '6' -print $data01 $data02 $data03 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 0 then - return -1 -endi -if $data03 != 5 then - return -1 -endi -if $data04 != 6 then +sql select * from $mt where tagCol6 = "empty1" +if $rows != 0 then return -1 endi -sql select * from $mt where tgcol4 = 1 -if $rows != 0 then - return -1 -endi -sql select * from $mt where tgcol3 = 1 -x step52 - return -1 -step52: -print =============== step7 -$i = 7 -$mt = $mtPrefix . $i -$tb = $tbPrefix . $i -sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 smallint, tgcol2 tinyint, tgcol3 binary(10)) -sql create table $tb using $mt tags( 1, 2, '3' ) -sql insert into $tb values(now, 1) -sql select * from $mt where tgcol3 = '3' -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -if $data03 != 2 then - return -1 -endi -if $data04 != 3 then - return -1 -endi - -sql alter table $mt rename tag tgcol1 tgcol4 -sql alter table $mt drop tag tgcol2 -sql alter table $mt drop tag tgcol3 -sql alter table $mt add tag tgcol5 bigint -sql alter table $mt add tag tgcol6 tinyint - -sql reset query cache -sql alter table $tb set tag tgcol4=4 -sql alter table $tb set tag tgcol5=5 -sql alter table $tb set tag tgcol6=6 -sql reset query cache - -sql select * from $mt where tgcol6 = 6 -print $data01 $data02 $data03 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 4 then - return -1 -endi -if $data03 != 5 then - return -1 -endi -if $data04 != 6 then - return -1 -endi - -sql select * from $mt where tgcol2 = 1 -x step71 - return -1 -step71: -sql select * from $mt where tgcol3 = 1 -x step72 - return -1 -step72: - -print =============== step8 -$i = 8 -$mt = $mtPrefix . $i -$tb = $tbPrefix . $i -sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 bigint, tgcol2 float, tgcol3 binary(10)) -sql create table $tb using $mt tags( 1, 2, '3' ) -sql insert into $tb values(now, 1) -sql select * from $mt where tgcol3 = '3' -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -if $data03 != 2.00000 then - return -1 -endi -if $data04 != 3 then - return -1 -endi - -sql alter table $mt rename tag tgcol1 tgcol4 -sql alter table $mt drop tag tgcol2 -sql alter table $mt drop tag tgcol3 -sql alter table $mt add tag tgcol5 binary(17) -sql alter table $mt add tag tgcol6 bool -sql reset query cache -sql alter table $tb set tag tgcol4=4 -sql alter table $tb set tag tgcol5='5' -sql alter table $tb set tag tgcol6='1' -sql reset query cache - -sql select * from $mt where tgcol5 = '5' -print select * from $mt where tgcol5 = 5 -print $data01 $data02 $data03 $data04 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 4 then - return -1 -endi -if $data03 != 5 then - return -1 -endi -if $data04 != 1 then - return -1 -endi - -sql select * from $mt where tgcol2 = 1 -x step81 - return -1 -step81: -sql select * from $mt where tgcol3 = 1 -x step82 - return -1 -step82: - -print =============== step9 -$i = 9 -$mt = $mtPrefix . $i -$tb = $tbPrefix . $i -sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 double, tgcol2 binary(10), tgcol3 binary(10)) -sql create table $tb using $mt tags( 1, '2', '3' ) -sql insert into $tb values(now, 1) -sql select * from $mt where tgcol2 = '2' -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1.000000000 then - return -1 -endi -if $data03 != 2 then - return -1 -endi -if $data04 != 3 then - return -1 -endi - -sql alter table $mt rename tag tgcol1 tgcol4 -sql alter table $mt drop tag tgcol2 -sql alter table $mt drop tag tgcol3 -sql alter table $mt add tag tgcol5 bool -sql alter table $mt add tag tgcol6 float - -sql reset query cache -sql alter table $tb set tag tgcol4=4 -sql alter table $tb set tag tgcol5=1 -sql alter table $tb set tag tgcol6=6 -sql reset query cache - -sql select * from $mt where tgcol5 = 1 -print $data01 $data02 $data03 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 4.000000000 then - return -1 -endi -if $data03 != 1 then - return -1 -endi -if $data04 != 6.00000 then - return -1 -endi - -sql select * from $mt where tgcol3 = 1 -x step91 - return -1 -step91: -sql select * from $mt where tgcol2 = 1 -x step92 - return -1 -step92: - -print =============== step10 -$i = 10 -$mt = $mtPrefix . $i -$tb = $tbPrefix . $i -sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 binary(10), tgcol2 binary(10), tgcol3 binary(10), tgcol4 binary(10)) -sql create table $tb using $mt tags( '1', '2', '3', '4' ) -sql insert into $tb values(now, 1) -sql select * from $mt where tgcol4 = '4' -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -if $data03 != 2 then - return -1 -endi -if $data04 != 3 then - return -1 -endi -if $data05 != 4 then - return -1 -endi - -sql alter table $mt rename tag tgcol1 tgcol4 -x step103 - return -1 -step103: - -sql alter table $mt drop tag tgcol2 -sql alter table $mt drop tag tgcol3 -sql alter table $mt drop tag tgcol4 -sql reset query cache -sql alter table $mt add tag tgcol4 binary(10) -sql alter table $mt add tag tgcol5 bool - -sql reset query cache -sql alter table $tb set tag tgcol4='4' -sql alter table $tb set tag tgcol5=false -sql reset query cache - -sql select * from $mt where tgcol4 = '4' -print $data01 $data02 $data03 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -if $data03 != 4 then - return -1 -endi -if $data04 != 0 then - return -1 -endi -if $data05 != null then - return -1 -endi - -sql select * from $mt where tgcol2 = 1 -x step101 - return -1 -step101: -sql select * from $mt where tgcol3 = 1 -x step102 - return -1 -step102: - -print =============== step11 -$i = 11 -$mt = $mtPrefix . $i -$tb = $tbPrefix . $i -sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 bool, tgcol2 int, tgcol3 smallint, tgcol4 float, tgcol5 binary(10)) -sql create table $tb using $mt tags( 1, 2, 3, 4, '5' ) -sql insert into $tb values(now, 1) -sql select * from $mt where tgcol1 = 1 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -if $data03 != 2 then - return -1 -endi -if $data04 != 3 then - return -1 -endi -if $data05 != 4.00000 then - return -1 -endi -if $data06 != 5 then - return -1 -endi - -sql alter table $mt rename tag tgcol1 tgcol4 -x step114 - return -1 -step114: - -sql alter table $mt drop tag tgcol2 -sql alter table $mt drop tag tgcol3 -sql alter table $mt drop tag tgcol4 -sql alter table $mt drop tag tgcol5 -sql reset query cache -sql alter table $mt add tag tgcol4 binary(10) -sql alter table $mt add tag tgcol5 int -sql alter table $mt add tag tgcol6 binary(10) -sql alter table $mt add tag tgcol7 bigint -sql alter table $mt add tag tgcol8 smallint - -sql reset query cache -sql alter table $tb set tag tgcol4='4' -sql alter table $tb set tag tgcol5=5 -sql alter table $tb set tag tgcol6='6' -sql alter table $tb set tag tgcol7=7 -sql alter table $tb set tag tgcol8=8 -sql reset query cache - -sql select * from $mt where tgcol5 =5 -print $data01 $data02 $data03 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -if $data03 != 4 then - return -1 -endi -if $data04 != 5 then - return -1 -endi -if $data05 != 6 then - return -1 -endi -if $data06 != 7 then - return -1 -endi -if $data07 != 8 then - return -1 -endi - -sql select * from $mt where tgcol2 = 1 -x step111 - return -1 -step111: -sql select * from $mt where tgcol3 = 1 -x step112 - return -1 -step112: -sql select * from $mt where tgcol9 = 1 -x step113 - return -1 -step113: - -print =============== step12 -$i = 12 -$mt = $mtPrefix . $i -$tb = $tbPrefix . $i -sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 bool, tgcol2 smallint, tgcol3 float, tgcol4 double, tgcol5 binary(10), tgcol6 binary(20)) -sql create table $tb using $mt tags( 1, 2, 3, 4, '5', '6' ) -sql insert into $tb values(now, 1) -sql select * from $mt where tgcol1 = 1 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -if $data03 != 2 then - return -1 -endi -if $data04 != 3.00000 then - return -1 -endi -if $data05 != 4.000000000 then - return -1 -endi -if $data06 != 5 then - return -1 -endi -if $data07 != 6 then - return -1 -endi - -sql alter table $mt drop tag tgcol2 -sql alter table $mt drop tag tgcol3 -sql alter table $mt drop tag tgcol4 -sql alter table $mt drop tag tgcol5 -sql reset query cache -sql alter table $mt add tag tgcol2 binary(10) -sql alter table $mt add tag tgcol3 int -sql alter table $mt add tag tgcol4 binary(10) -sql alter table $mt add tag tgcol5 bigint - -sql reset query cache -sql alter table $tb set tag tgcol1=false -sql alter table $tb set tag tgcol2='5' -sql alter table $tb set tag tgcol3=4 -sql alter table $tb set tag tgcol4='3' -sql alter table $tb set tag tgcol5=2 -sql alter table $tb set tag tgcol6='1' -sql reset query cache - -sql select * from $mt where tgcol4 = '3' -print $data01 $data02 $data03 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 0 then - return -1 -endi -if $data03 != 1 then - return -1 -endi -if $data04 != 5 then - return -1 -endi -if $data05 != 4 then - return -1 -endi -if $data06 != 3 then - return -1 -endi -if $data07 != 2 then - return -1 -endi - -sql select * from $mt where tgcol2 = '5' -if $rows != 1 then - return -1 -endi - -sql select * from $mt where tgcol3 = 4 -if $rows != 1 then - return -1 -endi - -sql select * from $mt where tgcol5 = 2 -if $rows != 1 then - return -1 -endi - -sql select * from $mt where tgcol6 = '1' -if $rows != 1 then - return -1 -endi - -print =============== step13 -$i = 13 -$mt = $mtPrefix . $i -$tb = $tbPrefix . $i -sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 binary(10), tgcol2 int, tgcol3 smallint, tgcol4 binary(11), tgcol5 double, tgcol6 binary(20)) -sql create table $tb using $mt tags( '1', 2, 3, '4', 5, '6' ) -sql insert into $tb values(now, 1) -sql select * from $mt where tgcol1 = '1' -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -if $data03 != 2 then - return -1 -endi -if $data04 != 3 then - return -1 -endi -if $data05 != 4 then - return -1 -endi -if $data06 != 5.000000000 then - return -1 -endi -if $data07 != 6 then - return -1 -endi - -sql alter table $mt drop tag tgcol2 -sql alter table $mt drop tag tgcol4 -sql alter table $mt drop tag tgcol6 -sql reset query cache -sql alter table $mt add tag tgcol2 binary(10) -sql alter table $mt add tag tgcol4 int -sql alter table $mt add tag tgcol6 bigint - -sql reset query cache -sql alter table $tb set tag tgcol1='7' -sql alter table $tb set tag tgcol2='8' -sql alter table $tb set tag tgcol3=9 -sql alter table $tb set tag tgcol4=10 -sql alter table $tb set tag tgcol5=11 -sql alter table $tb set tag tgcol6=12 -sql reset query cache - -sql select * from $mt where tgcol2 = '8' -print $data01 $data02 $data03 -if $rows != 1 then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 7 then - return -1 -endi -if $data03 != 9 then - return -1 -endi -if $data04 != 11.000000000 then - return -1 -endi -if $data05 != 8 then - return -1 -endi -if $data06 != 10 then - return -1 -endi -if $data07 != 12 then - return -1 -endi - -print =============== step14 -$i = 14 -$mt = $mtPrefix . $i -$tb = $tbPrefix . $i -sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 bool, tgcol2 bigint) -sql create table $tb using $mt tags( 1, 1 ) -sql insert into $tb values(now, 1) - -sql alter table $mt add tag tgcol3 binary(10) -sql alter table $mt add tag tgcol4 int -sql alter table $mt add tag tgcol5 bigint -sql alter table $mt add tag tgcol6 bigint - - sql reset query cache -sql alter table $mt drop tag tgcol6 -sql alter table $mt add tag tgcol7 bigint -sql alter table $mt add tag tgcol8 bigint - -print =============== clear -sql drop database $db -sql select * from information_schema.ins_databases -if $rows != 2 then - return -1 -endi system sh/exec.sh -n dnode1 -s stop -x SIGINT From ae885dc592c27f7517f5047551f4b1438b7e52ca Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 26 Nov 2024 11:28:37 +0800 Subject: [PATCH 12/25] update test case --- tests/script/tsim/tag/change_multi_tag.sim | 46 +++++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/tests/script/tsim/tag/change_multi_tag.sim b/tests/script/tsim/tag/change_multi_tag.sim index b7d655ad1c..13a4bdb1d8 100644 --- a/tests/script/tsim/tag/change_multi_tag.sim +++ b/tests/script/tsim/tag/change_multi_tag.sim @@ -40,6 +40,8 @@ sql_error alter table $tbj set tag tagCol1=1,tagCol1 = 2 # dumplicate tag name sql_error alter table $tbj set tag tagCol1=1,tagCol1 = 2 # not exist tag sql_error alter table $tbj set tag tagCol1 = 1, tagCol5="xxxxxxxxxxxxxxxx" sql_error alter table $tbj set tag tagCol1 = 1, tagCol5="xxxxxxxxxxxxxxxx", tagCol7="yyyyyyyyyyyyyyyyyyyyyyyyy" +sql_error alter table $tbj set tag tagCol1=1,tagCol5=10, tagCol1=3 +sql_error alter table $tbj set tag tagCol5="xxxx" sql alter table $tbj set tag tagCol1 = 100, tagCol2 = 100 sql select * from $mt where tagCol2 = 100 @@ -52,7 +54,7 @@ if $rows != 2 then return -1 endi -sql alter table $tbj set tag tagCol1=true,tagCol2=-1,tagcol3=-10, tagcol4=-100,tagcol5=-1000,tagCol6="empty",tagCol7="empty" +sql alter table $tbj set tag tagCol1=true,tagCol2=-1,tagcol3=-10, tagcol4=-100,tagcol5=-1000,tagCol6="empty",tagCol7="empty1" sql alter table $tb set tag tagCol1=0 sql select * from $mt where tagCol1 = true @@ -75,15 +77,11 @@ if $rows != 0 then return -1 endi -sql select * from $mt where tagCol4 = -1000 +sql select * from $mt where tagCol5 = -1000 if $rows != 0 then return -1 endi -sql select * from $mt where tagCol5 = -10000 -if $rows != 0 then - return -1 -endi sql select * from $mt where tagCol6 = "empty" if $rows != 0 then @@ -95,6 +93,42 @@ if $rows != 0 then return -1 endi +sql insert into $tbj values (now, 1) +sql select * from $mt where tagCol1 = true +if $rows != 1 then + return -1 +endi + +sql select * from $mt where tagCol2 = -1 +if $rows != 1 then + return -1 +endi + +sql select * from $mt where tagCol3 = -10 +if $rows != 1 then + return -1 +endi + +sql select * from $mt where tagCol4 = -100 +if $rows != 1 then + return -1 +endi + +sql select * from $mt where tagCol5 = -1000 +if $rows != 1 then + return -1 +endi + + +sql select * from $mt where tagCol6 = "empty" +if $rows != 1 then + return -1 +endi + +sql select * from $mt where tagCol7 = "empty1" +if $rows != 1 then + return -1 +endi system sh/exec.sh -n dnode1 -s stop -x SIGINT From d38657118dcf82762bdc5ab710e5f7ab961643f0 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 26 Nov 2024 13:50:43 +0800 Subject: [PATCH 13/25] update test case --- tests/script/tsim/tag/change_multi_tag.sim | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/script/tsim/tag/change_multi_tag.sim b/tests/script/tsim/tag/change_multi_tag.sim index 13a4bdb1d8..0ba238b05c 100644 --- a/tests/script/tsim/tag/change_multi_tag.sim +++ b/tests/script/tsim/tag/change_multi_tag.sim @@ -131,4 +131,52 @@ if $rows != 1 then return -1 endi +sql alter table $tbj set tag tagCol1=true +sql alter table $tb set tag tagCol1=true + +sql select * from $mt where tagCol1 = true +if $rows != 3 then + return -1 +endi + +sql alter table $tb set tag tagCol1=false + +sql alter table $tbj set tag tagCol1=true,tagCol2=-10,tagcol3=-100, tagcol4=-1000,tagcol5=-10000,tagCol6="empty1",tagCol7="empty2" + +sql select * from $mt where tagCol1 = true +if $rows != 1 then + return -1 +endi + +sql select * from $mt where tagCol2 = -10 +if $rows != 1 then + return -1 +endi + +sql select * from $mt where tagCol3 = -100 +if $rows != 1 then + return -1 +endi + +sql select * from $mt where tagCol4 = -1000 +if $rows != 1 then + return -1 +endi + +sql select * from $mt where tagCol5 = -10000 +if $rows != 1 then + return -1 +endi + + +sql select * from $mt where tagCol6 = "empty1" +if $rows != 1 then + return -1 +endi + +sql select * from $mt where tagCol7 = "empty2" +if $rows != 1 then + return -1 +endi + system sh/exec.sh -n dnode1 -s stop -x SIGINT From 022544d226c01a397b6dc60879120039bcfe0e5c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 26 Nov 2024 15:01:04 +0800 Subject: [PATCH 14/25] update test case --- source/libs/parser/src/parTranslater.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index c0f6ab124a..ed696ad236 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -15391,6 +15391,7 @@ static int32_t buildUpdateMultiTagValReq(STranslateContext* pCxt, SAlterTableStm TAOS_CHECK_GOTO(code, NULL, _err); if (taosArrayPush(pReq->pMultiTag, &val) == NULL) { + tfreeMultiTagUpateVal((void*)&val); TAOS_CHECK_GOTO(terrno, NULL, _err); } } From 1a05a4cd7d798932137c2b25f1ee729dc72da397 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 26 Nov 2024 17:44:06 +0800 Subject: [PATCH 15/25] update test case --- tests/system-test/0-others/empty_identifier.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/system-test/0-others/empty_identifier.py b/tests/system-test/0-others/empty_identifier.py index a576781d86..3644269b38 100644 --- a/tests/system-test/0-others/empty_identifier.py +++ b/tests/system-test/0-others/empty_identifier.py @@ -145,7 +145,6 @@ class TDTestCase: 'select * from ``', 'alter table meters add column `` int', 'alter table meters drop column ``', - 'alter table t0 set tag `` = ""', 'alter stable meters add tag `` int', 'alter stable meters rename tag cc ``', 'alter stable meters drop tag ``', From e87570c03688cb8518d51aa3b0aae9969edcccaf Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 26 Nov 2024 20:50:37 +0800 Subject: [PATCH 16/25] fix invalid free --- source/dnode/vnode/src/meta/metaTable.c | 4 ++++ tests/script/tsim/tag/change_multi_tag.sim | 2 ++ 2 files changed, 6 insertions(+) diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 54476d339f..94349048ad 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -2049,7 +2049,9 @@ static int metaUpdateTableMultiTagVal(SMeta *pMeta, int64_t version, SVAlterTbRe } if (tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData) != 0) { + tdbTbcClose(pUidIdxc); metaError("meta/table: failed to get uid index, uid:%" PRId64, uid); + return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST; } oversion = ((SUidIdxVal *)pData)[0].version; @@ -2302,7 +2304,9 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA } if (tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData) != 0) { + tdbTbcClose(pUidIdxc); metaError("meta/table: failed to get uid index, uid:%" PRId64, uid); + return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST; } oversion = ((SUidIdxVal *)pData)[0].version; diff --git a/tests/script/tsim/tag/change_multi_tag.sim b/tests/script/tsim/tag/change_multi_tag.sim index 0ba238b05c..9370afc785 100644 --- a/tests/script/tsim/tag/change_multi_tag.sim +++ b/tests/script/tsim/tag/change_multi_tag.sim @@ -179,4 +179,6 @@ if $rows != 1 then return -1 endi +sql alter table $tbj set tag tagCol1=true,tagCol2=-10,tagcol3=-100, tagcol4=-1000,tagcol5=NULL,tagCol6=NULL,tagCol7=NULL + system sh/exec.sh -n dnode1 -s stop -x SIGINT From 2aac26e0a9b492a85f65fb60cde86e93d031531c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 27 Nov 2024 07:56:24 +0800 Subject: [PATCH 17/25] fix partial failure --- source/dnode/vnode/src/meta/metaTable.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 94349048ad..e6ad1d03fc 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -2074,6 +2074,9 @@ static int metaUpdateTableMultiTagVal(SMeta *pMeta, int64_t version, SVAlterTbRe if (tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData) != 0) { metaError("meta/table: failed to get tb db, uid:%" PRId64, uid); + tdbTbcClose(pUidIdxc); + tdbTbcClose(pTbDbc); + return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST; } if ((ctbEntry.pBuf = taosMemoryMalloc(nData)) == NULL) { @@ -2329,6 +2332,8 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA if (tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData) != 0) { metaError("meta/table: failed to get tb db, uid:%" PRId64, uid); + tdbTbcClose(pUidIdxc); + tdbTbcClose(pTbDbc); } if ((ctbEntry.pBuf = taosMemoryMalloc(nData)) == NULL) { From 90d63ea5a2b389a466fd6f798d7804bc90d1c915 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 27 Nov 2024 07:59:16 +0800 Subject: [PATCH 18/25] fix partial failure --- source/libs/parser/src/parAstCreater.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 8b0fc19739..e05a399d32 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -2427,12 +2427,6 @@ static SNode* createAlterTableStmtFinalize(SNode* pRealTable, SAlterTableStmt* p nodesDestroyNode(pRealTable); return (SNode*)pStmt; } -static SNode* createAlterTableMultiStmtFinalize(SNode* pRealTable, SAlterTableMultiStmt* pStmt) { - strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); - strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName); - nodesDestroyNode(pRealTable); - return (SNode*)pStmt; -} SNode* createAlterTableModifyOptions(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions) { CHECK_PARSER_STATUS(pCxt); From 89ee604083c75c58b14fcadfcf9304c4875fd7a8 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 27 Nov 2024 09:01:02 +0800 Subject: [PATCH 19/25] add test case --- tests/script/tsim/tag/change_multi_tag.sim | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/script/tsim/tag/change_multi_tag.sim b/tests/script/tsim/tag/change_multi_tag.sim index 9370afc785..30ae1c653a 100644 --- a/tests/script/tsim/tag/change_multi_tag.sim +++ b/tests/script/tsim/tag/change_multi_tag.sim @@ -181,4 +181,25 @@ endi sql alter table $tbj set tag tagCol1=true,tagCol2=-10,tagcol3=-100, tagcol4=-1000,tagcol5=NULL,tagCol6=NULL,tagCol7=NULL +sql alter table $mt drop tag tagCol7 +sql alter table $mt drop tag tagCol3 + +sql alter table $mt add tag tagCol8 int + +sql_error alter table $tbj set tag tagCol1=true,tagCol2=-10,tagcol3=-100, tagcol4=-1000,tagcol5=NULL,tagCol6=NULL,tagCol7=NULL +sql_error alter table $tbj set tag tagCol1=true,tagCol2=-10,tagcol3=-100, tagcol4=-1000,tagcol5=NULL,tagCol6=NULL,tagCol7=NULL + +sql alter table $tbj set tag tagCol8 = 8 + +sql select * from $mt where tagCol4 = -1000 +if $rows != 1 then + return -1 +endi + +sql select * from $mt where tagCol8 = 8 +if $rows != 1 then + return -1 +endi + + system sh/exec.sh -n dnode1 -s stop -x SIGINT From a84a849ef760cbb81a67c81e0c85a95277d46c75 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 27 Nov 2024 09:12:17 +0800 Subject: [PATCH 20/25] add test case --- source/dnode/vnode/src/meta/metaTable.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index e6ad1d03fc..2a4b2baf45 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -2334,6 +2334,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA metaError("meta/table: failed to get tb db, uid:%" PRId64, uid); tdbTbcClose(pUidIdxc); tdbTbcClose(pTbDbc); + return terrno = TSDB_CODE_INVALID_MSG; } if ((ctbEntry.pBuf = taosMemoryMalloc(nData)) == NULL) { From 221eac50caa75e3645b13648bd5b9eef65fd25bd Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 27 Nov 2024 09:28:01 +0800 Subject: [PATCH 21/25] refactor code --- source/dnode/vnode/src/meta/metaTable.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 2a4b2baf45..8256b5e402 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -2023,7 +2023,6 @@ static int metaUpdateTableMultiTagVal(SMeta *pMeta, int64_t version, SVAlterTbRe const void *pData = NULL; int nData = 0; SHashObj *pTagTable = NULL; - SArray *updateTagColumnIds = NULL; // search name index ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal); @@ -2128,12 +2127,11 @@ static int metaUpdateTableMultiTagVal(SMeta *pMeta, int64_t version, SVAlterTbRe goto _err; } } - int32_t nUpdateTagVal = taosHashGetSize(pTagTable); - updateTagColumnIds = taosArrayInit(nUpdateTagVal, sizeof(int32_t)); SSchemaWrapper *pTagSchema = &stbEntry.stbEntry.schemaTag; SSchema *pColumn = NULL; int32_t iCol = 0; + int32_t count = 0; for (;;) { pColumn = NULL; @@ -2141,14 +2139,11 @@ static int metaUpdateTableMultiTagVal(SMeta *pMeta, int64_t version, SVAlterTbRe if (iCol >= pTagSchema->nCols) break; pColumn = &pTagSchema->pSchema[iCol]; if (taosHashGet(pTagTable, pColumn->name, strlen(pColumn->name)) != NULL) { - if (taosArrayPush(updateTagColumnIds, &iCol) == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } + count++; } iCol++; } - if (taosArrayGetSize(updateTagColumnIds) != nUpdateTagVal) { + if (count != taosHashGetSize(pTagTable)) { terrno = TSDB_CODE_VND_COL_NOT_EXISTS; goto _err; } @@ -2253,7 +2248,6 @@ static int metaUpdateTableMultiTagVal(SMeta *pMeta, int64_t version, SVAlterTbRe tdbTbcClose(pTbDbc); tdbTbcClose(pUidIdxc); taosHashCleanup(pTagTable); - taosArrayDestroy(updateTagColumnIds); return 0; _err: @@ -2264,7 +2258,6 @@ _err: tdbTbcClose(pTbDbc); tdbTbcClose(pUidIdxc); taosHashCleanup(pTagTable); - taosArrayDestroy(updateTagColumnIds); return -1; } static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) { From 0378062c4ecbb430829e9c30c0559174f50a3186 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 27 Nov 2024 15:00:47 +0800 Subject: [PATCH 22/25] doc: update doc --- docs/en/14-reference/03-taos-sql/03-table.md | 2 +- docs/zh/14-reference/03-taos-sql/03-table.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/14-reference/03-taos-sql/03-table.md b/docs/en/14-reference/03-taos-sql/03-table.md index 561f479aa3..e6a704a974 100644 --- a/docs/en/14-reference/03-taos-sql/03-table.md +++ b/docs/en/14-reference/03-taos-sql/03-table.md @@ -161,7 +161,7 @@ ALTER TABLE [db_name.]tb_name alter_table_clause alter_table_clause: { alter_table_options - | SET TAG tag_name = new_tag_value + | SET TAG tag_name = new_tag_value,tag_name2=new_tag2_value... } alter_table_options: diff --git a/docs/zh/14-reference/03-taos-sql/03-table.md b/docs/zh/14-reference/03-taos-sql/03-table.md index 40e2802fcd..4bf1bd5b87 100644 --- a/docs/zh/14-reference/03-taos-sql/03-table.md +++ b/docs/zh/14-reference/03-taos-sql/03-table.md @@ -171,7 +171,7 @@ ALTER TABLE [db_name.]tb_name alter_table_clause alter_table_clause: { alter_table_options - | SET TAG tag_name = new_tag_value + | SET TAG tag_name = new_tag_value,tag_name2=new_tag2_value... } alter_table_options: From 1f96f3ad7229c6d47a57c48ec84b32d6429a9404 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 27 Nov 2024 15:07:59 +0800 Subject: [PATCH 23/25] fix mem leak --- source/client/src/clientRawBlockWrite.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/client/src/clientRawBlockWrite.c b/source/client/src/clientRawBlockWrite.c index 924b1ce202..b209ff2eca 100644 --- a/source/client/src/clientRawBlockWrite.c +++ b/source/client/src/clientRawBlockWrite.c @@ -823,6 +823,9 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) { end: uDebug("alter table return"); + if (vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL) { + taosArrayDestroy(vAlterTbReq.pMultiTag); + } tDecoderClear(&decoder); *pJson = json; } From 6997386455b673a3e8863471a4034868ac19c103 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 27 Nov 2024 15:22:29 +0800 Subject: [PATCH 24/25] support subscribe --- source/client/src/clientRawBlockWrite.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source/client/src/clientRawBlockWrite.c b/source/client/src/clientRawBlockWrite.c index b209ff2eca..08ecf103cd 100644 --- a/source/client/src/clientRawBlockWrite.c +++ b/source/client/src/clientRawBlockWrite.c @@ -772,10 +772,13 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) { cJSON* tags = cJSON_CreateArray(); RAW_NULL_CHECK(tags); for (int32_t i = 0; i < nTags; i++) { + cJSON* member = cJSON_CreateObject(); + RAW_NULL_CHECK(member); + SMultiTagUpateVal* pTagVal = taosArrayGet(vAlterTbReq.pMultiTag, i); cJSON* tagName = cJSON_CreateString(pTagVal->tagName); RAW_NULL_CHECK(tagName); - RAW_FALSE_CHECK(cJSON_AddItemToObject(tags, "colName", tagName)); + RAW_FALSE_CHECK(cJSON_AddItemToObject(member, "colName", tagName)); if (pTagVal->tagType == TSDB_DATA_TYPE_JSON) { uError("processAlterTable isJson false"); @@ -799,12 +802,13 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) { } cJSON* colValue = cJSON_CreateString(buf); RAW_NULL_CHECK(colValue); - RAW_FALSE_CHECK(cJSON_AddItemToObject(tags, "colValue", colValue)); + RAW_FALSE_CHECK(cJSON_AddItemToObject(member, "colValue", colValue)); taosMemoryFree(buf); } cJSON* isNullCJson = cJSON_CreateBool(isNull); RAW_NULL_CHECK(isNullCJson); - RAW_FALSE_CHECK(cJSON_AddItemToObject(tags, "colValueNull", isNullCJson)); + RAW_FALSE_CHECK(cJSON_AddItemToObject(member, "colValueNull", isNullCJson)); + RAW_FALSE_CHECK(cJSON_AddItemToArray(tags, member)); } RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tags", tags)); break; From fcec7c522d692e93fbd2413a755514be99da4dac Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 27 Nov 2024 16:12:57 +0800 Subject: [PATCH 25/25] support subscribe --- source/client/src/clientRawBlockWrite.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/client/src/clientRawBlockWrite.c b/source/client/src/clientRawBlockWrite.c index 08ecf103cd..6331224c3a 100644 --- a/source/client/src/clientRawBlockWrite.c +++ b/source/client/src/clientRawBlockWrite.c @@ -620,7 +620,10 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) { cJSON* type = cJSON_CreateString("alter"); RAW_NULL_CHECK(type); RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "type", type)); - cJSON* tableType = cJSON_CreateString(vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_TAG_VAL ? "child" : "normal"); + cJSON* tableType = cJSON_CreateString(vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_TAG_VAL || + vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL + ? "child" + : "normal"); RAW_NULL_CHECK(tableType); RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tableType", tableType)); cJSON* tableName = cJSON_CreateString(vAlterTbReq.tbName);