Skip to content

Commit d99a230

Browse files
KKouldyoungsofun
andauthored
fix: timestamp_tz display (#18958)
* fix: timestamp_tz display * chore: fix timestamp_tz age * Update tests/sqllogictests/suites/query/functions/02_0002_function_cast.test Co-authored-by: Yang Xiufeng <[email protected]> * chore: add test for timezone_tz default tz * chore: add test for timezone_tz default tz --------- Co-authored-by: Yang Xiufeng <[email protected]>
1 parent 61232e7 commit d99a230

File tree

7 files changed

+33
-19
lines changed

7 files changed

+33
-19
lines changed

src/common/column/src/types/native.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ impl timestamp_tz {
532532

533533
impl Display for timestamp_tz {
534534
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
535-
let timestamp = Timestamp::from_microsecond(self.timestamp()).unwrap();
535+
let timestamp = Timestamp::from_microsecond(self.total_micros()).unwrap();
536536

537537
let offset = tz::Offset::from_seconds(self.seconds_offset()).unwrap();
538538
let string = strtime::format(

src/query/functions/src/scalars/timestamp/src/interval.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ fn register_interval_add_sub_mul(registry: &mut FunctionRegistry) {
145145
return;
146146
}
147147
};
148-
// EvalMonthsImpl::eval_timestamp will use tz to add offset to timestamp as local timestamp, so here we balance it by subtracting offset in advance
149-
// - input.micros_offset().unwrap_or(0)
150-
eval_timestamp_plus(a, b, output, ctx, |input| input.timestamp() - input.micros_offset().unwrap_or(0), |result| timestamp_tz::new(result, a.seconds_offset()), TimeZone::fixed(offset));
148+
eval_timestamp_plus(a, b, output, ctx, |input| input.timestamp(), |result| timestamp_tz::new(result, a.seconds_offset()), TimeZone::fixed(offset));
151149
},
152150
),
153151
);
@@ -185,9 +183,7 @@ fn register_interval_add_sub_mul(registry: &mut FunctionRegistry) {
185183
return;
186184
}
187185
};
188-
// EvalMonthsImpl::eval_timestamp will use tz to add offset to timestamp as local timestamp, so here we balance it by subtracting offset in advance
189-
// - input.micros_offset().unwrap_or(0)
190-
eval_timestamp_plus(a, b, output, ctx, |input| input.timestamp() - input.micros_offset().unwrap_or(0), |result| timestamp_tz::new(result, a.seconds_offset()), TimeZone::fixed(offset));
186+
eval_timestamp_plus(a, b, output, ctx, |input| input.timestamp(), |result| timestamp_tz::new(result, a.seconds_offset()), TimeZone::fixed(offset));
191187
},
192188
),
193189
);
@@ -239,9 +235,7 @@ fn register_interval_add_sub_mul(registry: &mut FunctionRegistry) {
239235
return;
240236
}
241237
};
242-
// EvalMonthsImpl::eval_timestamp will use tz to add offset to timestamp as local timestamp, so here we balance it by subtracting offset in advance
243-
// - input.micros_offset().unwrap_or(0)
244-
eval_timestamp_minus(a, b, output, ctx, |input| input.timestamp() - input.micros_offset().unwrap_or(0), |result| timestamp_tz::new(result, a.seconds_offset()), TimeZone::fixed(offset));
238+
eval_timestamp_minus(a, b, output, ctx, |input| input.timestamp(), |result| timestamp_tz::new(result, a.seconds_offset()), TimeZone::fixed(offset));
245239
},
246240
),
247241
);

tests/sqllogictests/suites/base/03_common/03_0016_insert_into_values.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ insert into ts1 values (1676620596564, '2024-10-22 12:00:00+0900')
7171
query T
7272
select a, b from ts1
7373
----
74-
2023-02-17 07:56:36.564000 2024-10-22 21:00:00.000000 +0900
74+
2023-02-17 07:56:36.564000 2024-10-22 12:00:00.000000 +0900
7575

7676
statement ok
7777
create table my_table(column1 string, column2 string, column3 string);

tests/sqllogictests/suites/base/05_ddl/05_0000_ddl_create_tables.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,5 +697,5 @@ insert into test_timestamp_tz values(1, '2024-10-22 12:00:00');
697697
query T rowsort
698698
select c1, c2::STRING from test_timestamp_tz;
699699
----
700-
0 2024-10-22 21:00:00.000000 +0900
700+
0 2024-10-22 12:00:00.000000 +0900
701701
1 2024-10-22 12:00:00.000000 +0000

