gruuya opened a new issue, #5280:
URL: https://github.com/apache/arrow-rs/issues/5280

   **Is your feature request related to a problem or challenge? Please describe 
what you are trying to do.**
   
   I'd like to be able to cast strings that represent timestamps into Date32 
objects.
   
   This is currently not possible (as per DataFusion CLI)
   ```sql
   ❯ SELECT '1998-11-30 00:00:00'::date;
   Optimizer rule 'simplify_expressions' failed
   caused by
   Arrow error: Cast error: Cannot cast string '1998-11-30 00:00:00' to value 
of Date32 type
   ```
   
   On the other hand this works in Postgres
   ```sql
   postgres=# SELECT '1998-01-30 00:00:00'::date;
       date    
   ------------
    1998-01-30
   (1 row)
   ```
   
   It seems like this is the cause of the issue
   
https://github.com/apache/arrow-rs/blob/a9470d3eb083303350fc109f94865666fd0f062f/arrow-cast/src/parse.rs#L547-L550
   
   **Describe the solution you'd like**
   
   One option would be to do
   
   ```rust
   fn parse_date(string: &str) -> Option<NaiveDate> {
       if string.len() > 10 {
           // Try to parse as timestamp and return just the date part
           return TimestampParser::new(string.as_bytes()).date();
       }
   ```
   
   That would handle the most common case (i.e. `'yyyy-mm-dd ...'`).
   
   Alternatively to handle other potential cases (single digit month and/or 
day, which PG also parses correctly) it might be better to `split_whitespace` 
and proceed with parsing the first element.
   
   **Describe alternatives you've considered**
   
   Perhaps this doesn't make sense to do in arrow-rs, and should instead be 
facilitated through a DataFusion optimizer rule.
   
   **Additional context**
   
   Related issue: #3492
   


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

Reply via email to