From 8d0798e27300b0e5084c8345ccf4140715908177 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 27 Oct 2021 14:51:08 +0800 Subject: [PATCH] optimize json length --- src/client/src/tscLocal.c | 5 +---- src/client/src/tscUtil.c | 12 +++++++++--- src/inc/taosdef.h | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index 76177f8019..32f43b030d 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -91,13 +91,10 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) { if (pSchema[i].type == TSDB_DATA_TYPE_BINARY){ bytes -= VARSTR_HEADER_SIZE; } - else if(pSchema[i].type == TSDB_DATA_TYPE_NCHAR) { + else if(pSchema[i].type == TSDB_DATA_TYPE_NCHAR || pSchema[i].type == TSDB_DATA_TYPE_JSON) { bytes -= VARSTR_HEADER_SIZE; bytes = bytes / TSDB_NCHAR_SIZE; } - else if(pSchema[i].type == TSDB_DATA_TYPE_JSON) { - bytes = bytes / TSDB_NCHAR_SIZE; - } pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 2); *(int32_t *)(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 2) * totalNumOfRows + pField->bytes * i) = bytes; diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 31759e6b9a..3ae4e53810 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -5180,8 +5180,12 @@ void getJsonTagValueElment(STable* data, char* key, int32_t keyLen, char* dst, i } int32_t length = 0; - taosMbsToUcs4(varDataVal(out), varDataLen(out), varDataVal(dst), bytes - VARSTR_HEADER_SIZE, &length); + + if(!taosMbsToUcs4(varDataVal(out), varDataLen(out), varDataVal(dst), bytes - VARSTR_HEADER_SIZE, &length)){ + tscError("getJsonTagValueElment mbstoucs4 error! length:%d", length); + } varDataSetLen(dst, length); + assert(varDataTLen(dst) <= bytes); } void getJsonTagValueAll(void* data, void* dst, int16_t bytes) { @@ -5192,9 +5196,11 @@ void getJsonTagValueAll(void* data, void* dst, int16_t bytes) { } int32_t length = 0; - taosMbsToUcs4(json, strlen(json), varDataVal(dst), bytes - VARSTR_HEADER_SIZE, &length); + if(!taosMbsToUcs4(json, strlen(json), varDataVal(dst), bytes - VARSTR_HEADER_SIZE, &length)){ + tscError("getJsonTagValueAll mbstoucs4 error! length:%d", length); + } varDataSetLen(dst, length); - assert(length <= bytes); + assert(varDataTLen(dst) <= bytes); tfree(json); } diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index c82b26a640..94aa3686f8 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -50,7 +50,7 @@ extern const int32_t TYPE_BYTES[16]; #define DOUBLE_BYTES sizeof(double) #define POINTER_BYTES sizeof(void *) // 8 by default assert(sizeof(ptrdiff_t) == sizseof(void*) -#define JSON_BYTES (TSDB_MAX_TAGS_LEN) +#define JSON_BYTES (TSDB_MAX_TAGS_LEN + VARSTR_HEADER_SIZE) #define TSDB_KEYSIZE sizeof(TSKEY) #if LINUX -- GitLab