kumarUjjawal opened a new pull request, #25094: URL: https://github.com/apache/datafusion/pull/25094
## Which issue does this PR close? - Closes #13212. ## Rationale for this change When a timezone-aware timestamp is subtracted from a timezone-naive timestamp, DataFusion does not use `datafusion.execution.time_zone` to interpret the naive value. For example, with the session timezone set to `+08:00`, subtracting `2024-11-01 00:00:00` from `2024-11-01 00:00:00+00:00` returns zero instead of eight hours. PostgreSQL and DuckDB handle this by implicitly casting the timezone-naive operand to the session timezone. DataFusion already produces the expected result when that cast is written explicitly, so the missing behavior belongs in type coercion. ## What changes are included in this PR? This PR: - Passes the configured session timezone to the type-coercion analyzer. - Casts the timezone-naive operand of mixed `timestamptz - timestamp` expressions using the session timezone. - Preserves the timezone of the timezone-aware operand. - Coerces both operands to the same timestamp precision. - Applies the same behavior to both operand orders and nested subqueries. - Passes the session timezone through `ExprSimplifier::coerce`, ensuring `SessionContext::create_physical_expr` behaves consistently with SQL planning. The change is limited to timestamp subtraction. Comparison operators retain their existing behavior and should be handled separately. The existing DST-boundary limitation described in #25084 remains. Because this PR inserts the previously missing cast automatically, mixed timestamp subtraction can now encounter that limitation for ambiguous or nonexistent local times. When no session timezone is configured, existing behavior is unchanged. ## What is the testing strategy for this PR? The added tests cover: - The reproduction from #13212. - Literal and column expressions. - Both subtraction operand orders. - Different session and operand timezones. - EST and EDT offsets for a named session timezone. - The direct `SessionContext::create_physical_expr` API. - Timestamp operands with different precisions. The following checks pass: ```text cargo fmt --all -- --check cargo clippy --workspace --all-targets --all-features -- -D warnings cargo test -p datafusion-optimizer cargo test -p datafusion --test core_integration ``` The extended workspace test suite from the contributor guide also passes, including all 512 SQL logic test files. ## Are there any user-facing changes? There are no public API changes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
