diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 9f557f5529e03ee504aea2c30cc6bfac113a06aa..d90a19da279170c89c180d46f2ed69828d788678 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4452,6 +4452,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { tVariantList* pVarList = pAlterSQL->varList; tVariant* pTagName = &pVarList->a[0].pVar; + int16_t numOfTags = tscGetNumOfTags(pTableMeta); SColumnIndex columnIndex = COLUMN_INDEX_INITIALIZER; SSQLToken name = {.type = TK_STRING, .z = pTagName->pz, .n = pTagName->nLen}; @@ -4475,8 +4476,10 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { (pVarList->a[1].pVar.nLen + VARSTR_HEADER_SIZE) > pTagsSchema->bytes) { return invalidSqlErrMsg(pQueryInfo->msg, msg14); } - - int32_t size = sizeof(SUpdateTableTagValMsg) + pTagsSchema->bytes + TSDB_EXTRA_PAYLOAD_SIZE; + + int32_t schemaLen = sizeof(STColumn) * numOfTags; + int32_t size = sizeof(SUpdateTableTagValMsg) + pTagsSchema->bytes + schemaLen + TSDB_EXTRA_PAYLOAD_SIZE; + if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { tscError("%p failed to malloc for alter table msg", pSql); return TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -4487,11 +4490,25 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { pUpdateMsg->tid = htonl(pTableMeta->sid); pUpdateMsg->uid = htobe64(pTableMeta->uid); pUpdateMsg->colId = htons(pTagsSchema->colId); - pUpdateMsg->type = htons(pTagsSchema->type); - pUpdateMsg->bytes = htons(pTagsSchema->bytes); pUpdateMsg->tversion = htons(pTableMeta->tversion); - - tVariantDump(&pVarList->a[1].pVar, pUpdateMsg->data, pTagsSchema->type, true); + pUpdateMsg->numOfTags = htons(numOfTags); + pUpdateMsg->schemaLen = htonl(schemaLen); + + // the schema is located after the msg body, then followed by true tag value + char* d = pUpdateMsg->data; + SSchema* pTagCols = tscGetTableTagSchema(pTableMeta); + for (int i = 0; i < numOfTags; ++i) { + STColumn* pCol = (STColumn*) d; + pCol->colId = htons(pTagCols[i].colId); + pCol->bytes = htons(pTagCols[i].bytes); + pCol->type = pTagCols[i].type; + pCol->offset = 0; + + d += sizeof(STColumn); + } + + // copy the tag value to msg body + tVariantDump(&pVarList->a[1].pVar, pUpdateMsg->data + schemaLen, pTagsSchema->type, true); int32_t len = 0; if (pTagsSchema->type != TSDB_DATA_TYPE_BINARY && pTagsSchema->type != TSDB_DATA_TYPE_NCHAR) { @@ -4502,7 +4519,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { pUpdateMsg->tagValLen = htonl(len); // length may be changed after dump data - int32_t total = sizeof(SUpdateTableTagValMsg) + len; + int32_t total = sizeof(SUpdateTableTagValMsg) + len + schemaLen; pUpdateMsg->head.contLen = htonl(total); } else if (pAlterSQL->type == TSDB_ALTER_TABLE_ADD_COLUMN) { diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index cb25242d27d3f8e50af643df3c447c7aaae76484..6155f08e76646ff887a51be60a0bfa500a6f873c 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -285,9 +285,9 @@ typedef struct { int32_t tid; int16_t tversion; int16_t colId; - int16_t type; - int16_t bytes; int32_t tagValLen; + int16_t numOfTags; + int32_t schemaLen; char data[]; } SUpdateTableTagValMsg; diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index dafc7dbb1bcb2eab6fa5f8f6587cc322879512d1..4d66f12178dd87b1dd870537e3fd5e64d73f19e3 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -310,7 +310,9 @@ int tsdbUpdateTagValue(TSDB_REPO_T *repo, SUpdateTableTagValMsg *pMsg) { tsdbRemoveTableFromIndex(pMeta, pTable); } // TODO: remove table from index if it is the first column of tag - tdSetKVRowDataOfCol(&pTable->tagVal, htons(pMsg->colId), htons(pMsg->type), pMsg->data); + // TODO: convert the tag schema from client, and then extract the type and bytes from schema according to colId + +// tdSetKVRowDataOfCol(&pTable->tagVal, htons(pMsg->colId), htons(pMsg->type), pMsg->data); if (schemaColAt(pTagSchema, DEFAULT_TAG_INDEX_COLUMN)->colId == htons(pMsg->colId)) { tsdbAddTableIntoIndex(pMeta, pTable); }