From fae8f5bfa58102da9c6994121012edd9c8c7263a Mon Sep 17 00:00:00 2001 From: lyh250-666 Date: Fri, 11 Oct 2024 13:41:17 +0800 Subject: [PATCH] opti:add case --- tests/script/tsim/scalar/caseWhen.sim | 21 +++++++++++++++++---- tests/system-test/2-query/case_when.py | 18 +++++++++--------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/tests/script/tsim/scalar/caseWhen.sim b/tests/script/tsim/scalar/caseWhen.sim index 777f976270..e7d2e4c456 100644 --- a/tests/script/tsim/scalar/caseWhen.sim +++ b/tests/script/tsim/scalar/caseWhen.sim @@ -1064,9 +1064,9 @@ sql_error select case when sum(f1) then sum(f1)-abs(f1) end from tba1; sql drop database if exists test_db; sql create database test_db vgroups 5; sql use test_db; -sql create stable test_stable (ts TIMESTAMP,c_int INT,c_uint INT UNSIGNED, c_bigint BIGINT, c_ubigint BIGINT UNSIGNED, c_float FLOAT, c_double DOUBLE, c_binary BINARY(20), c_smallint SMALLINT, c_usmallint SMALLINT UNSIGNED, c_tinyint TINYINT,c_utinyint TINYINT UNSIGNED,c_bool BOOL,c_nchar NCHAR(20), c_varchar VARCHAR(20)) tags(tag_id INT); +sql create stable test_stable (ts TIMESTAMP,c_int INT,c_uint INT UNSIGNED, c_bigint BIGINT, c_ubigint BIGINT UNSIGNED, c_float FLOAT, c_double DOUBLE, c_binary BINARY(20), c_smallint SMALLINT, c_usmallint SMALLINT UNSIGNED, c_tinyint TINYINT,c_utinyint TINYINT UNSIGNED,c_bool BOOL,c_nchar NCHAR(20), c_varchar VARCHAR(20), c_varbinary VARBINARY(20), c_geometry GEOMETRY(50)) tags(tag_id INT); sql create table t_test using test_stable tags(1); -sql insert into t_test values ('2022-09-30 15:15:01',123,456,1234567890,9876543210,123.45,678.90,'binary_val',32767,65535,127,255,true,'涛思数据','varchar_val'); +sql insert into t_test values ('2022-09-30 15:15:01',123,456,1234567890,9876543210,123.45,678.90,'binary_val',32767,65535,127,255,true,'涛思数据','varchar_val', '1101', 'point(10 10)'); sql select case when c_int > 100 then c_float else c_int end as result from t_test; if $rows != 1 then @@ -1088,7 +1088,6 @@ sql select case when c_bool then c_bool else c_utinyint end as result from t_tes if $rows != 1 then return -1 endi -print $data00 if $data00 != 1 then return -1 endi @@ -1126,4 +1125,18 @@ sql select case when c_double > 100 then c_nchar else c_double end as result fro if $data00 != 0.000000000 then return -1 endi -system sh/exec.sh -n dnode1 -s stop -x SIGINT + +sql select case when c_bool then c_varbinary else c_varchar end as result from t_test; +if $data00 != null 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 + return -1 +endi +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 ts > '2022-01-01 00:00:00' then c_bool 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; + + diff --git a/tests/system-test/2-query/case_when.py b/tests/system-test/2-query/case_when.py index 5140f2e50f..a05fa539bd 100755 --- a/tests/system-test/2-query/case_when.py +++ b/tests/system-test/2-query/case_when.py @@ -122,8 +122,8 @@ class TDTestCase: self.constant_check(database,sql1,sql2,5) #TD-20260 - # sql1 = "select _wstart,avg(q_int),min(q_smallint) from %s.stable_1 where tbname = 'stable_1_1' and ts < now state_window(case when q_smallint <0 then 1 else 0 end);" %database - # sql2 = "select _wstart,avg(q_int),min(q_smallint) from %s.stable_1_1 where ts < now state_window(case when q_smallint <0 then 1 else 0 end);" %database + sql1 = "select _wstart,avg(q_int),min(q_smallint) from %s.stable_1 where tbname = 'stable_1_1' and ts < now state_window(case when q_smallint <0 then 1 else 0 end);" %database + sql2 = "select _wstart,avg(q_int),min(q_smallint) from %s.stable_1_1 where ts < now state_window(case when q_smallint <0 then 1 else 0 end);" %database self.constant_check(database,sql1,sql2,0) self.constant_check(database,sql1,sql2,1) self.constant_check(database,sql1,sql2,2) @@ -159,7 +159,7 @@ class TDTestCase: 'first case when q_int < %d then %d when q_int >= %d then %d else %d end last' %(a1,a2,a1,a2,a3), #'first case when q_int < 3 then 1 when q_int >= 3 then 2 else 3 end last' , 'first cast(case q_int when q_int then q_int + (%d) else q_int is null end as double) last' %(a1), #'first cast(case q_int when q_int then q_int + 1 else q_int is null end as double) last' , 'first sum(case q_int when q_int then q_int + (%d) else q_int is null end + (%d)) last' %(a1,a2), #'first sum(case q_int when q_int then q_int + 1 else q_int is null end + 1) last' , - #'first case when q_int is not null then case when q_int <= %d then q_int else q_int * (%d) end else -(%d) end last' %(a1,a1,a3), #'first case when q_int is not null then case when q_int <= 0 then q_int else q_int * 10 end else -1 end last' , + 'first case when q_int is not null then case when q_int <= %d then q_int else q_int * (%d) end else -(%d) end last' %(a1,a1,a3), #'first case when q_int is not null then case when q_int <= 0 then q_int else q_int * 10 end else -1 end last' , 'first case %d when %d then %d end last' %(a1,a2,a3), # 'first case 3 when 3 then 4 end last' , 'first case %d when %d then %d end last' %(a1,a2,a3), # 'first case 3 when 1 then 4 end last' , 'first case %d when %d then %d else %d end last' %(a1,a1,a2,a3), # 'first case 3 when 1 then 4 else 2 end last' , @@ -231,12 +231,12 @@ class TDTestCase: 'first case when \'%d\' then \'b\' when null then %d end last' %(a1,a2) , #'first case when \'2\' then \'b\' when null then 0 end last' , 'first case when \'%d\' then \'b\' else null end last' %(a1), #'first case when \'0\' then \'b\' else null end last', 'first case when \'%d\' then \'b\' else %d end last' %(a1,a2), #'first case when \'0\' then \'b\' else 2 end last', - 'first case when q_int then q_int when q_int + (%d) then q_int + (%d) else q_int is null end last' %(a1,a2) , #'first case when q_int then q_int when q_int + 1 then q_int + 1 else q_int is null end last' , - #'first case when q_int then %d when ts then ts end last' %(a1), #'first case when q_int then 3 when ts then ts end last' , + 'first case when q_int then q_int when q_int + (%d) then cast(q_int + (%d) as int) else q_int is null end last' %(a1,a2) , #'first case when q_int then q_int when q_int + 1 then q_int + 1 else q_int is null end last' , + 'first case when q_int then %d when ts then cast(ts as int) end last' %(a1), #'first case when q_int then 3 when ts then ts end last' , 'first case when %d then q_int end last' %(a1), #'first case when 3 then q_int end last' , 'first case when q_int then %d when %d then %d end last' %(a1,a1,a3), #'first case when q_int then 3 when 1 then 2 end last' , 'first case when q_int < %d then %d when q_int >= %d then %d else %d end last' %(a1,a2,a1,a2,a3), #'first case when q_int < 3 then 1 when q_int >= 3 then 2 else 3 end last' , - #'first case when q_int is not null then case when q_int <= %d then q_int else q_int * (%d) end else -(%d) end last' %(a1,a1,a3), #'first case when q_int is not null then case when q_int <= 0 then q_int else q_int * 10 end else -1 end last' , + 'first case when q_int is not null then case when q_int <= %d then q_int else cast(q_int * (%d) as int) end else -(%d) end last' %(a1,a1,a3), #'first case when q_int is not null then case when q_int <= 0 then q_int else q_int * 10 end else -1 end last' , 'first case %d when %d then %d end last' %(a1,a2,a3), # 'first case 3 when 3 then 4 end last' , 'first case %d when %d then %d end last' %(a1,a2,a3), # 'first case 3 when 1 then 4 end last' , 'first case %d when %d then %d else %d end last' %(a1,a1,a2,a3), # 'first case 3 when 1 then 4 else 2 end last' , @@ -250,15 +250,15 @@ class TDTestCase: 'first case when \'a\' then \'b\' when null then %d end last' %(a1), # 'first case when \'a\' then \'b\' when null then 0 end last' , 'first case when \'%d\' then \'b\' when null then %d end last' %(a1,a2), # 'first case when \'2\' then \'b\' when null then 0 end last' , 'first case when %d then \'b\' else null end last' %(a1), # 'first case when 0 then \'b\' else null end last' , - 'first case when %d then \'b\' else %d+abs(%d) end last' %(a1,a2,a3), # 'first case when 0 then \'b\' else 2+abs(-2) end last' , + 'first case when %d then \'b\' else cast(%d+abs(%d) as int) end last' %(a1,a2,a3), # 'first case when 0 then \'b\' else 2+abs(-2) end last' , 'first case when %d then %d end last' %(a1,a2), # 'first case when 3 then 4 end last' , 'first case when %d then %d end last' %(a1,a2), # 'first case when 0 then 4 end last' , 'first case when null then %d end last' %(a1), # 'first case when null then 4 end last' , - #'first case when %d then %d+(%d) end last' %(a1,a2,a3), # 'first case when 1 then 4+1 end last' , + 'first case when %d then cast(%d+(%d) as int) end last' %(a1,a2,a3), # 'first case when 1 then 4+1 end last' , 'first case when %d-(%d) then %d end last' %(a1,a2,a3), # 'first case when 1-1 then 0 end last' , 'first case when %d+(%d) then %d end last' %(a1,a2,a3), # 'first case when 1+1 then 0 end last' , 'first case when abs(%d) then abs(%d) end last' %(a1,a2), # 'first case when abs(3) then abs(-1) end last' , - #'first case when abs(%d+(%d)) then abs(%d)+abs(%d) end last' %(a1,a2,a3,a1), # 'first case when abs(1+1) then abs(-1)+abs(3) end last' , + 'first case when abs(%d+(%d)) then cast(abs(%d)+abs(%d) as int) end last' %(a1,a2,a3,a1), # 'first case when abs(1+1) then abs(-1)+abs(3) end last' , 'first case when %d then %d else %d end last' %(a1,a2,a3), # 'first case when 0 then 1 else 3 end last' , 'first case when %d then %d when %d then %d else %d end last' %(a1,a2,a3,a1,a2), # 'first case when 0 then 1 when 1 then 0 else 3 end last' , 'first case when %d then %d when %d then %d when %d then %d end last' %(a1,a2,a3,a1,a2,a3), # 'first case when 0 then 1 when 1 then 0 when 2 then 3 end last' ,