From 83ae535c010569937f7282b3cb31d9ffca06177b Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 11 Oct 2021 18:04:56 +0800 Subject: [PATCH] support describe JSON NCHAR --- src/client/src/tscLocal.c | 15 +++++++++++++-- src/common/src/ttypes.c | 13 ++++++++++++- src/inc/taos.h | 2 +- src/inc/ttype.h | 2 +- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index c1141898cd..5fd4b9931b 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -85,9 +85,20 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) { pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 1); dst = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 1) * totalNumOfRows + pField->bytes * i; - STR_WITH_MAXSIZE_TO_VARSTR(dst, type, pField->bytes); - + char *postfix = NULL; + if (pSchema[i].type == TSDB_DATA_TYPE_JSON && JSON_TYPE_BINARY){ + postfix = " BINARY"; + + } + else if(pSchema[i].type == TSDB_DATA_TYPE_JSON && JSON_TYPE_NCHAR) { + postfix = " NCHAR"; + } + if(postfix){ + strncpy(varDataVal(dst), postfix, pField->bytes-varDataTLen(dst)); + varDataSetLen(dst, varDataLen(dst) + strlen(postfix)); + } + int32_t bytes = pSchema[i].bytes; if (pSchema[i].type == TSDB_DATA_TYPE_BINARY || (pSchema[i].type == TSDB_DATA_TYPE_JSON && JSON_TYPE_BINARY)){ bytes -= VARSTR_HEADER_SIZE; diff --git a/src/common/src/ttypes.c b/src/common/src/ttypes.c index b3e5ca1078..67ae79b011 100644 --- a/src/common/src/ttypes.c +++ b/src/common/src/ttypes.c @@ -17,6 +17,7 @@ #include "ttype.h" #include "ttokendef.h" #include "tscompression.h" +#include "tglobal.h" const int32_t TYPE_BYTES[16] = { -1, // TSDB_DATA_TYPE_NULL @@ -368,6 +369,16 @@ static void getStatics_nchr(const void *pData, int32_t numOfRow, int64_t *min, i *maxIndex = 0; } +static void getStatics_json(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, + int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) { + if (JSON_TYPE_NCHAR) { + getStatics_nchr(pData, numOfRow, min, max, sum, minIndex, maxIndex, numOfNull); + } + else{ + getStatics_bin(pData, numOfRow, min, max, sum, minIndex, maxIndex, numOfNull); + } +} + tDataTypeDescriptor tDataTypes[16] = { {TSDB_DATA_TYPE_NULL, 6, 1, "NOTYPE", 0, 0, NULL, NULL, NULL}, {TSDB_DATA_TYPE_BOOL, 4, CHAR_BYTES, "BOOL", false, true, tsCompressBool, tsDecompressBool, getStatics_bool}, @@ -384,7 +395,7 @@ tDataTypeDescriptor tDataTypes[16] = { {TSDB_DATA_TYPE_USMALLINT, 17, SHORT_BYTES, "SMALLINT UNSIGNED", 0, UINT16_MAX, tsCompressSmallint, tsDecompressSmallint, getStatics_u16}, {TSDB_DATA_TYPE_UINT, 12, INT_BYTES, "INT UNSIGNED", 0, UINT32_MAX, tsCompressInt, tsDecompressInt, getStatics_u32}, {TSDB_DATA_TYPE_UBIGINT, 15, LONG_BYTES, "BIGINT UNSIGNED", 0, UINT64_MAX, tsCompressBigint, tsDecompressBigint, getStatics_u64}, - {TSDB_DATA_TYPE_JSON, 4, 0, "JSON", 0, 0, tsCompressString, tsDecompressString, getStatics_nchr}, + {TSDB_DATA_TYPE_JSON, 4, 0, "JSON", 0, 0, tsCompressString, tsDecompressString, getStatics_json}, }; char tTokenTypeSwitcher[13] = { diff --git a/src/inc/taos.h b/src/inc/taos.h index bfa78ff4c2..0ed2a04d8d 100644 --- a/src/inc/taos.h +++ b/src/inc/taos.h @@ -46,7 +46,7 @@ typedef void **TAOS_ROW; #define TSDB_DATA_TYPE_USMALLINT 12 // 2 bytes #define TSDB_DATA_TYPE_UINT 13 // 4 bytes #define TSDB_DATA_TYPE_UBIGINT 14 // 8 bytes -#define TSDB_DATA_TYPE_JSON 15 +#define TSDB_DATA_TYPE_JSON 15 // json string typedef enum { TSDB_OPTION_LOCALE, diff --git a/src/inc/ttype.h b/src/inc/ttype.h index e42752c1b3..e73e4499c8 100644 --- a/src/inc/ttype.h +++ b/src/inc/ttype.h @@ -189,7 +189,7 @@ typedef struct tDataTypeDescriptor { int (*decompFunc)(const char *const input, int compressedSize, const int nelements, char *const output, int outputSize, char algorithm, char *const buffer, int bufferSize); void (*statisFunc)(const void *pData, int32_t numofrow, int64_t *min, int64_t *max, int64_t *sum, - int16_t *minindex, int16_t *maxindex, int16_t *numofnull); + int16_t *minindex, int16_t *maxindex, int16_t *numofnull); } tDataTypeDescriptor; extern tDataTypeDescriptor tDataTypes[16]; -- GitLab