diff --git a/source/client/src/clientRawBlockWrite.c b/source/client/src/clientRawBlockWrite.c index 6331224c3a..3a23d38375 100644 --- a/source/client/src/clientRawBlockWrite.c +++ b/source/client/src/clientRawBlockWrite.c @@ -755,9 +755,9 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) { } cJSON* colValue = cJSON_CreateString(buf); + taosMemoryFree(buf); RAW_NULL_CHECK(colValue); RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colValue", colValue)); - taosMemoryFree(buf); } cJSON* isNullCJson = cJSON_CreateBool(isNull); @@ -804,9 +804,9 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) { goto end; } cJSON* colValue = cJSON_CreateString(buf); + taosMemoryFree(buf); RAW_NULL_CHECK(colValue); RAW_FALSE_CHECK(cJSON_AddItemToObject(member, "colValue", colValue)); - taosMemoryFree(buf); } cJSON* isNullCJson = cJSON_CreateBool(isNull); RAW_NULL_CHECK(isNullCJson); diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 8256b5e402..65e520bb4a 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -2215,11 +2215,6 @@ static int metaUpdateTableMultiTagVal(SMeta *pMeta, int64_t version, SVAlterTbRe 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) { @@ -2454,11 +2449,6 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA 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) { diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index e05a399d32..1217618c0a 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -2547,6 +2547,7 @@ SNode* createAlterSingleTagColumnNode(SAstCreateContext* pCtx, SToken* pTagName, pCtx->errCode = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT, (SNode**)&pStmt); CHECK_MAKE_NODE(pStmt); pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_TAG_VAL; + CHECK_NAME(checkColumnName(pCtx, pTagName)); COPY_STRING_FORM_ID_TOKEN(pStmt->colName, pTagName); pStmt->pVal = (SValueNode*)pVal; pStmt->pNodeListTagValue = NULL; diff --git a/tests/script/tsim/tag/change_multi_tag.sim b/tests/script/tsim/tag/change_multi_tag.sim index 30ae1c653a..470b49d4dc 100644 --- a/tests/script/tsim/tag/change_multi_tag.sim +++ b/tests/script/tsim/tag/change_multi_tag.sim @@ -34,15 +34,34 @@ sql create table $ntable (ts timestamp, f int) sql insert into $tb values(now, 1) sql insert into $tb values(now, 1) -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 + +# invalid sql +sql_error alter table $mt set tag tgcol1 = 1, +sql_error alter table $mt set tag , +sql_error alter table $mt set tag tgcol1=10,tagcol2= +#set tag value on supertable +sql_error alter table $mt set tag tgcol1 = 1,tagcol2 = 2, tag3 = 4 +#set normal table value +sql_error alter table $ntable set tag f = 10 +# duplicate tag name +sql_error alter table $tbj set tag tagCol1=1,tagCol1 = 2 +sql_error alter table $tbj set tag tagCol1=1,tagCol5=10, tagCol5=3 +# not exist tag +sql_error alter table $tbj set tag tagNotExist = 1,tagCol1 = 2 +sql_error alter table $tbj set tag tagCol1 = 2, tagNotExist = 1 +sql_error alter table $tbj set tagNotExist = 1 +sql_error alter table $tbj set tagNotExist = NULL, sql_error alter table $tbj set tag tagCol1 = 1, tagCol5="xxxxxxxxxxxxxxxx" +# invalid tag value 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 +# invalid data type + +# escape +sql_error alter table $tbj set tag `tagCol1`=true +sql_error alter table $tbj set tag `tagCol1`=true,`tagCol2`=1,`tagNotExist`=10 +sql_error alter table $tbj set tag `tagCol1`=true,`tagCol2`=1,tagcol1=true + +sql alter table $tbj set tag tagCol1 = 100, tagCol2 = 100 sql select * from $mt where tagCol2 = 100 if $rows != 0 then @@ -180,14 +199,16 @@ if $rows != 1 then endi sql 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 `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 +#set not exist tag and value 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_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