Skip to content

Commit 91da76f

Browse files
authored
feat(query): Variant timestamp_tz offset support seconds (#19194)
* feat(query): Variant timestamp_tz offset support seconds * fix
1 parent c7485db commit 91da76f

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

Cargo.lock

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ async-recursion = { git = "https://github.com/datafuse-extras/async-recursion.gi
571571
backtrace = { git = "https://github.com/rust-lang/backtrace-rs.git", rev = "72265be" }
572572
color-eyre = { git = "https://github.com/eyre-rs/eyre.git", rev = "e5d92c3" }
573573
deltalake = { git = "https://github.com/delta-io/delta-rs", rev = "9954bff" }
574+
jsonb = { git = "https://github.com/databendlabs/jsonb", rev = "1868abf" }
574575
map-api = { git = "https://github.com/databendlabs/map-api", tag = "v0.4.2" }
575576
openraft = { git = "https://github.com/databendlabs/openraft", tag = "v0.10.0-alpha.13" }
576577
orc-rust = { git = "https://github.com/datafuse-extras/orc-rust", rev = "fc812ad7010" }

src/query/expression/src/types/variant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ pub fn cast_scalar_to_variant(
286286
ScalarRef::Timestamp(ts) => jsonb::Value::Timestamp(jsonb::Timestamp { value: ts }),
287287
ScalarRef::TimestampTz(ts_tz) => jsonb::Value::TimestampTz(jsonb::TimestampTz {
288288
value: ts_tz.timestamp(),
289-
offset: ts_tz.hours_offset(),
289+
offset: ts_tz.seconds_offset(),
290290
}),
291291
ScalarRef::Date(d) => jsonb::Value::Date(jsonb::Date { value: d }),
292292
ScalarRef::Interval(i) => {

src/query/functions/src/scalars/variant.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -910,8 +910,7 @@ pub fn register(registry: &mut FunctionRegistry) {
910910
}
911911
match RawJsonb::new(v).as_timestamp_tz() {
912912
Ok(Some(res)) => {
913-
let offset_seconds = i32::from(res.offset) * 3_600;
914-
output.push(timestamp_tz::new(res.value, offset_seconds));
913+
output.push(timestamp_tz::new(res.value, res.offset));
915914
}
916915
Ok(None) => output.push_null(),
917916
Err(err) => {
@@ -3474,10 +3473,7 @@ fn cast_to_timestamp_tz(val: &[u8], tz: &TimeZone) -> Result<Option<timestamp_tz
34743473
let value = jsonb::from_slice(val)?;
34753474
match value {
34763475
JsonbValue::Null => Ok(None),
3477-
JsonbValue::TimestampTz(ts) => {
3478-
let offset_seconds = i32::from(ts.offset) * 3_600;
3479-
Ok(Some(timestamp_tz::new(ts.value, offset_seconds)))
3480-
}
3476+
JsonbValue::TimestampTz(ts) => Ok(Some(timestamp_tz::new(ts.value, ts.offset))),
34813477
JsonbValue::Timestamp(ts) => {
34823478
let mut value = ts.value;
34833479
clamp_timestamp(&mut value);

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,23 @@ select to_timestamp('2025-01-01 10:00:00')::variant, to_timestamp(to_timestamp('
7676
query TTTT
7777
select to_timestamp_tz('2025-01-01 10:00:00 +0800')::variant, to_timestamp_tz(to_timestamp_tz('2025-01-01 10:00:00 +0800')::variant), to_timestamp_tz(parse_json('"2025-01-01 10:00:00 +0800"')), as_timestamp_tz(to_timestamp_tz('2025-01-01 10:00:00 +0800')::variant)
7878
----
79-
"2025-01-01 10:00:00.000000" 2025-01-01 10:00:00.000000 +0800 2025-01-01 10:00:00.000000 +0800 2025-01-01 10:00:00.000000 +0800
79+
"2025-01-01 10:00:00.000000 +0800" 2025-01-01 10:00:00.000000 +0800 2025-01-01 10:00:00.000000 +0800 2025-01-01 10:00:00.000000 +0800
80+
81+
query TTTT
82+
select to_timestamp_tz('2025-01-01 10:00:00 +0830')::variant, to_timestamp_tz(to_timestamp_tz('2025-01-01 10:00:00 +0830')::variant), to_timestamp_tz(parse_json('"2025-01-01 10:00:00 +0830"')), as_timestamp_tz(to_timestamp_tz('2025-01-01 10:00:00 +0830')::variant)
83+
----
84+
"2025-01-01 10:00:00.000000 +0830" 2025-01-01 10:00:00.000000 +0830 2025-01-01 10:00:00.000000 +0830 2025-01-01 10:00:00.000000 +0830
8085

8186
query TTTT
8287
select to_interval('10 months 2 days')::variant, to_interval(to_interval('10 months 2 days')::variant), to_interval(parse_json('"10 months 2 days"')), as_interval(to_interval('10 months 2 days')::variant)
8388
----
8489
"10 months 2 days" 10 months 2 days 10 months 2 days 10 months 2 days
8590

91+
query TTTT
92+
select to_interval('-10 months -2 days')::variant, to_interval(to_interval('-10 months -2 days')::variant), to_interval(parse_json('"-10 months -2 days"')), as_interval(to_interval('-10 months -2 days')::variant)
93+
----
94+
"-10 months -2 days" -10 months -2 days -10 months -2 days -10 months -2 days
95+
8696
query TTTT
8797
select to_decimal(10, 2)(parse_json('3.14')), as_decimal(parse_json('3.14')), as_decimal(10, 2)(parse_json('3.14')), as_decimal(parse_json('3.14'), 10, 2)
8898
----

0 commit comments

Comments
 (0)