Skip to content

Commit

Permalink
Fix cast time as int (#1760) (#1786)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Apr 15, 2021
1 parent d42e2a0 commit 627b41a
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions dbms/src/Functions/FunctionsTiDBConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,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;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/delta-merge-test/query/expr/cast_as_decimal.test
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/delta-merge-test/query/expr/cast_as_int.test
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions tests/fullstack-test/expr/agg_pushdown.test
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
+--------------+----------+
Expand Down
8 changes: 3 additions & 5 deletions tests/fullstack-test/expr/cast_as_time.test
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
+-----------------------+
Expand All @@ -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 |
+----------------------------+
Expand Down
14 changes: 14 additions & 0 deletions tests/fullstack-test/expr/cast_time_as_int.test
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion tests/fullstack-test/expr/in_expression.test
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions tests/fullstack-test/expr/timestamp_literal.test
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
+------+---------------------+
Expand Down

0 comments on commit 627b41a

Please sign in to comment.