From e6627f6955c5056a80342432d591d26fb1982a40 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 30 Dec 2022 10:02:15 +0800 Subject: [PATCH] fix:json parse error in the end --- source/client/src/clientSml.c | 10 ++++++---- source/client/src/clientSmlJson.c | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index ba154c95bd..689645abc6 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -1267,11 +1267,13 @@ int32_t smlClearForRerun(SSmlHandle *info) { pList = pList->next; } - if (unlikely(info->lines != NULL)) { - uError("SML:0x%" PRIx64 " info->lines != NULL", info->id); - return TSDB_CODE_SML_INVALID_DATA; + if (!info->dataFormat){ + if (unlikely(info->lines != NULL)) { + uError("SML:0x%" PRIx64 " info->lines != NULL", info->id); + return TSDB_CODE_SML_INVALID_DATA; + } + info->lines = (SSmlLineInfo *)taosMemoryCalloc(info->lineNum, sizeof(SSmlLineInfo)); } - info->lines = (SSmlLineInfo *)taosMemoryCalloc(info->lineNum, sizeof(SSmlLineInfo)); memset(&info->preLine, 0, sizeof(SSmlLineInfo)); info->currSTableMeta = NULL; diff --git a/source/client/src/clientSmlJson.c b/source/client/src/clientSmlJson.c index 5d97444622..ef8fe57b8b 100644 --- a/source/client/src/clientSmlJson.c +++ b/source/client/src/clientSmlJson.c @@ -406,7 +406,7 @@ static int32_t smlParseJSONString(SSmlHandle *info, char **start, SSmlLineInfo * }else{ smlJsonParseObj(start, elements, info->offset); } - if(**start == '\0') return TSDB_CODE_SUCCESS; + if(**start == '\0' && elements->measure == NULL) return TSDB_CODE_SUCCESS; SSmlKv kv = {.key = VALUE, .keyLen = VALUE_LEN, .value = elements->cols, .length = (size_t)elements->colsLen}; if (smlParseValue(&kv, &info->msgBuf) != TSDB_CODE_SUCCESS) { @@ -804,7 +804,7 @@ static int32_t smlParseTagsFromJSONExt(SSmlHandle *info, cJSON *tags, SSmlLineIn cnt++; } - SSmlTableInfo *tinfo = (SSmlTableInfo *)nodeListGet(info->childTables, elements->tags, POINTER_BYTES, is_same_child_table_telnet); + SSmlTableInfo *tinfo = (SSmlTableInfo *)nodeListGet(info->childTables, elements, POINTER_BYTES, is_same_child_table_telnet); if (unlikely(tinfo == NULL)) { tinfo = smlBuildTableInfo(1, elements->measure, elements->measureLen); if (unlikely(!tinfo)) { @@ -822,7 +822,10 @@ static int32_t smlParseTagsFromJSONExt(SSmlHandle *info, cJSON *tags, SSmlLineIn } } - nodeListSet(&info->childTables, tags, POINTER_BYTES, tinfo, is_same_child_table_telnet); + SSmlLineInfo *key = (SSmlLineInfo *)taosMemoryMalloc(sizeof(SSmlLineInfo)); + *key = *elements; + tinfo->key = key; + nodeListSet(&info->childTables, key, POINTER_BYTES, tinfo, is_same_child_table_telnet); } if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx; @@ -1054,6 +1057,9 @@ static int32_t smlParseJSONExt(SSmlHandle *info, char *payload) { info->lines = NULL; } ret = smlClearForRerun(info); + if(ret != TSDB_CODE_SUCCESS){ + return ret; + } cJSON *head = (payloadNum == 1 && cJSON_IsObject(info->root)) ? info->root : info->root->child; int cnt = 0; @@ -1103,6 +1109,7 @@ int32_t smlParseJSON(SSmlHandle *info, char *payload) { void* tmp = taosMemoryRealloc(info->lines, payloadNum * sizeof(SSmlLineInfo)); if(tmp != NULL){ info->lines = (SSmlLineInfo*)tmp; + memset(info->lines + cnt, 0, (payloadNum - cnt) * sizeof(SSmlLineInfo)); } } ret = smlParseJSONString(info, &dataPointStart, info->lines + cnt); @@ -1112,8 +1119,6 @@ int32_t smlParseJSON(SSmlHandle *info, char *payload) { return smlParseJSONExt(info, payload); } - if(*dataPointStart == '\0') break; - if(unlikely(info->reRun)){ cnt = 0; dataPointStart = payload; @@ -1124,6 +1129,8 @@ int32_t smlParseJSON(SSmlHandle *info, char *payload) { } continue; } + + if(*dataPointStart == '\0') break; cnt++; } info->lineNum = cnt;