diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 339590e2a3..a5e702976f 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -3186,7 +3186,7 @@ static int32_t rewriteIsTrue(SNode* pSrc, SNode** pIsTrue) { return TSDB_CODE_SUCCESS; } -extern int8_t gConvertTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX]; +extern int8_t gDisplyTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX]; static bool 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) { @@ -3209,9 +3209,9 @@ static bool selectCommonType(SDataType* commonType, const SDataType* newType) { int8_t type2 = newType->type; int8_t resultType; if (type1 < type2) { - resultType = gConvertTypes[type1][type2]; + resultType = gDisplyTypes[type1][type2]; } else { - resultType = gConvertTypes[type2][type1]; + resultType = gDisplyTypes[type2][type1]; } if (resultType == -1) { return false; diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 230454483d..667ffde032 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -1030,6 +1030,30 @@ int8_t gConvertTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = { /*MEDB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1, /*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 BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB MEDB G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IG*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1, + /*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1, + /*VARB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1,-1, -1, + /*DECI*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1, + /*BLOB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1, + /*MEDB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1, + /*GEOM*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0}; + int32_t vectorGetConvertType(int32_t type1, int32_t type2) { if (type1 == type2) { return 0; diff --git a/tests/script/tsim/scalar/caseWhen.sim b/tests/script/tsim/scalar/caseWhen.sim index e7d2e4c456..7b4c875675 100644 --- a/tests/script/tsim/scalar/caseWhen.sim +++ b/tests/script/tsim/scalar/caseWhen.sim @@ -296,16 +296,16 @@ sql select case when '2' then 'b' when null then 0 end from tba1; if $rows != 4 then return -1 endi -if $data00 != 0 then +if $data00 != b then return -1 endi -if $data10 != 0 then +if $data10 != b then return -1 endi -if $data20 != 0 then +if $data20 != b then return -1 endi -if $data30 != 0 then +if $data30 != b then return -1 endi @@ -1122,7 +1122,12 @@ if $data00 != @70-01-01 08:00:00.001@ then endi sql select case when c_double > 100 then c_nchar else c_double end as result from t_test; -if $data00 != 0.000000000 then +if $data00 != 涛思数据 then + return -1 +endi + +sql select case when c_double > 100 then c_varchar else c_double end as result from t_test; +if $data00 != varchar_val then return -1 endi diff --git a/tests/system-test/2-query/case_when.py b/tests/system-test/2-query/case_when.py index a05fa539bd..85fe43b487 100755 --- a/tests/system-test/2-query/case_when.py +++ b/tests/system-test/2-query/case_when.py @@ -280,7 +280,6 @@ class TDTestCase: for i in range(30): cs = self.state_window_list().split(',')[i] - print(cs) sql1 = "select _wstart,avg(q_int),min(q_smallint) from %s.stable_1 where tbname = 'stable_1_1' state_window(%s);" % (database,cs) sql2 = "select _wstart,avg(q_int),min(q_smallint) from %s.stable_1_1 state_window(%s) ;" % (database,cs) self.constant_check(database,sql1,sql2,0)