提交 5caf1148 编写于 作者: wmmhello's avatar wmmhello

fix:error in sml meta change

上级 75e42d92
...@@ -310,8 +310,11 @@ static int32_t getBytes(uint8_t type, int32_t length){ ...@@ -310,8 +310,11 @@ static int32_t getBytes(uint8_t type, int32_t length){
} }
} }
static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SSmlSTableMeta *sTableData, //static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SSmlSTableMeta *sTableData,
int32_t colVer, int32_t tagVer, int8_t source, uint64_t suid){ // int32_t colVer, int32_t tagVer, int8_t source, uint64_t suid){
static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SSmlSTableMeta *sTableData,
STableMeta *pTableMeta, ESchemaAction action){
SRequestObj* pRequest = NULL; SRequestObj* pRequest = NULL;
SMCreateStbReq pReq = {0}; SMCreateStbReq pReq = {0};
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
...@@ -327,43 +330,81 @@ static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SSmlSTableMeta *sT ...@@ -327,43 +330,81 @@ static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SSmlSTableMeta *sT
goto end; goto end;
} }
pReq.colVer = colVer; if (action == SCHEMA_ACTION_NULL){
pReq.tagVer = tagVer; pReq.colVer = 1;
pReq.source = source; pReq.tagVer = 1;
pReq.suid = 0;
pReq.source = TD_REQ_FROM_APP;
} else if (action == SCHEMA_ACTION_TAG){
pReq.colVer = pTableMeta->sversion;
pReq.tagVer = pTableMeta->tversion + 1;
pReq.suid = pTableMeta->uid;
pReq.source = TD_REQ_FROM_TAOX;
} else if (action == SCHEMA_ACTION_COLUMN){
pReq.colVer = pTableMeta->sversion + 1;
pReq.tagVer = pTableMeta->tversion;
pReq.suid = pTableMeta->uid;
pReq.source = TD_REQ_FROM_TAOX;
}
pReq.commentLen = -1; pReq.commentLen = -1;
pReq.igExists = true; pReq.igExists = true;
pReq.suid = suid;
tNameExtractFullName(pName, pReq.name); tNameExtractFullName(pName, pReq.name);
pReq.numOfColumns = taosArrayGetSize(sTableData->cols); if(action == SCHEMA_ACTION_NULL || action == SCHEMA_ACTION_COLUMN){
pReq.numOfTags = taosArrayGetSize(sTableData->tags); pReq.numOfColumns = taosArrayGetSize(sTableData->cols);
pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SField));
pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SField)); for (int i = 0; i < pReq.numOfColumns; i++) {
for (int i = 0; i < pReq.numOfColumns; i++) { SSmlKv *kv = (SSmlKv *)taosArrayGetP(sTableData->cols, i);
SSmlKv *kv = (SSmlKv *)taosArrayGetP(sTableData->cols, i); SField field = {0};
SField field = {0}; field.type = kv->type;
field.type = kv->type; field.bytes = getBytes(kv->type, kv->length);
field.bytes = getBytes(kv->type, kv->length); memcpy(field.name, kv->key, kv->keyLen);
memcpy(field.name, kv->key, kv->keyLen); taosArrayPush(pReq.pColumns, &field);
taosArrayPush(pReq.pColumns, &field); }
}else if (action == SCHEMA_ACTION_TAG){
pReq.numOfColumns = pTableMeta->tableInfo.numOfColumns;
pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SField));
for (int i = 0; i < pReq.numOfColumns; i++) {
SSchema *s = &pTableMeta->schema[i];
SField field = {0};
field.type = s->type;
field.bytes = s->bytes;
strcpy(field.name, s->name);
taosArrayPush(pReq.pColumns, &field);
}
} }
if (pReq.numOfTags == 0){ if(action == SCHEMA_ACTION_NULL || action == SCHEMA_ACTION_TAG){
pReq.numOfTags = 1; pReq.numOfTags = taosArrayGetSize(sTableData->tags);
pReq.pTags = taosArrayInit(pReq.numOfTags, sizeof(SField)); if (pReq.numOfTags == 0){
SField field = {0}; pReq.numOfTags = 1;
field.type = TSDB_DATA_TYPE_NCHAR; pReq.pTags = taosArrayInit(pReq.numOfTags, sizeof(SField));
field.bytes = 1; SField field = {0};
strcpy(field.name, tsSmlTagName); field.type = TSDB_DATA_TYPE_NCHAR;
taosArrayPush(pReq.pTags, &field); field.bytes = 1;
}else{ strcpy(field.name, tsSmlTagName);
taosArrayPush(pReq.pTags, &field);
}else{
pReq.pTags = taosArrayInit(pReq.numOfTags, sizeof(SField));
for (int i = 0; i < pReq.numOfTags; i++) {
SSmlKv *kv = (SSmlKv *)taosArrayGetP(sTableData->tags, i);
SField field = {0};
field.type = kv->type;
field.bytes = getBytes(kv->type, kv->length);
memcpy(field.name, kv->key, kv->keyLen);
taosArrayPush(pReq.pTags, &field);
}
}
}else if (action == SCHEMA_ACTION_COLUMN){
pReq.numOfTags = pTableMeta->tableInfo.numOfTags;
pReq.pTags = taosArrayInit(pReq.numOfTags, sizeof(SField)); pReq.pTags = taosArrayInit(pReq.numOfTags, sizeof(SField));
for (int i = 0; i < pReq.numOfTags; i++) { for (int i = 0; i < pReq.numOfTags; i++) {
SSmlKv *kv = (SSmlKv *)taosArrayGetP(sTableData->tags, i); SSchema *s = &pTableMeta->schema[i + pTableMeta->tableInfo.numOfColumns];
SField field = {0}; SField field = {0};
field.type = kv->type; field.type = s->type;
field.bytes = getBytes(kv->type, kv->length); field.bytes = s->bytes;
memcpy(field.name, kv->key, kv->keyLen); strcpy(field.name, s->name);
taosArrayPush(pReq.pTags, &field); taosArrayPush(pReq.pTags, &field);
} }
} }
...@@ -424,7 +465,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) { ...@@ -424,7 +465,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
code = catalogGetSTableMeta(info->pCatalog, &conn, &pName, &pTableMeta); code = catalogGetSTableMeta(info->pCatalog, &conn, &pName, &pTableMeta);
if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_STB_NOT_EXIST) { if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_STB_NOT_EXIST) {
code = smlSendMetaMsg(info, &pName, sTableData, 1, 1, TD_REQ_FROM_APP, 0); code = smlSendMetaMsg(info, &pName, sTableData, NULL, SCHEMA_ACTION_NULL);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
uError("SML:0x%" PRIx64 " smlSendMetaMsg failed. can not create %s", info->id, superTable); uError("SML:0x%" PRIx64 " smlSendMetaMsg failed. can not create %s", info->id, superTable);
goto end; goto end;
...@@ -445,7 +486,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) { ...@@ -445,7 +486,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
goto end; goto end;
} }
if (action == SCHEMA_ACTION_TAG){ if (action == SCHEMA_ACTION_TAG){
code = smlSendMetaMsg(info, &pName, sTableData, pTableMeta->sversion, pTableMeta->tversion + 1, TD_REQ_FROM_TAOX, pTableMeta->uid); code = smlSendMetaMsg(info, &pName, sTableData, pTableMeta, action);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
uError("SML:0x%" PRIx64 " smlSendMetaMsg failed. can not create %s", info->id, superTable); uError("SML:0x%" PRIx64 " smlSendMetaMsg failed. can not create %s", info->id, superTable);
goto end; goto end;
...@@ -468,7 +509,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) { ...@@ -468,7 +509,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
goto end; goto end;
} }
if (action == SCHEMA_ACTION_COLUMN){ if (action == SCHEMA_ACTION_COLUMN){
code = smlSendMetaMsg(info, &pName, sTableData, pTableMeta->sversion + 1, pTableMeta->tversion, TD_REQ_FROM_TAOX, pTableMeta->uid); code = smlSendMetaMsg(info, &pName, sTableData, pTableMeta, action);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
uError("SML:0x%" PRIx64 " smlSendMetaMsg failed. can not create %s", info->id, superTable); uError("SML:0x%" PRIx64 " smlSendMetaMsg failed. can not create %s", info->id, superTable);
goto end; goto end;
......
...@@ -83,6 +83,8 @@ class TDTestCase: ...@@ -83,6 +83,8 @@ class TDTestCase:
tdSql.checkData(1, 3, "web01") tdSql.checkData(1, 3, "web01")
tdSql.checkData(1, 4, "t1") tdSql.checkData(1, 4, "t1")
tdSql.query("select * from macylr")
tdSql.checkRows(2)
return return
def run(self): def run(self):
......
...@@ -1070,6 +1070,36 @@ int sml_16960_Test() { ...@@ -1070,6 +1070,36 @@ int sml_16960_Test() {
return code; return code;
} }
int sml_add_tag_col_Test() {
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
TAOS_RES *pRes = taos_query(taos, "create database if not exists sml_db schemaless 1");
taos_free_result(pRes);
const char *sql[] = {
"macylr,t0=f,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"binaryTagValue\",t8=L\"ncharTagValue\" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"binaryColValue\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000"
};
pRes = taos_query(taos, "use sml_db");
taos_free_result(pRes);
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql) / sizeof(sql[0]), TSDB_SML_LINE_PROTOCOL, 0);
printf("%s result:%s\n", __FUNCTION__, taos_errstr(pRes));
int code = taos_errno(pRes);
taos_free_result(pRes);
if (code) return code;
const char *sql1[] = {
"macylr,id=macylr_17875_1804,t0=f,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"binaryTagValue\",t8=L\"ncharTagValue\",t11=127i8,t10=L\"ncharTagValue\" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"binaryColValue\",c8=L\"ncharColValue\",c9=7u64,c11=L\"ncharColValue\",c10=f 1626006833639000000"
};
pRes = taos_schemaless_insert(taos, (char **)sql1, sizeof(sql1) / sizeof(sql1[0]), TSDB_SML_LINE_PROTOCOL, 0);
printf("%s result:%s\n", __FUNCTION__, taos_errstr(pRes));
code = taos_errno(pRes);
taos_free_result(pRes);
return code;
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
int ret = 0; int ret = 0;
ret = smlProcess_influx_Test(); ret = smlProcess_influx_Test();
...@@ -1097,5 +1127,7 @@ int main(int argc, char *argv[]) { ...@@ -1097,5 +1127,7 @@ int main(int argc, char *argv[]) {
ret = sml_dup_time_Test(); ret = sml_dup_time_Test();
if(ret) return ret; if(ret) return ret;
ret = sml_16960_Test(); ret = sml_16960_Test();
if(ret) return ret;
ret = sml_add_tag_col_Test();
return ret; return ret;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册