From 5dd226d86688779a89d8f4780042658bffff1d89 Mon Sep 17 00:00:00 2001 From: Yu Lei Date: Tue, 13 Apr 2021 00:30:13 +0800 Subject: [PATCH 1/4] fix cast time as int Signed-off-by: Yu Lei --- dbms/src/Functions/FunctionsTiDBConversion.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dbms/src/Functions/FunctionsTiDBConversion.h b/dbms/src/Functions/FunctionsTiDBConversion.h index 5019be879e8..cc969c94c05 100644 --- a/dbms/src/Functions/FunctionsTiDBConversion.h +++ b/dbms/src/Functions/FunctionsTiDBConversion.h @@ -474,8 +474,8 @@ struct TiDBConvertToInteger else { MyDateTime date_time(vec_from[i]); - vec_to[i] = date_time.year * 10000000000ULL + date_time.month * 100000000ULL + date_time.day * 100000 - + date_time.hour * 1000 + date_time.minute * 100 + date_time.second; + vec_to[i] = date_time.year * 10000000000ULL + date_time.month * 100000000ULL + date_time.day * 1000000 + + date_time.hour * 10000 + date_time.minute * 100 + date_time.second; } } } From 0be4643e2539536c794a99a0d5b75616b19fefa6 Mon Sep 17 00:00:00 2001 From: Yu Lei Date: Tue, 13 Apr 2021 00:40:51 +0800 Subject: [PATCH 2/4] refine tests Signed-off-by: Yu Lei --- tests/fullstack-test/expr/agg_pushdown.test | 3 +-- tests/fullstack-test/expr/cast_as_time.test | 8 +++----- tests/fullstack-test/expr/cast_string_as_int.test | 6 ++---- tests/fullstack-test/expr/cast_time_as_int.test | 14 ++++++++++++++ tests/fullstack-test/expr/in_expression.test | 1 - tests/fullstack-test/expr/timestamp_literal.test | 5 ++--- 6 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 tests/fullstack-test/expr/cast_time_as_int.test diff --git a/tests/fullstack-test/expr/agg_pushdown.test b/tests/fullstack-test/expr/agg_pushdown.test index 4e00a05f115..c4ee3839e96 100644 --- a/tests/fullstack-test/expr/agg_pushdown.test +++ b/tests/fullstack-test/expr/agg_pushdown.test @@ -12,8 +12,7 @@ mysql> insert into test.t select * from test.t; mysql> insert into test.t select * from test.t; mysql> insert into test.t select * from test.t; -mysql> set @@tidb_isolation_read_engines='tiflash' -mysql> select substr(c, 2), count(1) from test.t group by substr(c, 2) order by substr(c, 2) +mysql> set @@tidb_isolation_read_engines='tiflash'; select substr(c, 2), count(1) from test.t group by substr(c, 2) order by substr(c, 2) +--------------+----------+ | substr(c, 2) | count(1) | +--------------+----------+ diff --git a/tests/fullstack-test/expr/cast_as_time.test b/tests/fullstack-test/expr/cast_as_time.test index 5a6b8f35c9b..4905b0d9136 100644 --- a/tests/fullstack-test/expr/cast_as_time.test +++ b/tests/fullstack-test/expr/cast_as_time.test @@ -6,14 +6,13 @@ func> wait_table test t mysql> insert into test.t values(20201208111111.999999) mysql> insert into test.t values(20201208111111.123456) -mysql> set @@tidb_isolation_read_engines='tiflash' -mysql> select * from test.t where cast(a as datetime(4)) = '2020-12-08 11:11:11.1235' +mysql> set @@tidb_isolation_read_engines='tiflash';select * from test.t where cast(a as datetime(4)) = '2020-12-08 11:11:11.1235' +-----------------------+ | a | +-----------------------+ | 20201208111111.123456 | +-----------------------+ -mysql> select * from test.t where cast(a as datetime(4)) = '2020-12-08 11:11:12.0000' +mysql> set @@tidb_isolation_read_engines='tiflash';select * from test.t where cast(a as datetime(4)) = '2020-12-08 11:11:12.0000' +-----------------------+ | a | +-----------------------+ @@ -27,8 +26,7 @@ mysql> alter table test.t set tiflash replica 1 location labels 'rack', 'host', func> wait_table test t mysql> insert into test.t values('2020-12-08 11:11:11.999999') -mysql> set @@tidb_isolation_read_engines='tiflash' -mysql> select * from test.t where cast(a as datetime(4)) = '2020-12-08 11:11:12.0000' +mysql> set @@tidb_isolation_read_engines='tiflash';select * from test.t where cast(a as datetime(4)) = '2020-12-08 11:11:12.0000' +----------------------------+ | a | +----------------------------+ diff --git a/tests/fullstack-test/expr/cast_string_as_int.test b/tests/fullstack-test/expr/cast_string_as_int.test index 999b0dfd776..79783fb3b6d 100644 --- a/tests/fullstack-test/expr/cast_string_as_int.test +++ b/tests/fullstack-test/expr/cast_string_as_int.test @@ -6,17 +6,15 @@ mysql> insert into test.t values('2006-01') func> wait_table test t -mysql> set @@tidb_isolation_read_engines='tiflash' - # Issue https://github.com/pingcap/tics/issues/1469 -mysql> select * from test.t where cast(a as signed) = -123 +mysql> set @@tidb_isolation_read_engines='tiflash'; select * from test.t where cast(a as signed) = -123 +------+ | a | +------+ | -123 | +------+ -mysql> select * from test.t where cast(a as signed) = 2006 +mysql> set @@tidb_isolation_read_engines='tiflash'; select * from test.t where cast(a as signed) = 2006 +---------+ | a | +---------+ diff --git a/tests/fullstack-test/expr/cast_time_as_int.test b/tests/fullstack-test/expr/cast_time_as_int.test new file mode 100644 index 00000000000..2c5ab6cff73 --- /dev/null +++ b/tests/fullstack-test/expr/cast_time_as_int.test @@ -0,0 +1,14 @@ +mysql> drop table if exists test.t +mysql> create table test.t(col_datetime datetime, col_date date) +mysql> alter table test.t set tiflash replica 1 +mysql> insert into test.t values('2021/04/13 00:34:00.123456', '2021/04/13') + +func> wait_table test t + +# Issue https://github.com/pingcap/tics/issues/1469 + +mysql> select count(*) from test.t where cast(col_datetime as signed) = 20210413003400 and cast(col_date as signed) = 20210413 +count(*) +1 + +mysql> drop table if exists test.t diff --git a/tests/fullstack-test/expr/in_expression.test b/tests/fullstack-test/expr/in_expression.test index b5e491a4c20..28ba86792ec 100644 --- a/tests/fullstack-test/expr/in_expression.test +++ b/tests/fullstack-test/expr/in_expression.test @@ -6,7 +6,6 @@ func> wait_table test t mysql> insert into test.t values(1, -80, -1, 1); mysql> insert into test.t values(3, -90, -3, 0); -mysql> set session tidb_isolation_read_engines='tiflash' # issue https://github.com/pingcap/tics/issues/1483 mysql> set session tidb_isolation_read_engines='tiflash'; select a from test.t where a in (1.0, 2); diff --git a/tests/fullstack-test/expr/timestamp_literal.test b/tests/fullstack-test/expr/timestamp_literal.test index 10d1959fde1..06a4fb2f363 100644 --- a/tests/fullstack-test/expr/timestamp_literal.test +++ b/tests/fullstack-test/expr/timestamp_literal.test @@ -5,14 +5,13 @@ mysql> alter table test.t set tiflash replica 1 location labels 'rack', 'host', func> wait_table test t mysql> set time_zone = 'UTC'; insert into test.t values(1,'2020-01-01 00:00:00') -mysql> set @@tidb_isolation_read_engines='tiflash' -mysql> set time_zone = '+9:00'; select * from test.t where value = (select max(value) from test.t); +mysql> set @@tidb_isolation_read_engines='tiflash'; set time_zone = '+9:00'; select * from test.t where value = (select max(value) from test.t); +------+---------------------+ | id | value | +------+---------------------+ | 1 | 2020-01-01 09:00:00 | +------+---------------------+ -mysql> set time_zone = 'Asia/Shanghai'; select * from test.t where value = (select max(value) from test.t); +mysql> set @@tidb_isolation_read_engines='tiflash'; set time_zone = 'Asia/Shanghai'; select * from test.t where value = (select max(value) from test.t); +------+---------------------+ | id | value | +------+---------------------+ From e8d0f5ea205d8bfd0c715b29a947fc88decc911a Mon Sep 17 00:00:00 2001 From: Yu Lei Date: Tue, 13 Apr 2021 02:18:23 +0800 Subject: [PATCH 3/4] fix test Signed-off-by: Yu Lei --- tests/delta-merge-test/query/expr/cast_as_decimal.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/delta-merge-test/query/expr/cast_as_decimal.test b/tests/delta-merge-test/query/expr/cast_as_decimal.test index c7c72af3c2e..441f3a48447 100644 --- a/tests/delta-merge-test/query/expr/cast_as_decimal.test +++ b/tests/delta-merge-test/query/expr/cast_as_decimal.test @@ -14,7 +14,7 @@ => DBGInvoke dag('select count(1) from default.test group by a, cast_int_decimal(a), cast_real_decimal(b), cast_decimal_decimal(c), cast_string_decimal(d), cast_time_decimal(e)', 4,'encode_type:chunk') ┌─count(1)─┬─a─┬─cast_int_decimal(a)─┬─cast_real_decimal(b)─┬─cast_decimal_decimal(c)─┬─cast_string_decimal(d)─┬─cast_time_decimal(e)─┐ -│ 1 │ 1 │ 1 │ 1 │ 1 │ 123 │ 20200901501000 │ +│ 1 │ 1 │ 1 │ 1 │ 1 │ 123 │ 20200915010000 │ └──────────┴───┴─────────────────────┴──────────────────────┴─────────────────────────┴────────────────────────┴──────────────────────┘ # Clean up. From 5e1983f14b026bcc1b92eec3a314eec5cae4aeb1 Mon Sep 17 00:00:00 2001 From: Yu Lei Date: Thu, 15 Apr 2021 17:50:23 +0800 Subject: [PATCH 4/4] fix Signed-off-by: Yu Lei --- tests/delta-merge-test/query/expr/cast_as_int.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/delta-merge-test/query/expr/cast_as_int.test b/tests/delta-merge-test/query/expr/cast_as_int.test index 02a55230878..5bf27ca303f 100644 --- a/tests/delta-merge-test/query/expr/cast_as_int.test +++ b/tests/delta-merge-test/query/expr/cast_as_int.test @@ -14,7 +14,7 @@ => DBGInvoke dag('select count(1) from default.test group by a, cast_int_int(a), cast_real_int(b), cast_decimal_int(c), cast_string_int(d), cast_time_int(e)', 4,'encode_type:chunk') ┌─count(1)─┬─a─┬─cast_int_int(a)─┬─cast_real_int(b)─┬─cast_decimal_int(c)─┬─cast_string_int(d)─┬─cast_time_int(e)─┐ -│ 1 │ 1 │ 1 │ 1 │ 1 │ 123 │ 20200901501000 │ +│ 1 │ 1 │ 1 │ 1 │ 1 │ 123 │ 20200915010000 │ └──────────┴───┴─────────────────┴──────────────────┴─────────────────────┴────────────────────┴──────────────────┘ # Clean up. => DBGInvoke __drop_tidb_table(default, test)