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

   ### Describe the bug
   
   `TRY_CAST` should return NULL when a cast fails. However, `timestamp/date` 
casts that overflow during conversion currently return an error.
   
   ### To Reproduce
   
   1. Timestamp(Second) -> Timestamp(Nanosecond) overflow:
   
   ```sql
   SELECT TRY_CAST(
       arrow_cast(9223372037, 'Timestamp(s)')
       AS TIMESTAMP(9)
   ) AS ts;
   ```
   
   actual output:
   
   ```text
   Optimizer rule 'simplify_expressions' failed
   Execution("Cannot cast Timestamp(s) value 9223372037 to Timestamp(ns): 
converted value exceeds the representable i64 range")
   ```
   
   2. Date -> Timestamp(Nanosecond) overflow:
   
   ```sql
   SELECT CAST(DATE '3000-01-01' AS TIMESTAMP(9)
   ```
   
   actual output:
   
   ```text
   Optimizer rule 'simplify_expressions' failed
   Execution("Cannot cast Date32 value 376200 to Timestamp(ns): converted value 
exceeds the representable i64 range")
   ```
   
   ### Expected behavior
   
   Both `TRY_CAST` queries should return NULL, while the equivalent CAST 
queries should continue to return errors.
   
   ### Additional context
   
   _No response_


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