opti:modify bytes for numbers and string

This commit is contained in:
lyh250-666 2024-10-25 16:59:46 +08:00
parent b5b698a76c
commit d5876b0457
3 changed files with 35 additions and 43 deletions

View File

@ -3314,16 +3314,12 @@ 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;

View File

@ -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,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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,

View File

@ -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;