rctruta opened a new pull request, #27842:
URL: https://github.com/apache/datafusion/pull/27842
## Which issue does this PR close?
- Closes #27841.
## Rationale for this change
When 1-argument `to_date(str)` receives an unparseable string (such as
`to_date('1995-02-30')`, `to_date('not-a-date')`, or `to_date('')`), it
currently returns:
```text
Arrow error: Parser error: Unable to cast to Date32 for converting from i64
to i32 failed
```
This message is a leftover from the pre-#12227 `i64` nanosecond-timestamp ->
`i32` epoch-day narrowing step; `Date32Type::parse(s)` parses directly to
`Option<i32>`, so returning that message on `None` misleads users about why
parsing failed and hides the offending value. Returning `Error parsing '{s}' as
Date32` reports the actual parse failure and input string (consistent with
`to_time`'s `Error parsing '{s}' as time`).
## What changes are included in this PR?
- Update the `Date32Type::parse(s) => None` arm in
`datafusion/functions/src/datetime/to_date.rs` to return
`arrow_err!(ParseError(format!("Error parsing '{s}' as Date32")))`.
- Strengthen `test_to_date_string_with_invalid_number` in `to_date.rs` and
the invalid-date cases in
`datafusion/sqllogictest/test_files/datetime/dates.slt` to assert the full
error message across `'213111111'`/`'202412311'`, `'1995-02-30'`,
`'not-a-date'`, and `''`.
## What is the testing strategy for this PR?
- Unit tests in `datafusion/functions/src/datetime/to_date.rs`
(`test_to_date_string_with_invalid_number`) covering `Utf8`, `LargeUtf8`, and
`Utf8View` scalars and arrays.
- End-to-end `sqllogictest` cases in
`datafusion/sqllogictest/test_files/datetime/dates.slt`.
## Are there any user-facing changes?
Invalid string inputs to 1-argument `to_date()` now return `Arrow error:
Parser error: Error parsing '<input>' as Date32` instead of `Arrow error:
Parser error: Unable to cast to Date32 for converting from i64 to i32 failed`.
--
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]