diff --git a/Cargo.lock b/Cargo.lock index 2f3d492733ea1..78ee3a13fe687 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9794,8 +9794,7 @@ dependencies = [ [[package]] name = "jsonb" version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a901f06163d352fbe41c3c2ff5e08b75330a003cc941e988fb501022f5421e6" +source = "git+https://github.com/databendlabs/jsonb?rev=1868abf#1868abfa1698a4c67fc17428da0cff5f33a2f4ad" dependencies = [ "byteorder", "ethnum", @@ -9806,9 +9805,9 @@ dependencies = [ "num-traits", "ordered-float 5.1.0", "rand 0.9.2", - "ryu", "serde", "serde_json", + "zmij", ] [[package]] @@ -18358,6 +18357,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "868b928d7949e09af2f6086dfc1e01936064cc7a819253bce650d4e2a2d63ba8" +[[package]] +name = "zmij" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fc5a66a20078bf1251bde995aa2fdcc4b800c70b5d92dd2c62abc5c60f679f8" + [[package]] name = "zopfli" version = "0.8.2" diff --git a/Cargo.toml b/Cargo.toml index 3239627b64123..ef58215377668 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -571,6 +571,7 @@ async-recursion = { git = "https://github.com/datafuse-extras/async-recursion.gi backtrace = { git = "https://github.com/rust-lang/backtrace-rs.git", rev = "72265be" } color-eyre = { git = "https://github.com/eyre-rs/eyre.git", rev = "e5d92c3" } deltalake = { git = "https://github.com/delta-io/delta-rs", rev = "9954bff" } +jsonb = { git = "https://github.com/databendlabs/jsonb", rev = "1868abf" } map-api = { git = "https://github.com/databendlabs/map-api", tag = "v0.4.2" } openraft = { git = "https://github.com/databendlabs/openraft", tag = "v0.10.0-alpha.13" } orc-rust = { git = "https://github.com/datafuse-extras/orc-rust", rev = "fc812ad7010" } diff --git a/src/query/expression/src/types/variant.rs b/src/query/expression/src/types/variant.rs index 183305bcf4d56..bbd1c5abc213b 100644 --- a/src/query/expression/src/types/variant.rs +++ b/src/query/expression/src/types/variant.rs @@ -286,7 +286,7 @@ pub fn cast_scalar_to_variant( ScalarRef::Timestamp(ts) => jsonb::Value::Timestamp(jsonb::Timestamp { value: ts }), ScalarRef::TimestampTz(ts_tz) => jsonb::Value::TimestampTz(jsonb::TimestampTz { value: ts_tz.timestamp(), - offset: ts_tz.hours_offset(), + offset: ts_tz.seconds_offset(), }), ScalarRef::Date(d) => jsonb::Value::Date(jsonb::Date { value: d }), ScalarRef::Interval(i) => { diff --git a/src/query/functions/src/scalars/variant.rs b/src/query/functions/src/scalars/variant.rs index 9e38a562a21e3..0da2f96df1de0 100644 --- a/src/query/functions/src/scalars/variant.rs +++ b/src/query/functions/src/scalars/variant.rs @@ -910,8 +910,7 @@ pub fn register(registry: &mut FunctionRegistry) { } match RawJsonb::new(v).as_timestamp_tz() { Ok(Some(res)) => { - let offset_seconds = i32::from(res.offset) * 3_600; - output.push(timestamp_tz::new(res.value, offset_seconds)); + output.push(timestamp_tz::new(res.value, res.offset)); } Ok(None) => output.push_null(), Err(err) => { @@ -3474,10 +3473,7 @@ fn cast_to_timestamp_tz(val: &[u8], tz: &TimeZone) -> Result Ok(None), - JsonbValue::TimestampTz(ts) => { - let offset_seconds = i32::from(ts.offset) * 3_600; - Ok(Some(timestamp_tz::new(ts.value, offset_seconds))) - } + JsonbValue::TimestampTz(ts) => Ok(Some(timestamp_tz::new(ts.value, ts.offset))), JsonbValue::Timestamp(ts) => { let mut value = ts.value; clamp_timestamp(&mut value); diff --git a/tests/sqllogictests/suites/query/functions/02_0056_function_semi_structureds_as.test b/tests/sqllogictests/suites/query/functions/02_0056_function_semi_structureds_as.test index 56fbcace06251..e970fff8a55c3 100644 --- a/tests/sqllogictests/suites/query/functions/02_0056_function_semi_structureds_as.test +++ b/tests/sqllogictests/suites/query/functions/02_0056_function_semi_structureds_as.test @@ -76,13 +76,23 @@ select to_timestamp('2025-01-01 10:00:00')::variant, to_timestamp(to_timestamp(' query TTTT 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) ---- -"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 +"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 + +query TTTT +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) +---- +"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 query TTTT 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) ---- "10 months 2 days" 10 months 2 days 10 months 2 days 10 months 2 days +query TTTT +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) +---- +"-10 months -2 days" -10 months -2 days -10 months -2 days -10 months -2 days + query TTTT 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) ----