fix:give error if col is same in schemless & fix json parse error in TD-22903
This commit is contained in:
parent
3bfd156616
commit
4827c25a61
|
@ -190,7 +190,7 @@ typedef struct {
|
||||||
//
|
//
|
||||||
SArray *preLineTagKV;
|
SArray *preLineTagKV;
|
||||||
SArray *maxTagKVs;
|
SArray *maxTagKVs;
|
||||||
SArray *preLineColKV;
|
SArray *masColKVs;
|
||||||
|
|
||||||
SSmlLineInfo preLine;
|
SSmlLineInfo preLine;
|
||||||
STableMeta *currSTableMeta;
|
STableMeta *currSTableMeta;
|
||||||
|
|
|
@ -817,7 +817,6 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
|
||||||
if (i < pTableMeta->tableInfo.numOfColumns) {
|
if (i < pTableMeta->tableInfo.numOfColumns) {
|
||||||
taosArrayPush(pColumns, &field);
|
taosArrayPush(pColumns, &field);
|
||||||
} else {
|
} else {
|
||||||
uError("SML:0x%" PRIx64 "field name:%s, bytes:%d", info->id, field.name, field.bytes);
|
|
||||||
taosArrayPush(pTags, &field);
|
taosArrayPush(pTags, &field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1074,7 +1073,6 @@ void smlDestroyInfo(SSmlHandle *info) {
|
||||||
taosArrayDestroy(info->valueJsonArray);
|
taosArrayDestroy(info->valueJsonArray);
|
||||||
|
|
||||||
taosArrayDestroy(info->preLineTagKV);
|
taosArrayDestroy(info->preLineTagKV);
|
||||||
taosArrayDestroy(info->preLineColKV);
|
|
||||||
|
|
||||||
if (!info->dataFormat) {
|
if (!info->dataFormat) {
|
||||||
for (int i = 0; i < info->lineNum; i++) {
|
for (int i = 0; i < info->lineNum; i++) {
|
||||||
|
@ -1117,7 +1115,6 @@ SSmlHandle *smlBuildSmlInfo(TAOS *taos) {
|
||||||
info->tagJsonArray = taosArrayInit(8, POINTER_BYTES);
|
info->tagJsonArray = taosArrayInit(8, POINTER_BYTES);
|
||||||
info->valueJsonArray = taosArrayInit(8, POINTER_BYTES);
|
info->valueJsonArray = taosArrayInit(8, POINTER_BYTES);
|
||||||
info->preLineTagKV = taosArrayInit(8, sizeof(SSmlKv));
|
info->preLineTagKV = taosArrayInit(8, sizeof(SSmlKv));
|
||||||
info->preLineColKV = taosArrayInit(8, sizeof(SSmlKv));
|
|
||||||
|
|
||||||
if (NULL == info->pVgHash || NULL == info->childTables || NULL == info->superTables) {
|
if (NULL == info->pVgHash || NULL == info->childTables || NULL == info->superTables) {
|
||||||
uError("create SSmlHandle failed");
|
uError("create SSmlHandle failed");
|
||||||
|
|
|
@ -686,7 +686,7 @@ static int32_t smlParseTagsFromJSON(SSmlHandle *info, cJSON *tags, SSmlLineInfo
|
||||||
if (info->dataFormat) {
|
if (info->dataFormat) {
|
||||||
if (unlikely(!isSameMeasure)) {
|
if (unlikely(!isSameMeasure)) {
|
||||||
SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
|
SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
|
||||||
SSmlSTableMeta *sMeta = NULL;
|
SSmlSTableMeta *sMeta = NULL;
|
||||||
if (unlikely(tmp == NULL)) {
|
if (unlikely(tmp == NULL)) {
|
||||||
STableMeta *pTableMeta = smlGetMeta(info, elements->measure, elements->measureLen);
|
STableMeta *pTableMeta = smlGetMeta(info, elements->measure, elements->measureLen);
|
||||||
if (pTableMeta == NULL) {
|
if (pTableMeta == NULL) {
|
||||||
|
@ -697,12 +697,12 @@ static int32_t smlParseTagsFromJSON(SSmlHandle *info, cJSON *tags, SSmlLineInfo
|
||||||
sMeta = smlBuildSTableMeta(info->dataFormat);
|
sMeta = smlBuildSTableMeta(info->dataFormat);
|
||||||
sMeta->tableMeta = pTableMeta;
|
sMeta->tableMeta = pTableMeta;
|
||||||
taosHashPut(info->superTables, elements->measure, elements->measureLen, &sMeta, POINTER_BYTES);
|
taosHashPut(info->superTables, elements->measure, elements->measureLen, &sMeta, POINTER_BYTES);
|
||||||
tmp = &sMeta;
|
|
||||||
for(int i = pTableMeta->tableInfo.numOfColumns; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++){
|
for(int i = pTableMeta->tableInfo.numOfColumns; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++){
|
||||||
SSchema *tag = pTableMeta->schema + i;
|
SSchema *tag = pTableMeta->schema + i;
|
||||||
SSmlKv kv = {.key = tag->name, .keyLen = strlen(tag->name), .type = tag->type, .length = (tag->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE };
|
SSmlKv kv = {.key = tag->name, .keyLen = strlen(tag->name), .type = tag->type, .length = (tag->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE };
|
||||||
taosArrayPush(sMeta->tags, &kv);
|
taosArrayPush(sMeta->tags, &kv);
|
||||||
}
|
}
|
||||||
|
tmp = &sMeta;
|
||||||
}
|
}
|
||||||
info->currSTableMeta = (*tmp)->tableMeta;
|
info->currSTableMeta = (*tmp)->tableMeta;
|
||||||
info->maxTagKVs = (*tmp)->tags;
|
info->maxTagKVs = (*tmp)->tags;
|
||||||
|
|
|
@ -149,6 +149,7 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
|
||||||
SSmlSTableMeta **tmp =
|
SSmlSTableMeta **tmp =
|
||||||
(SSmlSTableMeta **)taosHashGet(info->superTables, currElement->measure, currElement->measureLen);
|
(SSmlSTableMeta **)taosHashGet(info->superTables, currElement->measure, currElement->measureLen);
|
||||||
|
|
||||||
|
SSmlSTableMeta *sMeta = NULL;
|
||||||
if (unlikely(tmp == NULL)) {
|
if (unlikely(tmp == NULL)) {
|
||||||
STableMeta *pTableMeta = smlGetMeta(info, currElement->measure, currElement->measureLen);
|
STableMeta *pTableMeta = smlGetMeta(info, currElement->measure, currElement->measureLen);
|
||||||
if (pTableMeta == NULL) {
|
if (pTableMeta == NULL) {
|
||||||
|
@ -156,16 +157,15 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
|
||||||
info->reRun = true;
|
info->reRun = true;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
SSmlSTableMeta *sMeta = smlBuildSTableMeta(info->dataFormat);
|
sMeta = smlBuildSTableMeta(info->dataFormat);
|
||||||
sMeta->tableMeta = pTableMeta;
|
sMeta->tableMeta = pTableMeta;
|
||||||
taosHashPut(info->superTables, currElement->measure, currElement->measureLen, &sMeta, POINTER_BYTES);
|
taosHashPut(info->superTables, currElement->measure, currElement->measureLen, &sMeta, POINTER_BYTES);
|
||||||
tmp = &sMeta;
|
|
||||||
|
|
||||||
for(int i = pTableMeta->tableInfo.numOfColumns; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++){
|
for(int i = pTableMeta->tableInfo.numOfColumns; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++){
|
||||||
SSchema *tag = pTableMeta->schema + i;
|
SSchema *tag = pTableMeta->schema + i;
|
||||||
SSmlKv kv = {.key = tag->name, .keyLen = strlen(tag->name), .type = tag->type, .length = (tag->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE };
|
SSmlKv kv = {.key = tag->name, .keyLen = strlen(tag->name), .type = tag->type, .length = (tag->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE };
|
||||||
taosArrayPush(sMeta->tags, &kv);
|
taosArrayPush(sMeta->tags, &kv);
|
||||||
}
|
}
|
||||||
|
tmp = &sMeta;
|
||||||
}
|
}
|
||||||
info->currSTableMeta = (*tmp)->tableMeta;
|
info->currSTableMeta = (*tmp)->tableMeta;
|
||||||
info->maxTagKVs = (*tmp)->tags;
|
info->maxTagKVs = (*tmp)->tags;
|
||||||
|
@ -305,9 +305,6 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
|
||||||
static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLineInfo *currElement, bool isSameMeasure,
|
static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLineInfo *currElement, bool isSameMeasure,
|
||||||
bool isSameCTable) {
|
bool isSameCTable) {
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
SArray *preLineKV = info->preLineColKV;
|
|
||||||
bool isSuperKVInit = true;
|
|
||||||
SArray *superKV = NULL;
|
|
||||||
if (info->dataFormat) {
|
if (info->dataFormat) {
|
||||||
if (unlikely(!isSameCTable)) {
|
if (unlikely(!isSameCTable)) {
|
||||||
SSmlTableInfo **oneTable =
|
SSmlTableInfo **oneTable =
|
||||||
|
@ -322,7 +319,6 @@ static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
|
||||||
if (unlikely(!isSameMeasure)) {
|
if (unlikely(!isSameMeasure)) {
|
||||||
SSmlSTableMeta **tmp =
|
SSmlSTableMeta **tmp =
|
||||||
(SSmlSTableMeta **)taosHashGet(info->superTables, currElement->measure, currElement->measureLen);
|
(SSmlSTableMeta **)taosHashGet(info->superTables, currElement->measure, currElement->measureLen);
|
||||||
SSmlSTableMeta *sMeta = NULL;
|
|
||||||
if (unlikely(tmp == NULL)) {
|
if (unlikely(tmp == NULL)) {
|
||||||
STableMeta *pTableMeta = smlGetMeta(info, currElement->measure, currElement->measureLen);
|
STableMeta *pTableMeta = smlGetMeta(info, currElement->measure, currElement->measureLen);
|
||||||
if (pTableMeta == NULL) {
|
if (pTableMeta == NULL) {
|
||||||
|
@ -330,17 +326,23 @@ static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
|
||||||
info->reRun = true;
|
info->reRun = true;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
sMeta = smlBuildSTableMeta(info->dataFormat);
|
*tmp = smlBuildSTableMeta(info->dataFormat);
|
||||||
sMeta->tableMeta = pTableMeta;
|
(*tmp)->tableMeta = pTableMeta;
|
||||||
taosHashPut(info->superTables, currElement->measure, currElement->measureLen, &sMeta, POINTER_BYTES);
|
taosHashPut(info->superTables, currElement->measure, currElement->measureLen, tmp, POINTER_BYTES);
|
||||||
tmp = &sMeta;
|
|
||||||
|
for(int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++){
|
||||||
|
SSchema *tag = pTableMeta->schema + i;
|
||||||
|
SSmlKv kv = {.key = tag->name, .keyLen = strlen(tag->name), .type = tag->type };
|
||||||
|
if(tag->type == TSDB_DATA_TYPE_NCHAR){
|
||||||
|
kv.length = (tag->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
|
||||||
|
}else if(tag->type == TSDB_DATA_TYPE_BINARY){
|
||||||
|
kv.length = tag->bytes - VARSTR_HEADER_SIZE;
|
||||||
|
}
|
||||||
|
taosArrayPush((*tmp)->cols, &kv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
info->currSTableMeta = (*tmp)->tableMeta;
|
info->currSTableMeta = (*tmp)->tableMeta;
|
||||||
superKV = (*tmp)->cols;
|
info->masColKVs = (*tmp)->cols;
|
||||||
if (unlikely(taosArrayGetSize(superKV) == 0)) {
|
|
||||||
isSuperKVInit = false;
|
|
||||||
}
|
|
||||||
taosArrayClear(preLineKV);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,69 +441,26 @@ static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
|
||||||
info->reRun = true;
|
info->reRun = true;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
if (cnt >= taosArrayGetSize(info->masColKVs)) {
|
||||||
|
info->dataFormat = false;
|
||||||
|
info->reRun = true;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->masColKVs, cnt);
|
||||||
|
if (kv.type != maxKV->type) {
|
||||||
|
info->dataFormat = false;
|
||||||
|
info->reRun = true;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
if (unlikely(!IS_SAME_KEY)) {
|
||||||
|
info->dataFormat = false;
|
||||||
|
info->reRun = true;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
if (isSameMeasure) {
|
if (unlikely(IS_VAR_DATA_TYPE(kv.type) && kv.length > maxKV->length)) {
|
||||||
if (cnt >= taosArrayGetSize(preLineKV)) {
|
maxKV->length = kv.length;
|
||||||
info->dataFormat = false;
|
info->needModifySchema = true;
|
||||||
info->reRun = true;
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
SSmlKv *maxKV = (SSmlKv *)taosArrayGet(preLineKV, cnt);
|
|
||||||
if (kv.type != maxKV->type) {
|
|
||||||
info->dataFormat = false;
|
|
||||||
info->reRun = true;
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unlikely(IS_VAR_DATA_TYPE(kv.type) && kv.length > maxKV->length)) {
|
|
||||||
maxKV->length = kv.length;
|
|
||||||
SSmlSTableMeta **tableMeta =
|
|
||||||
(SSmlSTableMeta **)taosHashGet(info->superTables, currElement->measure, currElement->measureLen);
|
|
||||||
if (unlikely(NULL == tableMeta)) {
|
|
||||||
uError("SML:0x%" PRIx64 " NULL == tableMeta", info->id);
|
|
||||||
return TSDB_CODE_SML_INTERNAL_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSmlKv *oldKV = (SSmlKv *)taosArrayGet((*tableMeta)->cols, cnt);
|
|
||||||
oldKV->length = kv.length;
|
|
||||||
info->needModifySchema = true;
|
|
||||||
}
|
|
||||||
if (unlikely(!IS_SAME_KEY)) {
|
|
||||||
info->dataFormat = false;
|
|
||||||
info->reRun = true;
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isSuperKVInit) {
|
|
||||||
if (unlikely(cnt >= taosArrayGetSize(superKV))) {
|
|
||||||
info->dataFormat = false;
|
|
||||||
info->reRun = true;
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
SSmlKv *maxKV = (SSmlKv *)taosArrayGet(superKV, cnt);
|
|
||||||
if (unlikely(kv.type != maxKV->type)) {
|
|
||||||
info->dataFormat = false;
|
|
||||||
info->reRun = true;
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IS_VAR_DATA_TYPE(kv.type)) {
|
|
||||||
if (kv.length > maxKV->length) {
|
|
||||||
maxKV->length = kv.length;
|
|
||||||
} else {
|
|
||||||
kv.length = maxKV->length;
|
|
||||||
}
|
|
||||||
info->needModifySchema = true;
|
|
||||||
}
|
|
||||||
if (unlikely(!IS_SAME_KEY)) {
|
|
||||||
info->dataFormat = false;
|
|
||||||
info->reRun = true;
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
taosArrayPush(superKV, &kv);
|
|
||||||
}
|
|
||||||
taosArrayPush(preLineKV, &kv);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (currElement->colArray == NULL) {
|
if (currElement->colArray == NULL) {
|
||||||
|
|
|
@ -82,7 +82,7 @@ static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SS
|
||||||
if (info->dataFormat) {
|
if (info->dataFormat) {
|
||||||
if (!isSameMeasure) {
|
if (!isSameMeasure) {
|
||||||
SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
|
SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
|
||||||
SSmlSTableMeta * sMeta = NULL;
|
SSmlSTableMeta *sMeta = NULL;
|
||||||
if (unlikely(tmp == NULL)) {
|
if (unlikely(tmp == NULL)) {
|
||||||
STableMeta *pTableMeta = smlGetMeta(info, elements->measure, elements->measureLen);
|
STableMeta *pTableMeta = smlGetMeta(info, elements->measure, elements->measureLen);
|
||||||
if (pTableMeta == NULL) {
|
if (pTableMeta == NULL) {
|
||||||
|
@ -93,12 +93,12 @@ static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SS
|
||||||
sMeta = smlBuildSTableMeta(info->dataFormat);
|
sMeta = smlBuildSTableMeta(info->dataFormat);
|
||||||
sMeta->tableMeta = pTableMeta;
|
sMeta->tableMeta = pTableMeta;
|
||||||
taosHashPut(info->superTables, elements->measure, elements->measureLen, &sMeta, POINTER_BYTES);
|
taosHashPut(info->superTables, elements->measure, elements->measureLen, &sMeta, POINTER_BYTES);
|
||||||
tmp = &sMeta;
|
|
||||||
for(int i = pTableMeta->tableInfo.numOfColumns; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++){
|
for(int i = pTableMeta->tableInfo.numOfColumns; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++){
|
||||||
SSchema *tag = pTableMeta->schema + i;
|
SSchema *tag = pTableMeta->schema + i;
|
||||||
SSmlKv kv = {.key = tag->name, .keyLen = strlen(tag->name), .type = tag->type, .length = (tag->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE };
|
SSmlKv kv = {.key = tag->name, .keyLen = strlen(tag->name), .type = tag->type, .length = (tag->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE };
|
||||||
taosArrayPush(sMeta->tags, &kv);
|
taosArrayPush(sMeta->tags, &kv);
|
||||||
}
|
}
|
||||||
|
tmp = &sMeta;
|
||||||
}
|
}
|
||||||
info->currSTableMeta = (*tmp)->tableMeta;
|
info->currSTableMeta = (*tmp)->tableMeta;
|
||||||
info->maxTagKVs = (*tmp)->tags;
|
info->maxTagKVs = (*tmp)->tags;
|
||||||
|
|
Loading…
Reference in New Issue