Files
greptimedb/tests/cases/standalone/common/system/timezone.result
dennis zhuang 6a12c27e78 feat: make query be aware of timezone setting (#3175)
* feat: let TypeConversionRule aware query context timezone setting

* chore: don't optimize explain command

* feat: parse string into timestamp with timezone

* fix: compile error

* chore: check the scalar value type in predicate

* chore: remove mut for engine context

* chore: return none if the scalar value is utf8 in time range predicate

* fix: some fixme

* feat: let Date and DateTime parsing from string value be aware of timezone

* chore: tweak

* test: add datetime from_str test with timezone

* feat: construct function context from query context

* test: add timezone test for to_unixtime and date_format function

* fix: typo

* chore: apply suggestion

* test: adds string with timezone

* chore: apply CR suggestion

Co-authored-by: Lei, HUANG <6406592+v0y4g3r@users.noreply.github.com>

* chore: apply suggestion

---------

Co-authored-by: Lei, HUANG <6406592+v0y4g3r@users.noreply.github.com>
2024-01-22 14:14:03 +00:00

272 lines
7.1 KiB
Plaintext

--- tests for timezone ---
SHOW VARIABLES time_zone;
+-----------+
| TIME_ZONE |
+-----------+
| UTC |
+-----------+
SHOW VARIABLES system_time_zone;
+------------------+
| SYSTEM_TIME_ZONE |
+------------------+
| UTC |
+------------------+
CREATE TABLE test(d double, ts timestamp_ms time index);
Affected Rows: 0
INSERT INTO test values
(1, '2024-01-01 00:00:00'),
(2, '2024-01-02 08:00:00'),
(3, '2024-01-03 16:00:00'),
(4, '2024-01-04 00:00:00'),
(5, '2024-01-05 00:00:00+08:00');
Affected Rows: 5
SELECT * from test;
+-----+---------------------+
| d | ts |
+-----+---------------------+
| 1.0 | 2024-01-01T00:00:00 |
| 2.0 | 2024-01-02T08:00:00 |
| 3.0 | 2024-01-03T16:00:00 |
| 4.0 | 2024-01-04T00:00:00 |
| 5.0 | 2024-01-04T16:00:00 |
+-----+---------------------+
SELECT * from test where ts >= '2024-01-02 08:00:00';
+-----+---------------------+
| d | ts |
+-----+---------------------+
| 2.0 | 2024-01-02T08:00:00 |
| 3.0 | 2024-01-03T16:00:00 |
| 4.0 | 2024-01-04T00:00:00 |
| 5.0 | 2024-01-04T16:00:00 |
+-----+---------------------+
SELECT * from test where ts <= '2024-01-03 16:00:00';
+-----+---------------------+
| d | ts |
+-----+---------------------+
| 1.0 | 2024-01-01T00:00:00 |
| 2.0 | 2024-01-02T08:00:00 |
| 3.0 | 2024-01-03T16:00:00 |
+-----+---------------------+
select date_format(ts, '%Y-%m-%d %H:%M:%S:%3f') from test;
+----------------------------------------------------+
| date_format(test.ts,Utf8("%Y-%m-%d %H:%M:%S:%3f")) |
+----------------------------------------------------+
| 2024-01-01 00:00:00:000 |
| 2024-01-02 08:00:00:000 |
| 2024-01-03 16:00:00:000 |
| 2024-01-04 00:00:00:000 |
| 2024-01-04 16:00:00:000 |
+----------------------------------------------------+
select to_unixtime('2024-01-02 00:00:00');
+------------------------------------------+
| to_unixtime(Utf8("2024-01-02 00:00:00")) |
+------------------------------------------+
| 1704153600 |
+------------------------------------------+
select to_unixtime('2024-01-02T00:00:00+08:00');
+------------------------------------------------+
| to_unixtime(Utf8("2024-01-02T00:00:00+08:00")) |
+------------------------------------------------+
| 1704124800 |
+------------------------------------------------+
--- UTC+8 ---
SET TIME_ZONE = '+8:00';
Affected Rows: 0
SHOW VARIABLES time_zone;
+-----------+
| TIME_ZONE |
+-----------+
| +08:00 |
+-----------+
SHOW VARIABLES system_time_zone;
+------------------+
| SYSTEM_TIME_ZONE |
+------------------+
| UTC |
+------------------+
SELECT * from test;
+-----+---------------------+
| d | ts |
+-----+---------------------+
| 1.0 | 2024-01-01T00:00:00 |
| 2.0 | 2024-01-02T08:00:00 |
| 3.0 | 2024-01-03T16:00:00 |
| 4.0 | 2024-01-04T00:00:00 |
| 5.0 | 2024-01-04T16:00:00 |
+-----+---------------------+
SELECT * from test where ts >= '2024-01-02 08:00:00';
+-----+---------------------+
| d | ts |
+-----+---------------------+
| 2.0 | 2024-01-02T08:00:00 |
| 3.0 | 2024-01-03T16:00:00 |
| 4.0 | 2024-01-04T00:00:00 |
| 5.0 | 2024-01-04T16:00:00 |
+-----+---------------------+
SELECT * from test where ts <= '2024-01-03 16:00:00';
+-----+---------------------+
| d | ts |
+-----+---------------------+
| 1.0 | 2024-01-01T00:00:00 |
| 2.0 | 2024-01-02T08:00:00 |
+-----+---------------------+
select date_format(ts, '%Y-%m-%d %H:%M:%S:%3f') from test;
+----------------------------------------------------+
| date_format(test.ts,Utf8("%Y-%m-%d %H:%M:%S:%3f")) |
+----------------------------------------------------+
| 2024-01-01 08:00:00:000 |
| 2024-01-02 16:00:00:000 |
| 2024-01-04 00:00:00:000 |
| 2024-01-04 08:00:00:000 |
| 2024-01-05 00:00:00:000 |
+----------------------------------------------------+
select to_unixtime('2024-01-02 00:00:00');
+------------------------------------------+
| to_unixtime(Utf8("2024-01-02 00:00:00")) |
+------------------------------------------+
| 1704124800 |
+------------------------------------------+
select to_unixtime('2024-01-02 00:00:00+08:00');
+------------------------------------------------+
| to_unixtime(Utf8("2024-01-02 00:00:00+08:00")) |
+------------------------------------------------+
| 1704124800 |
+------------------------------------------------+
--- UTC-8 ---
SET TIME_ZONE = '-8:00';
Affected Rows: 0
SHOW VARIABLES time_zone;
+-----------+
| TIME_ZONE |
+-----------+
| -08:00 |
+-----------+
SHOW VARIABLES system_time_zone;
+------------------+
| SYSTEM_TIME_ZONE |
+------------------+
| UTC |
+------------------+
SELECT * from test;
+-----+---------------------+
| d | ts |
+-----+---------------------+
| 1.0 | 2024-01-01T00:00:00 |
| 2.0 | 2024-01-02T08:00:00 |
| 3.0 | 2024-01-03T16:00:00 |
| 4.0 | 2024-01-04T00:00:00 |
| 5.0 | 2024-01-04T16:00:00 |
+-----+---------------------+
SELECT * from test where ts >= '2024-01-02 08:00:00';
+-----+---------------------+
| d | ts |
+-----+---------------------+
| 3.0 | 2024-01-03T16:00:00 |
| 4.0 | 2024-01-04T00:00:00 |
| 5.0 | 2024-01-04T16:00:00 |
+-----+---------------------+
SELECT * from test where ts <= '2024-01-03 16:00:00';
+-----+---------------------+
| d | ts |
+-----+---------------------+
| 1.0 | 2024-01-01T00:00:00 |
| 2.0 | 2024-01-02T08:00:00 |
| 3.0 | 2024-01-03T16:00:00 |
| 4.0 | 2024-01-04T00:00:00 |
+-----+---------------------+
select date_format(ts, '%Y-%m-%d %H:%M:%S:%3f') from test;
+----------------------------------------------------+
| date_format(test.ts,Utf8("%Y-%m-%d %H:%M:%S:%3f")) |
+----------------------------------------------------+
| 2023-12-31 16:00:00:000 |
| 2024-01-02 00:00:00:000 |
| 2024-01-03 08:00:00:000 |
| 2024-01-03 16:00:00:000 |
| 2024-01-04 08:00:00:000 |
+----------------------------------------------------+
select to_unixtime('2024-01-02 00:00:00');
+------------------------------------------+
| to_unixtime(Utf8("2024-01-02 00:00:00")) |
+------------------------------------------+
| 1704182400 |
+------------------------------------------+
select to_unixtime('2024-01-02 00:00:00+08:00');
+------------------------------------------------+
| to_unixtime(Utf8("2024-01-02 00:00:00+08:00")) |
+------------------------------------------------+
| 1704124800 |
+------------------------------------------------+
drop table test;
Affected Rows: 0
-- revert timezone to UTC
SET TIME_ZONE = 'UTC';
Affected Rows: 0
SHOW VARIABLES time_zone;
+-----------+
| TIME_ZONE |
+-----------+
| UTC |
+-----------+