From 3d60242687d13218313fc521c84d62e07de61e01 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 18 Oct 2021 17:54:33 +0800 Subject: [PATCH] change json null data format --- src/client/src/tscUtil.c | 9 +++++---- tests/pytest/stable/json_tag.py | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 1776cc9a05..2f88a05c5a 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -699,7 +699,7 @@ static void setResRawPtrImpl(SSqlRes* pRes, SInternalField* pInfo, int32_t i, bo if (isNull(p, TSDB_DATA_TYPE_NCHAR) && pInfo->field.type == TSDB_DATA_TYPE_NCHAR) { memcpy(dst, p, varDataTLen(p)); - } else if(isNull(p, TSDB_DATA_TYPE_JSON && pInfo->field.type == TSDB_DATA_TYPE_JSON)) { + } else if(isNull(p, TSDB_DATA_TYPE_JSON) && pInfo->field.type == TSDB_DATA_TYPE_JSON) { memcpy(dst, p, varDataTLen(p)); }else if (varDataLen(p) > 0) { int32_t length = taosUcs4ToMbs(varDataVal(p), varDataLen(p), varDataVal(dst)); @@ -5158,11 +5158,12 @@ void getJsonTagValueElment(STable* data, char* key, int32_t keyLen, char* dst, i return; } - char out[TSDB_MAX_TAGS_LEN] = {0}; + char out[20] = {0}; char* realData = POINTER_SHIFT(result, CHAR_BYTES); if(*(char*)result == TSDB_DATA_TYPE_NCHAR) { - assert(varDataTLen(result) <= TSDB_MAX_TAGS_LEN); - varDataCopy(out, result); + assert(varDataTLen(realData) <= bytes); + varDataCopy(dst, realData); + return; }else if (*(char*)result == TSDB_DATA_TYPE_DOUBLE) { double jsonVd = *(double*)(realData); sprintf(varDataVal(out), "%.9lf", jsonVd); diff --git a/tests/pytest/stable/json_tag.py b/tests/pytest/stable/json_tag.py index 72528e2d68..79e4168792 100644 --- a/tests/pytest/stable/json_tag.py +++ b/tests/pytest/stable/json_tag.py @@ -176,19 +176,19 @@ class TDTestCase: tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_5 using db_json_tag_test.jsons1 tags('\t')") tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_6 using db_json_tag_test.jsons1 tags('')") tdSql.query("select jtag from db_json_tag_test.jsons1_6") - tdSql.checkData(0, 0, "") + tdSql.checkData(0, 0, None) tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_7 using db_json_tag_test.jsons1 tags('{}')") tdSql.query("select jtag from db_json_tag_test.jsons1_7") - tdSql.checkData(0, 0, "") + tdSql.checkData(0, 0, None) tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_8 using db_json_tag_test.jsons1 tags('null')") tdSql.query("select jtag from db_json_tag_test.jsons1_8") - tdSql.checkData(0, 0, "") + tdSql.checkData(0, 0, None) tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_9 using db_json_tag_test.jsons1 tags('{\"\":4, \"time\":null}')") tdSql.query("select jtag from db_json_tag_test.jsons1_9") - tdSql.checkData(0, 0, "") + tdSql.checkData(0, 0, None) tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_10 using db_json_tag_test.jsons1 tags('{\"k1\":\"\",\"k1\":\"v1\",\"k2\":true,\"k3\":false,\"k4\":55}')") tdSql.query("select jtag from db_json_tag_test.jsons1_10") -- GitLab