aleksandar-trajkovic-db opened a new pull request, #60455:
URL: https://github.com/apache/spark/pull/60455
### What changes were proposed in this pull request?
Takes over #57564, which was approved but closed as stale. A fractional to
integral cast pushed down to JDBC is wrapped in the dialect's truncating
function (`JdbcDialect.truncateFractionalValue`) on Postgres, MySQL, Oracle,
Snowflake and H2. Dialects whose cast already truncates (SQL Server, DB2,
Teradata, Derby, Databricks) keep the plain cast. Integral cast targets without
a dialect mapping are spelled `SMALLINT`/`INTEGER`/`BIGINT` instead of Spark's
`short`/`long`.
### Why are the changes needed?
A pushed cast should return Spark's result, but Spark truncates and these
databases round, so rows are silently dropped or miscounted:
```sql
SELECT * FROM pg.public.t WHERE CAST(d AS INT) = 2 -- d = 2.6
```
Before: `CAST("d" AS integer) = 2` (Postgres rounds 2.6 to 3, so the row is
dropped). Target: `CAST(TRUNC("d") AS INTEGER) = 2`. A pushed `CAST(.. AS
BIGINT)` was also sent as `CAST(.. AS long)`, which Postgres, SQL Server and
DB2 reject.
### Does this PR introduce _any_ user-facing change?
Yes. Pushed fractional to integral casts on Postgres, MySQL/MariaDB, Oracle,
Snowflake and H2 now truncate like Spark instead of rounding.
`spark.sql.legacy.jdbc.roundIntegralCastPushdown.enabled` restores the old
behavior.
### How was this patch tested?
New tests in `JDBCV2Suite` and `V2JDBCTest`.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 5.5)
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]