Files
greptimedb/tests/cases/standalone/common/system/timezone.result
Lei, HUANG 69870e2762 fix(mito): use 1day as default time partition duration (#6202)
* fix unit tests

* fix: sqlness

* fix/default-time-window:
 ## Add Helper Functions and Enhance Compaction Tests

 - **Refactor Compaction Logic**: Introduced helper functions `flush` and `compact` in `compaction_test.rs` to streamline compaction operations.
 - **Enhance Compaction Tests**: Added a new test `test_infer_compaction_time_window` in `compaction_test.rs` to verify compaction time window inference.
 - **Testing Improvements**: Added `#[cfg(test)]` attribute to `new_multi_partitions` in `time_partition.rs` to ensure it's only included in test builds.

* fix/default-time-window:
 - **Refactor `TimePartition` Struct**: Removed unnecessary comments regarding `time_range` in `time_partition.rs`.
 - **Enhance `TimePartitions` Functionality**: Added a method `part_duration_or_default` to provide a default partition duration in `time_partition.rs`.
 - **Update SQL Test Cases**: Modified SQL operations and expected results in `scan_big_varchar.result` and `scan_big_varchar.sql` to reflect changes in data manipulation logic.

* fix/default-time-window:
 ### Update Time Partition Default Duration

 - **Refactor Default Duration**: Introduced `INITIAL_TIME_WINDOW` constant to define the default time window duration as `Duration::from_days(1)`. This change replaces multiple instances of the hardcoded default duration across the `time_partition.rs` file.
 - **Files Affected**: `time_partition.rs`

* fix/default-time-window:
 ## Update Partition Duration Handling

 - **`time_partition.rs`**: Refactored `part_duration` to be non-optional, removing `Option` wrapper. Updated logic to use `unwrap_or` with `INITIAL_TIME_WINDOW` where necessary. Adjusted related methods and tests to accommodate this change.
 - **`version.rs` (memtable and region)**: Updated handling of `part_duration` to align with changes in `time_partition.rs`, ensuring consistent use of non-optional `Duration`.

* fix/default-time-window:
 ### Improve Error Context in `time_partition.rs`

 - Enhanced error context message in `time_partition.rs` to provide clearer information on partition time range issues, including bucket size details.

Signed-off-by: Lei, HUANG <lhuang@greptime.com>

---------

Signed-off-by: Lei, HUANG <lhuang@greptime.com>
2025-06-08 16:20:26 +00:00

304 lines
7.6 KiB
Plaintext

--- tests for timezone ---
SHOW VARIABLES time_zone;
+-----------+
| TIME_ZONE |
+-----------+
| UTC |
+-----------+
SHOW VARIABLES system_time_zone;
+------------------+
| SYSTEM_TIME_ZONE |
+------------------+
| UTC |
+------------------+
select timezone();
+------------+
| timezone() |
+------------+
| 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 ORDER BY ts ASC;
+-----+---------------------+
| 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' ORDER BY ts;
+-----+---------------------+
| 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' ORDER BY ts;
+-----+---------------------+
| 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 ORDER BY ts;
+----------------------------------------------------+
| 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 timezone();
+------------+
| timezone() |
+------------+
| +08:00 |
+------------+
SELECT * from test ORDER BY ts;
+-----+---------------------+
| 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' ORDER BY ts;
+-----+---------------------+
| 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' ORDER BY ts;
+-----+---------------------+
| 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 ORDER BY ts;
+----------------------------------------------------+
| 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 SESSION 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 timezone();
+------------+
| timezone() |
+------------+
| -08:00 |
+------------+
SELECT * from test ORDER BY ts;
+-----+---------------------+
| 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' ORDER BY ts;
+-----+---------------------+
| 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' ORDER BY ts;
+-----+---------------------+
| 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 ORDER BY ts;
+----------------------------------------------------+
| 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 LOCAL TIME_ZONE = 'UTC';
Affected Rows: 0
SHOW VARIABLES time_zone;
+-----------+
| TIME_ZONE |
+-----------+
| UTC |
+-----------+
select timezone();
+------------+
| timezone() |
+------------+
| UTC |
+------------+