tests/sqllogictests/suites/base/09_fuse_engine/09_0001_remote_insert.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ INSERT INTO t3 (a,b,c,d,e,f) values(true, '2021-09-07 21:38:35.000000', '2021-09
5353
query BTTTTT
5454
SELECT a, b, c, d, e, f FROM t3 order by a desc;
5555
----
56-
1 2021-09-07 21:38:35.000000 2021-09-07 [1,2,3] (10,'abc') 2024-10-22 21:00:00.000000 +0900
56+
1 2021-09-07 21:38:35.000000 2021-09-07 [1,2,3] (10,'abc') 2024-10-22 12:00:00.000000 +0900
5757
0 2021-09-07 21:38:35.000000 2021-09-07 [4,5,6] (20,'xyz') 2024-10-22 12:00:00.000000 +0000
5858

5959
query IIIT
@@ -150,7 +150,7 @@ INSERT INTO t_compression_zstd (a,b,c,e) values(true, '2021-09-07 21:38:35.00000
150150
query BTTT
151151
SELECT a, b, c, e FROM t_compression_zstd order by a desc;
152152
----
153-
1 2021-09-07 21:38:35.000000 2021-09-07 2024-10-22 21:00:00.000000 +0900
153+
1 2021-09-07 21:38:35.000000 2021-09-07 2024-10-22 12:00:00.000000 +0900
154154
0 2021-09-07 21:38:35.000000 2021-09-07 2024-10-22 12:00:00.000000 +0000
155155

156156
statement ok

tests/sqllogictests/suites/base/11_data_type/11_0001_data_type_date_time.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ select '2044-05-06 03:25:02.868894'::TIMESTAMP_TZ
8989
query T
9090
select '2044-05-06 03:25:02.868894-0700'::TIMESTAMP_TZ::STRING
9191
----
92-
2044-05-05 20:25:02.868894 -0700
92+
2044-05-06 03:25:02.868894 -0700
9393

9494
query T
9595
select '2044-05-06 03:25:02.868894-07:00'::TIMESTAMP_TZ::STRING
9696
----
97-
2044-05-05 20:25:02.868894 -0700
97+
2044-05-06 03:25:02.868894 -0700
9898

9999
query T
100100
select '2044-05-06T03:25:02.868894'::TIMESTAMP_TZ::STRING
@@ -104,12 +104,12 @@ select '2044-05-06T03:25:02.868894'::TIMESTAMP_TZ::STRING
104104
query T
105105
select '2044-05-06T03:25:02.868894-0700'::TIMESTAMP_TZ::STRING
106106
----
107-
2044-05-05 20:25:02.868894 -0700
107+
2044-05-06 03:25:02.868894 -0700
108108

109109
query T
110110
select '2044-05-06T03:25:02.868894-07:00'::TIMESTAMP_TZ::STRING
111111
----
112-
2044-05-05 20:25:02.868894 -0700
112+
2044-05-06 03:25:02.868894 -0700
113113

114114
query T
115115
select '9999-12-12'::TIMESTAMP_TZ::STRING

tests/sqllogictests/suites/query/functions/02_0002_function_cast.test

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ set timezone='Asia/Shanghai'
215215
query T
216216
select to_timestamp_tz(to_timestamp('2021-12-20 17:01:01.000000'))::STRING
217217
----
218-
2021-12-20 17:01:01.000000 +0800
218+
2021-12-20 09:01:01.000000 +0800
219219

220220
query T
221221
select to_timestamp(to_timestamp_tz('2021-12-20 17:01:01.000000 +0000'))
@@ -235,6 +235,26 @@ select to_timestamp(to_timestamp_tz('2021-12-20 17:01:01.000000 +0800'))
235235
----
236236
2021-12-20 09:01:01.000000
237237

238+
query T
239+
select to_timestamp_tz('2024-04-16 12:34:56.789 +0600')
240+
----
241+
2024-04-16 12:34:56.789000 +0600
242+
243+
query T
244+
settings(timezone='Asia/Shanghai') select to_timestamp_tz('2024-04-16 12:34:56.789 +0600')
245+
----
246+
2024-04-16 12:34:56.789000 +0600
247+
248+
query T
249+
settings(timezone='Asia/Shanghai') select to_timestamp_tz('2024-04-16 12:34:56.789 +0800')
250+
----
251+
2024-04-16 12:34:56.789000 +0800
252+
253+
query T
254+
settings(timezone='Asia/Shanghai') select to_timestamp_tz('2024-04-16 12:34:56.789')
255+
----
256+
2024-04-16 12:34:56.789000 +0800
257+
238258
query B
239259
SELECT to_variant(true)::boolean
240260
----

0 commit comments

Comments
 (0)