friendlymatthew commented on issue #7153: URL: https://github.com/apache/arrow-rs/issues/7153#issuecomment-2744406137
> IMO I would expect an error if I try to use a time format specifier on a date, i.e. the current chrono behaviour, although I agree the current error message is unhelpful ([chronotope/chrono#1660](https://github.com/chronotope/chrono/issues/1660)). > > I understand from [apache/datafusion#14536](https://github.com/apache/datafusion/issues/14536) the intent is to replicate postgres behaviour which does allow this. > > Fortunately it is relatively straightforward to detect if a format string contains "invalid" literals using [StftimeItems](https://docs.rs/chrono/latest/chrono/format/strftime/struct.StrftimeItems.html#impl-Iterator-for-StrftimeItems%3C'a%3E). > > So perhaps DataFusion could do this, and then either enable a new option on FormatOptions to format dates as timestamps, or cast the input array to a timestamp, or something else. Sounds good. I think there's two separate parts to this: improving the format error message and supporting the intermediary cast for this feature. The latter being done in Datafusion land. <br> For improving the format error message, maybe we should do this in arrow. Consider: ```rust let invalid_date_format = "%Y-%m-%Q"; // %Q is an invalid time specifier let cast_options = CastOptions { safe: false, format_options: FormatOptions::default().with_date_format(Some(invalid_date_format)), }; let array = Date32Array::from(vec![10000, 17890]); let res = cast_with_options(&array, &DataType::Utf8, &cast_options); dbg!(&res); // Err(CastError("Format error")) ``` Maybe we could use [`StrftimeItems::parse`](https://docs.rs/chrono/latest/chrono/format/strftime/struct.StrftimeItems.html#method.parse) and check if the format string errs and pass the error message along. I changed the issue to reflect the above. -- 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]
