andygrove opened a new issue, #5073:
URL: https://github.com/apache/datafusion-comet/issues/5073
### Describe the bug
`next_day` and `make_date` honor ANSI mode correctly (throw vs NULL), and
`make_date` even reproduces the `java.time` message text and validation order
faithfully. But both raise plain `DataFusionError::Execution` strings instead
of `SparkError` variants, so under ANSI they surface as `CometNativeException`
instead of the Spark exception types:
- `next_day` with an invalid day name
(`native/spark-expr/src/datetime_funcs/next_day.rs:146-155`): Spark throws
`SparkIllegalArgumentException` with error class `ILLEGAL_DAY_OF_WEEK`,
SQLSTATE `22009`. Comet throws a generic exception with only the message
substring `"Illegal input for day of week: ..."`.
- `make_date` with out-of-range fields
(`native/spark-expr/src/datetime_funcs/make_date.rs:177-187`): Spark throws
`SparkDateTimeException` with error class
`DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION`, SQLSTATE `22023`, including the
`spark.sql.ansi.enabled` suggestion sentence. Comet emits only the inner range
message.
`native/common/src/error.rs` has no variants for these two error classes;
adding e.g. `IllegalDayOfWeek { input }` and `DatetimeFieldOutOfBounds {
range_message }` and routing them through the existing JSON conversion path (as
done for cast and arithmetic ANSI errors, `ShimSparkErrorConverter`) closes the
gap.
Existing tests
(`spark/src/test/resources/sql-tests/expressions/datetime/next_day_ansi.sql`,
`make_date_ansi.sql`) assert message substrings only, so they pass despite the
wrong exception type.
Minor related note: Spark flips `MakeDate.nullable` to depend on child
nullability when `failOnError` is set (`datetimeExpressions.scala:2570`); Comet
does not model this.
### Steps to reproduce
```sql
SET spark.sql.ansi.enabled=true;
SELECT next_day(date'2024-01-01', 'NOT_A_DAY'); -- Spark:
SparkIllegalArgumentException [ILLEGAL_DAY_OF_WEEK]
SELECT make_date(2024, 13, 1); -- Spark:
SparkDateTimeException [DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION]
```
Comet throws `CometNativeException` in both cases.
### Expected behavior
Exception type, error class, and SQLSTATE match Spark.
### Additional context
Found by an ANSI-mode audit of all native expressions against Spark 4.1.1.
--
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]