linhongliu-db opened a new pull request, #60402:
URL: https://github.com/apache/spark/pull/60402

   ### What changes were proposed in this pull request?
   
   Under a non-UTC session time zone, Data Source V2 push-down translates 
time-zone-dependent casts and
   datetime field extractions of a `TIMESTAMP` (for example `hour(ts)`, and 
`dayofmonth(ts)` which reads
   `CAST(ts AS DATE)`) to V2 `Extract`/`Cast`, which carry no time zone. JDBC 
exchanges timestamps in the
   JVM default zone, so the remote source evaluates the field in its own zone, 
and a filter such as
   `WHERE hour(ts) = 21` returns wrong rows when the session time zone differs 
from the JVM default.
   
   `V2ExpressionBuilder` now does not push a zone-dependent cast or datetime 
field extraction when the
   expression's time zone does not have the rules of the JVM default time zone; 
Spark evaluates it in the
   session time zone instead. A new legacy conf 
`spark.sql.legacy.dataSource.pushDownDatetimeIgnoringTimeZone`
   (default `false`) restores the previous behavior.
   
   ### Why are the changes needed?
   
   Wrong results for datetime filters pushed to a Data Source V2 source under a 
non-UTC session time zone.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, documented in `docs/sql-migration-guide.md`. Zone-dependent datetime 
push-down is now evaluated in
   the session time zone rather than the source's own zone. Set
   `spark.sql.legacy.dataSource.pushDownDatetimeIgnoringTimeZone=true` to 
restore the old behavior.
   
   ### How was this patch tested?
   
   New `JDBCV2Suite` regressions cover `hour`/`dayofmonth` of a `TIMESTAMP` 
under a session zone that
   differs from the JVM default, a gate-off case that reproduces the wrong 
rows, and a zone-independent
   `date1` control that stays pushed. Locally `JDBCV2Suite` (88/88) passes and 
scalastyle is clean on JDK 21.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Isaac)
   
   This pull request and its description were written by Isaac.
   


-- 
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]

Reply via email to