viirya opened a new pull request, #6826:
URL: https://github.com/apache/datafusion-comet/pull/6826
## Which issue does this PR close?
Closes #6825.
## Rationale for this change
`CometCast` folded every cast of a literal with `cast.eval()` while
planning. Spark's `ConstantFolding` leaves a failing cast unfolded when it sits
in a conditional branch, so under ANSI a query such as `CASE WHEN id = 5 THEN
CAST('bad' AS BIGINT) ELSE id END` failed in Comet at planning time while Spark
returned rows.
## What changes are included in this PR?
- `CometCast` folds a cast of a literal only when evaluating it succeeds
(`NonFatal` is caught, matching Spark's `ConstantFolding.tryFold`).
- When the fold fails, `getSupportLevel` reports the support level of the
actual cast (time zone and `isSupported` checks), and `convert` serializes it
as a regular cast. The error is then raised only when a row reaches the cast,
and it matches Spark's error.
- Casts of literals that evaluate successfully are folded as before.
## How are these changes tested?
- New SQL file test `expressions/cast/cast_literal_ansi.sql` (ANSI,
`ConstantFolding: enabled`): unreached `CASE`/`IF`/`COALESCE` branches return
rows, and reached branches raise `CAST_INVALID_INPUT` / `CAST_OVERFLOW` like
Spark.
- New `CometNativeCastSuite` test that checks the query runs natively and,
via `checkSparkError`, that the error raised by the native cast has the same
exception class, error class and SQLSTATE as Spark's.
- Both new tests fail without the fix.
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]