Skip to content

fix: preserve timezone casts in timestamp comparisons - #26049

Closed
mikamikasuki wants to merge 2 commits into
apache:mainfrom
mikamikasuki:fix/25941-preserve-timezone-cast
Closed

mikamikasuki wants to merge 2 commits into
apache:mainfrom
mikamikasuki:fix/25941-preserve-timezone-cast

Conversation

@mikamikasuki

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

When a timestamp without a time zone is cast to a timestamp with a time zone, comparison simplification can move the cast from a column to a literal and change the represented instant. This can make a literal comparison return no rows even when an equivalent column comparison matches.

What changes are included in this PR?

Preserve naive-to-zoned timestamp casts on column expressions during logical and physical comparison simplification.

What is the testing strategy for this PR?

Updated timestamps_timezone.slt to assert the matching row and retained cast in the plan, and added physical-expression regression coverage.

Validated with cargo fmt --all -- --check, cargo clippy --all-targets --all-features -- -D warnings, and the full extended workspace test suite.

Are there any user-facing changes?

Timestamp comparisons involving naive-to-zoned column casts return the matching rows for non-UTC time zones.

@github-actions github-actions Bot added physical-expr Changes to the physical-expr crates optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt) labels Oct 5, 2026
@alamb alamb added the Prolific Author author opened PRs or issues in more than 20 repositories in the last 30 days label Oct 22, 2026
@mikamikasuki
mikamikasuki marked this pull request as ready for review October 24, 2026 22:50
@alamb

alamb commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Merge conflicts

@alamb
alamb marked this pull request as draft October 29, 2026 17:38
@alamb

alamb commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Sorry I don't think we have time to handle so many AI generated pull requests

@alamb alamb closed this Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules physical-expr Changes to the physical-expr crates Prolific Author author opened PRs or issues in more than 20 repositories in the last 30 days sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comparing a timestamp cast to a time zone against a literal returns wrong results

2 participants