Skip to content

Commit 0c2fa63

Browse files
andygroveclaude
andauthored
test: add date_trunc DST regression test in non-UTC session timezone (#4040)
* test: add date_trunc DST regression test in non-UTC session timezone Exercises CometTruncTimestamp natively (via allowIncompatible=true) with a session timezone that observes DST. Covers spring-forward and fall-back transition days across DAY, HOUR, WEEK, MONTH, QUARTER, and YEAR levels, plus baseline non-DST days. * test: add ignored test for date_trunc panic on ambiguous DST fall-back time Adds a separate SQL test file exercising date_trunc with timestamp('2024-11-03 01:30:00') in America/Los_Angeles. Truncating this timestamp produces an ambiguous local time (1:00 AM occurs in both PDT and PST), causing chrono to return None and the native kernel to panic. All queries are marked ignore until the Rust code is fixed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 779c251 commit 0c2fa63

2 files changed

Lines changed: 112 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
-- Exercise Comet's native date_trunc on a timezone that observes DST.
19+
-- CometTruncTimestamp marks non-UTC as Incompatible, so enable allowIncompatible
20+
-- to force the native path and verify correctness against Spark.
21+
22+
-- Config: spark.comet.expression.TruncTimestamp.allowIncompatible=true
23+
-- Config: spark.sql.session.timeZone=America/Los_Angeles
24+
25+
statement
26+
CREATE TABLE test_trunc_dst(ts timestamp) USING parquet
27+
28+
statement
29+
INSERT INTO test_trunc_dst VALUES
30+
(timestamp('2024-11-03 06:30:00')),
31+
(timestamp('2024-11-03 14:30:00')),
32+
(timestamp('2024-03-10 05:30:00')),
33+
(timestamp('2024-03-10 12:30:00')),
34+
(timestamp('2024-11-15 12:00:00')),
35+
(timestamp('2024-12-15 23:30:00')),
36+
(timestamp('2024-07-15 10:00:00')),
37+
(NULL)
38+
39+
-- DAY truncation on a time after fall-back (PST) produces midnight of the same
40+
-- day, which is BEFORE the fall-back transition and should be in PDT.
41+
query
42+
SELECT ts, date_trunc('DAY', ts) FROM test_trunc_dst ORDER BY ts
43+
44+
-- HOUR truncation crossing DST boundaries.
45+
query
46+
SELECT ts, date_trunc('HOUR', ts) FROM test_trunc_dst ORDER BY ts
47+
48+
-- WEEK truncation can span DST transitions (the week of Nov 3 2024 starts Oct 28 PDT).
49+
query
50+
SELECT ts, date_trunc('WEEK', ts) FROM test_trunc_dst ORDER BY ts
51+
52+
-- MONTH truncation: Nov 15 PST truncated to MONTH gives Nov 1, which is PDT.
53+
query
54+
SELECT ts, date_trunc('MONTH', ts) FROM test_trunc_dst ORDER BY ts
55+
56+
-- QUARTER truncation: the motivating case from the PR (Dec PST -> Oct PDT).
57+
query
58+
SELECT ts, date_trunc('QUARTER', ts) FROM test_trunc_dst ORDER BY ts
59+
60+
-- YEAR truncation: Dec 15 PST truncated to YEAR gives Jan 1, which is PST too, so no DST crossing.
61+
query
62+
SELECT ts, date_trunc('YEAR', ts) FROM test_trunc_dst ORDER BY ts
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
-- Regression test for ambiguous local times during DST fall-back.
19+
-- On 2024-11-03 at 2:00 AM America/Los_Angeles, clocks fall back to 1:00 AM,
20+
-- so 1:30 AM occurs twice (once in PDT, once in PST). Truncating 01:30 to HOUR
21+
-- gives 01:00, which is ambiguous. chrono's DateTime::with_minute(0) returns
22+
-- None for ambiguous results, causing a panic in as_micros_from_unix_epoch_utc.
23+
24+
-- Config: spark.comet.expression.TruncTimestamp.allowIncompatible=true
25+
-- Config: spark.sql.session.timeZone=America/Los_Angeles
26+
27+
statement
28+
CREATE TABLE test_trunc_ambiguous(ts timestamp) USING parquet
29+
30+
statement
31+
INSERT INTO test_trunc_ambiguous VALUES
32+
(timestamp('2024-11-03 01:30:00'))
33+
34+
query ignore(native panic: chrono returns None for ambiguous local time during DST fall-back)
35+
SELECT ts, date_trunc('DAY', ts) FROM test_trunc_ambiguous ORDER BY ts
36+
37+
query ignore(native panic: chrono returns None for ambiguous local time during DST fall-back)
38+
SELECT ts, date_trunc('HOUR', ts) FROM test_trunc_ambiguous ORDER BY ts
39+
40+
query ignore(native panic: chrono returns None for ambiguous local time during DST fall-back)
41+
SELECT ts, date_trunc('WEEK', ts) FROM test_trunc_ambiguous ORDER BY ts
42+
43+
query ignore(native panic: chrono returns None for ambiguous local time during DST fall-back)
44+
SELECT ts, date_trunc('MONTH', ts) FROM test_trunc_ambiguous ORDER BY ts
45+
46+
query ignore(native panic: chrono returns None for ambiguous local time during DST fall-back)
47+
SELECT ts, date_trunc('QUARTER', ts) FROM test_trunc_ambiguous ORDER BY ts
48+
49+
query ignore(native panic: chrono returns None for ambiguous local time during DST fall-back)
50+
SELECT ts, date_trunc('YEAR', ts) FROM test_trunc_ambiguous ORDER BY ts

0 commit comments

Comments
 (0)