rctruta opened a new issue, #27841:
URL: https://github.com/apache/datafusion/issues/27841

   ### Describe the bug
   
   When 1-argument `to_date(expr)` receives an unparseable date string, 
`Date32Type::parse(s)` returns `None` and `to_date` emits a misleading error 
claiming an `i64` to `i32` conversion failed, without reporting the invalid 
input string:
   
   ```text
   Arrow error: Parser error: Unable to cast to Date32 for converting from i64 
to i32 failed
   ```
   
   Before #12227, 1-argument `to_date` parsed strings via 
`string_to_timestamp_nanos_shim(s)` (`Result<i64>`) and then narrowed epoch 
days from `i64` to `i32` (`v.try_into()`), where `"Unable to cast to Date32 for 
converting from i64 to i32 failed"` guarded only that `i64 -> i32` conversion. 
When #12227 replaced that pipeline with `Date32Type::parse(s) -> Option<i32>`, 
the old `i64 -> i32` overflow string was carried over into the `None` branch 
(`datafusion/functions/src/datetime/to_date.rs`, lines 76–81), so every invalid 
date string now triggers it.
   
   ### To Reproduce
   
   Run the following SQL queries (e.g. via `SessionContext::sql` or 
`sqllogictest`):
   
   ```sql
   SELECT to_date('1995-02-30');
   -- Arrow error: Parser error: Unable to cast to Date32 for converting from 
i64 to i32 failed
   
   SELECT to_date('not-a-date');
   -- Arrow error: Parser error: Unable to cast to Date32 for converting from 
i64 to i32 failed
   
   SELECT to_date('');
   -- Arrow error: Parser error: Unable to cast to Date32 for converting from 
i64 to i32 failed
   ```
   
   ### Expected behavior
   
   1-argument `to_date(string)` should report that parsing the input string as 
`Date32` failed and include the offending value:
   
   ```text
   Arrow error: Parser error: Error parsing '1995-02-30' as Date32
   ```
   
   ### Additional context
   
   Existing tests only checked that an error was returned 
(`test_to_date_string_with_invalid_number` in `to_date.rs`) or matched the 
prefix `DataFusion error: Arrow error:` (`dates.slt:151`), so the leftover 
message went unnoticed.
   
   ### Willingness to contribute
   
   I plan to contribute a fix for this bug independently


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