fix: annotate to_timestamp array results with the execution timezone - #24636
Open
adriangb wants to merge 1 commit into
Open
fix: annotate to_timestamp array results with the execution timezone#24636adriangb wants to merge 1 commit into
to_timestamp array results with the execution timezone#24636adriangb wants to merge 1 commit into
Conversation
adriangb
marked this pull request as ready for review
August 24, 2026 19:28
Contributor
Author
`handle`/`handle_multiple` built the result array straight from `O::DATA_TYPE`, which for timestamps carries no timezone, while the scalar branch went through `scalar_value(dt, ..)` and did pick up the timezone from the declared return type. With `datafusion.execution.time_zone` set, a string *column* argument therefore produced `Timestamp(u, None)` while `return_type` promised `Timestamp(u, <tz>)`, so any plan materializing the column failed, and comparisons against another zoned value reached the Arrow kernel with mismatched types. Re-annotate the array with the declared return type before returning it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
adriangb
force-pushed
the
claude/datafusion-issue-24632-4a017a
branch
from
August 24, 2026 19:29
96ca8ce to
09ca1ce
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes timezone metadata mismatches for array-based to_timestamp* results.
Changes:
- Re-annotates parsed arrays with the declared return type.
- Updates unit-test expectations and adds coverage across timestamp variants.
- Adds SQL regression coverage for timezone-aware arrays and comparisons.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
datafusion/functions/src/datetime/common.rs |
Applies declared timestamp timezone metadata to result arrays. |
datafusion/functions/src/datetime/to_timestamp.rs |
Updates and expands unit tests. |
datafusion/sqllogictest/test_files/to_timestamp_timezone.slt |
Adds end-to-end timezone regression tests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #24636 +/- ##
==========================================
- Coverage 81.43% 81.43% -0.01%
==========================================
Files 1118 1118
Lines 399414 399469 +55
Branches 399414 399469 +55
==========================================
+ Hits 325278 325313 +35
- Misses 55145 55157 +12
- Partials 18991 18999 +8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
I'll try and review this tonight @adriangb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
to_timestampwith string input returns an array whose timezone does not match its declared return type #24632.Rationale for this change
With
datafusion.execution.time_zoneset,to_timestampon a string column declared areturn type of
Timestamp(ns, <tz>)but produced an array ofTimestamp(ns, None). Thedeclared type and the produced array disagreed, so any plan that materialized the column
failed at execution:
A second symptom: because the planner trusts the declared type it inserts no coercion, so a
comparison against another timezone-aware value reached the Arrow kernel with mismatched
types (
Invalid comparison operation: Timestamp(ns) <= Timestamp(ns, "UTC")).Scalar arguments were unaffected — they are constant-folded through a different code path
that did pick up the timezone — which is why every existing test passed.
What changes are included in this PR?
handle/handle_multipleindatafusion/functions/src/datetime/common.rsbuilt the resultarray straight from
O::DATA_TYPE, which for timestamps carries no timezone, and ignoredthe
dtreturn type they were passed. The scalar branches of the same functions wentthrough
scalar_value(dt, ..)and did carry the timezone — hence the mismatch.The array branches now re-annotate the result with
dtbefore returning it.to_date, theother caller, returns
Date32and is unaffected.Two existing unit tests in
to_timestamp.rsassertedTimestamp(_, None)for array resultseven though their helpers configure
"UTC"as the execution timezone; those expectationsencoded the bug and are updated.
Are these changes tested?
Yes.
to_timestamp_timezone.sltgains coverage for non-constant-folded (array) input: thearrow_typeofand value forto_timestampunderUTCandAmerica/New_York, theexplicit-format overload, all four precision variants, the comparison from the issue, and
a
to_datecase confirming it is unaffected. Every one of these fails onmain.to_timestamp_array_respects_execution_timezoneunit test asserts, for each of thefive
to_timestamp*UDFs and both overloads, that the returned array's type equals whatreturn_typeadvertises.The full sqllogictest suite and the extended workspace test suite pass, as does
./dev/rust_lint.sh.Are there any user-facing changes?
Yes, a bug fix:
to_timestamp*on a string column now returns an array annotated withdatafusion.execution.time_zone, matching its declared return type, instead of failing atexecution. No API changes.
🤖 Generated with Claude Code