From d5876b045751f49cd304c80d100f0812e76aa00e Mon Sep 17 00:00:00 2001 From: lyh250-666 Date: Fri, 25 Oct 2024 16:59:46 +0800 Subject: [PATCH 01/10] opti:modify bytes for numbers and string --- source/libs/parser/src/parTranslater.c | 16 +++++-------- source/libs/scalar/src/sclvector.c | 30 ++++++++++++------------ tests/script/tsim/scalar/caseWhen.sim | 32 +++++++++++--------------- 3 files changed, 35 insertions(+), 43 deletions(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 636be7c5cc..26151230d3 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -3314,17 +3314,13 @@ static int32_t selectCommonType(SDataType* commonType, const SDataType* newType) commonType->bytes = TMAX(commonType->bytes, newType->bytes); return TSDB_CODE_SUCCESS; } - if (resultType == commonType->type){ - return TSDB_CODE_SUCCESS; - } - if(resultType == newType->type) { - *commonType = *newType; - return TSDB_CODE_SUCCESS; - } commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), TYPE_BYTES[resultType]); - if(resultType == TSDB_DATA_TYPE_VARCHAR && (IS_FLOAT_TYPE(commonType->type) || IS_FLOAT_TYPE(newType->type))) { - commonType->bytes += TYPE_BYTES[TSDB_DATA_TYPE_DOUBLE]; - } + if((resultType == TSDB_DATA_TYPE_VARCHAR || resultType == TSDB_DATA_TYPE_NCHAR) && ( + (IS_FLOAT_TYPE(commonType->type) || IS_FLOAT_TYPE(newType->type)) || + (IS_NUMERIC_TYPE(commonType->type) || IS_NUMERIC_TYPE(newType->type)))) + { + commonType->bytes = TMAX(commonType->bytes, 32); + } commonType->type = resultType; return TSDB_CODE_SUCCESS; diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 54794b9044..487027941c 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -1033,21 +1033,21 @@ int8_t gConvertTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = { int8_t gDisplyTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = { /*NULL BOOL TINY SMAL INT BIGI FLOA DOUB VARC TIME NCHA UTINY USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/ /*NULL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, -1, -1, -1, 8, - /*BOOL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 5, 10, 11, 12, 13, 14, 8, -1, -1, -1, -1, 8, - /*TINY*/ 0, 0, 2, 3, 4, 5, 8, 8, 8, 5, 10, 3, 4, 5, 8, 8, -1, -1, -1, -1, 8, - /*SMAL*/ 0, 0, 0, 3, 4, 5, 8, 8, 8, 5, 10, 3, 4, 5, 8, 8, -1, -1, -1, -1, 8, - /*INT */ 0, 0, 0, 0, 4, 5, 8, 8, 8, 5, 10, 4, 4, 5, 8, 8, -1, -1, -1, -1, 8, - /*BIGI*/ 0, 0, 0, 0, 0, 5, 8, 8, 8, 5, 10, 5, 5, 5, 8, 8, -1, -1, -1, -1, 8, - /*FLOA*/ 0, 0, 0, 0, 0, 0, 6, 7, 8, 8, 10, 8, 8, 8, 8, 8, -1, -1, -1, -1, 8, - /*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 10, 8, 8, 8, 8, 8, -1, -1, -1, -1, 8, - /*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 10, 8, 8, 8, 8, 8, -1, -1, -1, -1, 8, - /*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 10, 5, 5, 5, 8, 8, -1, -1, -1, -1, 8, - /*NCHA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 10, -1, -1, -1, -1, 10, - /*UTINY*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 12, 13, 14, 8, -1, -1, -1, -1, 8, - /*USMA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, 8, -1, -1, -1, -1, 8, - /*UINT*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, 8, -1, -1, -1, -1, 8, - /*UBIG*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 8, -1, -1, -1, -1, 8, - /*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, -1, -1, -1, -1, 8, + /*BOOL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 5, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1, + /*TINY*/ 0, 0, 2, 3, 4, 5, 8, 8, 8, 5, 10, 3, 4, 5, 8, -1, -1, -1, -1, -1, -1, + /*SMAL*/ 0, 0, 0, 3, 4, 5, 8, 8, 8, 5, 10, 3, 4, 5, 8, -1, -1, -1, -1, -1, -1, + /*INT */ 0, 0, 0, 0, 4, 5, 8, 8, 8, 5, 10, 4, 4, 5, 8, -1, -1, -1, -1, -1, -1, + /*BIGI*/ 0, 0, 0, 0, 0, 5, 8, 8, 8, 5, 10, 5, 5, 5, 8, -1, -1, -1, -1, -1, -1, + /*FLOA*/ 0, 0, 0, 0, 0, 0, 6, 7, 8, 8, 10, 8, 8, 8, 8, -1, -1, -1, -1, -1, -1, + /*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 10, 8, 8, 8, 8, -1, -1, -1, -1, -1, -1, + /*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 10, 8, 8, 8, 8, -1, -1, -1, -1, -1, -1, + /*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 10, 5, 5, 5, 8, -1, -1, -1, -1, -1, -1, + /*NCHA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, -1, -1, -1, -1, -1, -1, + /*UTINY*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1, + /*USMA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, -1, -1, -1, -1, -1, -1, + /*UINT*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, -1, -1, -1, -1, -1, -1, + /*UBIG*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, -1, -1, -1, + /*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, /*VARB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, -1, -1, -1, -1, /*DECI*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, /*BLOB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, diff --git a/tests/script/tsim/scalar/caseWhen.sim b/tests/script/tsim/scalar/caseWhen.sim index 67c8ac3673..3bba63aae3 100644 --- a/tests/script/tsim/scalar/caseWhen.sim +++ b/tests/script/tsim/scalar/caseWhen.sim @@ -838,7 +838,7 @@ endi if $data20 != 11 then return -1 endi -if $data30 != 1664176504 then +if $data30 != 1664176504000 then return -1 endi @@ -1130,36 +1130,32 @@ if $data00 != varchar_val then return -1 endi -sql select case when ts > '2022-01-01 00:00:00' then c_varchar else c_geometry end as result from t_test; -if $data00 != varchar_val then +sql select case when 1 then 1234567890987654 else 'abcertyuiojhgfddhjgfcvbn' end; +if $data00 != 1234567890987654 then return -1 endi -sql select case when ts > '2022-01-01 00:00:00' then c_bool else c_geometry end as result from t_test; -if $data00 != true then +sql select case when 0 then 1234567890987654 else 'abcertyuiojhgfddhjgfcvbn' end; +if $data00 != abcertyuiojhgfddhjgfcvbn then return -1 endi -sql select case when 0 then tag_id else c_geometry end as result from t_test; -if $data00 != 16842773 then - return -1 -endi - -sql select case when 0 then tag_id else c_nchar end as result from t_test; +sql select case when 0 then 1234567890987654 else c_nchar end from t_test; if $data00 != 涛思数据 then return -1 endi -sql select case when 0 then tag_id else c_int end as result from t_test; -if $data00 != 123 then - return -1 -endi - -sql select case when 0 then tag_id else c_float end as result from t_test; -if $data00 != 123.449997 then +sql select case when 1 then 1234567890987654 else c_nchar end from t_test; +if $data00 != 1234567890987654 then return -1 endi +sql_error select case when ts > '2022-01-01 00:00:00' then c_varchar else c_geometry end as result from t_test; +sql_error select case when ts > '2022-01-01 00:00:00' then c_bool else c_geometry end as result from t_test; +sql_error select case when 0 then tag_id else c_geometry end as result from t_test; +sql_error select case when 0 then tag_id else c_nchar end as result from t_test; +sql_error select case when 0 then tag_id else c_int end as result from t_test; +sql_error select case when 0 then tag_id else c_float end as result from t_test; sql_error select case when c_double > 100 then c_varbinary else c_geometry end as result from t_test; sql_error select case when c_bool then c_double else c_varbinary end as result from t_test; sql_error select case when c_bool then c_varbinary else c_varchar end as result from t_test; From 38ae87fa05d3ae042394543cc89513ef9cbcc914 Mon Sep 17 00:00:00 2001 From: lyh250-666 Date: Fri, 25 Oct 2024 17:05:14 +0800 Subject: [PATCH 02/10] opti:modify bytes for numbers and string --- source/libs/scalar/src/sclvector.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 487027941c..f2e27c2f65 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -1032,7 +1032,7 @@ int8_t gConvertTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = { int8_t gDisplyTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = { /*NULL BOOL TINY SMAL INT BIGI FLOA DOUB VARC TIME NCHA UTINY USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/ - /*NULL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, -1, -1, -1, 8, + /*NULL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, -1, -1, -1, 20, /*BOOL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 5, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1, /*TINY*/ 0, 0, 2, 3, 4, 5, 8, 8, 8, 5, 10, 3, 4, 5, 8, -1, -1, -1, -1, -1, -1, /*SMAL*/ 0, 0, 0, 3, 4, 5, 8, 8, 8, 5, 10, 3, 4, 5, 8, -1, -1, -1, -1, -1, -1, @@ -1040,7 +1040,7 @@ int8_t gDisplyTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = { /*BIGI*/ 0, 0, 0, 0, 0, 5, 8, 8, 8, 5, 10, 5, 5, 5, 8, -1, -1, -1, -1, -1, -1, /*FLOA*/ 0, 0, 0, 0, 0, 0, 6, 7, 8, 8, 10, 8, 8, 8, 8, -1, -1, -1, -1, -1, -1, /*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 10, 8, 8, 8, 8, -1, -1, -1, -1, -1, -1, - /*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 10, 8, 8, 8, 8, -1, -1, -1, -1, -1, -1, + /*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 10, 8, 8, 8, 8, -1, 8, -1, -1, -1, -1, /*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 10, 5, 5, 5, 8, -1, -1, -1, -1, -1, -1, /*NCHA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, -1, -1, -1, -1, -1, -1, /*UTINY*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1, From ed1186f05e416777610e63ad468c8406ae136838 Mon Sep 17 00:00:00 2001 From: lyh250-666 Date: Fri, 25 Oct 2024 17:20:59 +0800 Subject: [PATCH 03/10] opti:modify bytes for numbers and string, and varbinary --- source/libs/scalar/src/sclvector.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index f2e27c2f65..2fb37e34bf 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -1040,7 +1040,7 @@ int8_t gDisplyTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = { /*BIGI*/ 0, 0, 0, 0, 0, 5, 8, 8, 8, 5, 10, 5, 5, 5, 8, -1, -1, -1, -1, -1, -1, /*FLOA*/ 0, 0, 0, 0, 0, 0, 6, 7, 8, 8, 10, 8, 8, 8, 8, -1, -1, -1, -1, -1, -1, /*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 10, 8, 8, 8, 8, -1, -1, -1, -1, -1, -1, - /*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 10, 8, 8, 8, 8, -1, 8, -1, -1, -1, -1, + /*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 10, 8, 8, 8, 8, -1, 16, -1, -1, -1, -1, /*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 10, 5, 5, 5, 8, -1, -1, -1, -1, -1, -1, /*NCHA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, -1, -1, -1, -1, -1, -1, /*UTINY*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1, From e6031cba1e6d5cb4dd9ef018d88f8dd30efe4258 Mon Sep 17 00:00:00 2001 From: lyh250-666 Date: Fri, 25 Oct 2024 17:27:36 +0800 Subject: [PATCH 04/10] opti:modify bytes for numbers and string, and varbinary --- tests/script/tsim/scalar/caseWhen.sim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/script/tsim/scalar/caseWhen.sim b/tests/script/tsim/scalar/caseWhen.sim index 3bba63aae3..4753e24513 100644 --- a/tests/script/tsim/scalar/caseWhen.sim +++ b/tests/script/tsim/scalar/caseWhen.sim @@ -1150,6 +1150,11 @@ if $data00 != 1234567890987654 then return -1 endi +sql select case when 1 then c_varchar else c_varbinary end from t_test; +if $data00 != null then + return -1 +endi + sql_error select case when ts > '2022-01-01 00:00:00' then c_varchar else c_geometry end as result from t_test; sql_error select case when ts > '2022-01-01 00:00:00' then c_bool else c_geometry end as result from t_test; sql_error select case when 0 then tag_id else c_geometry end as result from t_test; @@ -1158,6 +1163,5 @@ sql_error select case when 0 then tag_id else c_int end as result from t_test; sql_error select case when 0 then tag_id else c_float end as result from t_test; sql_error select case when c_double > 100 then c_varbinary else c_geometry end as result from t_test; sql_error select case when c_bool then c_double else c_varbinary end as result from t_test; -sql_error select case when c_bool then c_varbinary else c_varchar end as result from t_test; system sh/exec.sh -n dnode1 -s stop -x SIGINT From edfefbff77bd71368eba6bad8e530cae26765c12 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 30 Oct 2024 19:07:47 +0800 Subject: [PATCH 05/10] fix: value node clone issue --- include/common/ttypes.h | 16 +++++++++++---- source/libs/nodes/src/nodesCloneFuncs.c | 2 +- source/libs/parser/inc/parInt.h | 2 ++ source/libs/parser/src/parTranslater.c | 26 ++++++++++++++----------- source/libs/scalar/src/sclvector.c | 4 ++-- 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/include/common/ttypes.h b/include/common/ttypes.h index 3934553b1c..76c59f37bb 100644 --- a/include/common/ttypes.h +++ b/include/common/ttypes.h @@ -238,12 +238,20 @@ typedef struct { case TSDB_DATA_TYPE_UBIGINT: \ snprintf(_output, (int32_t)(_outputBytes), "%" PRIu64, *(uint64_t *)(_input)); \ break; \ - case TSDB_DATA_TYPE_FLOAT: \ - snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \ + case TSDB_DATA_TYPE_FLOAT: { \ + int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \ + if (n >= (_outputBytes)) { \ + snprintf(_output, (int32_t)(_outputBytes), "%*.7f", (_outputBytes) - 1, *(float *)(_input)); \ + } \ break; \ - case TSDB_DATA_TYPE_DOUBLE: \ - snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \ + } \ + case TSDB_DATA_TYPE_DOUBLE: { \ + int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \ + if (n >= (_outputBytes)) { \ + snprintf(_output, (int32_t)(_outputBytes), "%*.7f", (_outputBytes) - 1, *(double *)(_input)); \ + } \ break; \ + } \ case TSDB_DATA_TYPE_UINT: \ snprintf(_output, (int32_t)(_outputBytes), "%u", *(uint32_t *)(_input)); \ break; \ diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index b2b06e6bea..8731199a5b 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -175,7 +175,7 @@ static int32_t valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) { case TSDB_DATA_TYPE_VARCHAR: case TSDB_DATA_TYPE_VARBINARY: case TSDB_DATA_TYPE_GEOMETRY: { - int32_t len = pSrc->node.resType.bytes + 1; + int32_t len = varDataTLen(pSrc->datum.p); pDst->datum.p = taosMemoryCalloc(1, len); if (NULL == pDst->datum.p) { return terrno; diff --git a/source/libs/parser/inc/parInt.h b/source/libs/parser/inc/parInt.h index c231de653c..5999ada70f 100644 --- a/source/libs/parser/inc/parInt.h +++ b/source/libs/parser/inc/parInt.h @@ -28,6 +28,8 @@ extern "C" { #define QUERY_SMA_OPTIMIZE_DISABLE 0 #define QUERY_SMA_OPTIMIZE_ENABLE 1 +#define QUERY_NUMBER_MAX_DISPLAY_LEN 65 + int32_t parseInsertSql(SParseContext* pCxt, SQuery** pQuery, SCatalogReq* pCatalogReq, const SMetaData* pMetaData); int32_t continueCreateTbFromFile(SParseContext* pCxt, SQuery** pQuery); int32_t parse(SParseContext* pParseCxt, SQuery** pQuery); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 26151230d3..5636c4bdad 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -3297,7 +3297,7 @@ extern int8_t gDisplyTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX]; static int32_t selectCommonType(SDataType* commonType, const SDataType* newType) { if (commonType->type < TSDB_DATA_TYPE_NULL || commonType->type >= TSDB_DATA_TYPE_MAX || newType->type < TSDB_DATA_TYPE_NULL || newType->type >= TSDB_DATA_TYPE_MAX) { - return TSDB_CODE_INVALID_PARA; + return TSDB_CODE_INVALID_PARA; } int8_t type1 = commonType->type; int8_t type2 = newType->type; @@ -3307,23 +3307,27 @@ static int32_t selectCommonType(SDataType* commonType, const SDataType* newType) } else { resultType = gDisplyTypes[type2][type1]; } + if (resultType == -1) { - return TSDB_CODE_SCALAR_CONVERT_ERROR; + return TSDB_CODE_SCALAR_CONVERT_ERROR; } + if (commonType->type == newType->type) { commonType->bytes = TMAX(commonType->bytes, newType->bytes); return TSDB_CODE_SUCCESS; } - commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), TYPE_BYTES[resultType]); - if((resultType == TSDB_DATA_TYPE_VARCHAR || resultType == TSDB_DATA_TYPE_NCHAR) && ( - (IS_FLOAT_TYPE(commonType->type) || IS_FLOAT_TYPE(newType->type)) || - (IS_NUMERIC_TYPE(commonType->type) || IS_NUMERIC_TYPE(newType->type)))) - { - commonType->bytes = TMAX(commonType->bytes, 32); - } - commonType->type = resultType; - return TSDB_CODE_SUCCESS; + if ((resultType == TSDB_DATA_TYPE_VARCHAR) && (IS_MATHABLE_TYPE(commonType->type) || IS_MATHABLE_TYPE(newType->type))) { + commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), QUERY_NUMBER_MAX_DISPLAY_LEN); + } else if ((resultType == TSDB_DATA_TYPE_NCHAR) && (IS_MATHABLE_TYPE(commonType->type) || IS_MATHABLE_TYPE(newType->type))) { + commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), QUERY_NUMBER_MAX_DISPLAY_LEN * TSDB_NCHAR_SIZE); + } else { + commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), TYPE_BYTES[resultType]); + } + + commonType->type = resultType; + + return TSDB_CODE_SUCCESS; } static EDealRes translateCaseWhen(STranslateContext* pCxt, SCaseWhenNode* pCaseWhen) { diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 2fb37e34bf..8db0562c63 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -1031,7 +1031,7 @@ int8_t gConvertTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = { /*GEOM*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0}; int8_t gDisplyTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = { - /*NULL BOOL TINY SMAL INT BIGI FLOA DOUB VARC TIME NCHA UTINY USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/ + /*NULL BOOL TINY SMAL INT BIGI FLOA DOUB VARC TIM NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/ /*NULL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, -1, -1, -1, 20, /*BOOL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 5, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1, /*TINY*/ 0, 0, 2, 3, 4, 5, 8, 8, 8, 5, 10, 3, 4, 5, 8, -1, -1, -1, -1, -1, -1, @@ -1047,7 +1047,7 @@ int8_t gDisplyTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = { /*USMA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, -1, -1, -1, -1, -1, -1, /*UINT*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, -1, -1, -1, -1, -1, -1, /*UBIG*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, -1, -1, -1, - /*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, + /*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, -1, -1, -1, -1, -1, /*VARB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, -1, -1, -1, -1, /*DECI*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, /*BLOB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, From b701665ac6db40ee49082687ceb07b73f147efc7 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Thu, 31 Oct 2024 10:29:59 +0800 Subject: [PATCH 06/10] fix: compile issue --- include/common/ttypes.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/common/ttypes.h b/include/common/ttypes.h index 76c59f37bb..087e593195 100644 --- a/include/common/ttypes.h +++ b/include/common/ttypes.h @@ -241,14 +241,14 @@ typedef struct { case TSDB_DATA_TYPE_FLOAT: { \ int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \ if (n >= (_outputBytes)) { \ - snprintf(_output, (int32_t)(_outputBytes), "%*.7f", (_outputBytes) - 1, *(float *)(_input)); \ + snprintf(_output, (int32_t)(_outputBytes), "%*.7f", (int32_t)((_outputBytes) - 1), *(float *)(_input)); \ } \ break; \ } \ case TSDB_DATA_TYPE_DOUBLE: { \ int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \ if (n >= (_outputBytes)) { \ - snprintf(_output, (int32_t)(_outputBytes), "%*.7f", (_outputBytes) - 1, *(double *)(_input)); \ + snprintf(_output, (int32_t)(_outputBytes), "%*.7f", (int32_t)((_outputBytes) - 1), *(double *)(_input)); \ } \ break; \ } \ From eaea66cf480866f2b2b50a82aabe20e9ea160f59 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Thu, 31 Oct 2024 15:39:13 +0800 Subject: [PATCH 07/10] fix: value node clone issue --- source/libs/nodes/src/nodesCloneFuncs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index 8731199a5b..866b105ca1 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -176,7 +176,7 @@ static int32_t valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) { case TSDB_DATA_TYPE_VARBINARY: case TSDB_DATA_TYPE_GEOMETRY: { int32_t len = varDataTLen(pSrc->datum.p); - pDst->datum.p = taosMemoryCalloc(1, len); + pDst->datum.p = taosMemoryCalloc(1, len + 1); if (NULL == pDst->datum.p) { return terrno; } From 726594b926d3e8b7f131e9b611179a68d338f65c Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Thu, 31 Oct 2024 17:08:07 +0800 Subject: [PATCH 08/10] fix: float display issue --- include/common/ttypes.h | 4 ++-- source/libs/scalar/src/sclfunc.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/common/ttypes.h b/include/common/ttypes.h index 087e593195..bf9205ecfe 100644 --- a/include/common/ttypes.h +++ b/include/common/ttypes.h @@ -241,14 +241,14 @@ typedef struct { case TSDB_DATA_TYPE_FLOAT: { \ int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \ if (n >= (_outputBytes)) { \ - snprintf(_output, (int32_t)(_outputBytes), "%*.7f", (int32_t)((_outputBytes) - 1), *(float *)(_input)); \ + snprintf(_output, (int32_t)(_outputBytes), "%.7e", *(float *)(_input)); \ } \ break; \ } \ case TSDB_DATA_TYPE_DOUBLE: { \ int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \ if (n >= (_outputBytes)) { \ - snprintf(_output, (int32_t)(_outputBytes), "%*.7f", (int32_t)((_outputBytes) - 1), *(double *)(_input)); \ + snprintf(_output, (int32_t)(_outputBytes), "%.15e", *(double *)(_input)); \ } \ break; \ } \ diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 6f6362a8f7..d01a5ed7ab 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -2085,7 +2085,8 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp (void)memcpy(varDataVal(output), convBuf, len); varDataSetLen(output, len); } else { - NUM_TO_STRING(inputType, input, bufSize, buf); + int32_t outputSize = TMIN(outputLen - VARSTR_HEADER_SIZE, bufSize); + NUM_TO_STRING(inputType, input, outputSize, buf); int32_t len = (int32_t)strlen(buf); len = (outputLen - VARSTR_HEADER_SIZE) > len ? len : (outputLen - VARSTR_HEADER_SIZE); (void)memcpy(varDataVal(output), buf, len); From 016d176ea5f40c640110af5650aafc33d12eb077 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 1 Nov 2024 08:55:03 +0800 Subject: [PATCH 09/10] fix: number to string output length issue --- source/libs/scalar/src/sclfunc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index d01a5ed7ab..9e75abcfe8 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -2085,7 +2085,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp (void)memcpy(varDataVal(output), convBuf, len); varDataSetLen(output, len); } else { - int32_t outputSize = TMIN(outputLen - VARSTR_HEADER_SIZE, bufSize); + int32_t outputSize = (outputLen - VARSTR_HEADER_SIZE) < bufSize ? (outputLen - VARSTR_HEADER_SIZE + 1): bufSize; NUM_TO_STRING(inputType, input, outputSize, buf); int32_t len = (int32_t)strlen(buf); len = (outputLen - VARSTR_HEADER_SIZE) > len ? len : (outputLen - VARSTR_HEADER_SIZE); From bda37462fce0c973e10b55034b6bbc79954adb28 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 1 Nov 2024 09:13:04 +0800 Subject: [PATCH 10/10] fix: optimize float display --- include/common/ttypes.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/include/common/ttypes.h b/include/common/ttypes.h index bf9205ecfe..0ef47cdd12 100644 --- a/include/common/ttypes.h +++ b/include/common/ttypes.h @@ -239,16 +239,22 @@ typedef struct { snprintf(_output, (int32_t)(_outputBytes), "%" PRIu64, *(uint64_t *)(_input)); \ break; \ case TSDB_DATA_TYPE_FLOAT: { \ - int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \ - if (n >= (_outputBytes)) { \ - snprintf(_output, (int32_t)(_outputBytes), "%.7e", *(float *)(_input)); \ + int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \ + if (n >= (_outputBytes)) { \ + n = snprintf(_output, (int32_t)(_outputBytes), "%.7e", *(float *)(_input)); \ + if (n >= (_outputBytes)) { \ + snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \ + } \ } \ break; \ } \ case TSDB_DATA_TYPE_DOUBLE: { \ - int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \ - if (n >= (_outputBytes)) { \ - snprintf(_output, (int32_t)(_outputBytes), "%.15e", *(double *)(_input)); \ + int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \ + if (n >= (_outputBytes)) { \ + snprintf(_output, (int32_t)(_outputBytes), "%.15e", *(double *)(_input)); \ + if (n >= (_outputBytes)) { \ + snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \ + } \ } \ break; \ } \