alamb commented on code in PR #5730:
URL: https://github.com/apache/arrow-rs/pull/5730#discussion_r1597412412
##########
arrow-cast/src/cast/string.rs:
##########
@@ -112,8 +112,11 @@ fn cast_string_to_timestamp_impl<O: OffsetSizeTrait, T:
ArrowTimestampType, Tz:
.map(|v| {
v.map(|v| {
let naive = string_to_datetime(tz, v)?.naive_utc();
- T::make_value(naive).ok_or_else(|| {
- ArrowError::CastError(format!(
+ T::make_value(naive).ok_or_else(|| match T::UNIT {
+ TimeUnit::Nanosecond => ArrowError::CastError(format!(
Review Comment:
I wonder if you would be willing to improve the messages for the other types
(like Microsecond, etc)?
##########
arrow-cast/src/cast/mod.rs:
##########
@@ -8057,6 +8057,35 @@ mod tests {
test_cast_string_to_decimal256_overflow(overflow_array);
}
+ #[test]
+ fn test_cast_outside_supported_range_for_nanoseconds() {
+ const EXPECTED_ERROR_MESSAGE: &str = "The dates that can be
represented as nanoseconds have to be between 1677-09-21T00:12:44.0 and
2262-04-11T23:47:16.854775804";
+
+ let array = StringArray::from(vec![Some("1650-01-01
01:01:01.000001")]);
+
+ let cast_options = CastOptions {
+ safe: false,
+ format_options: FormatOptions::default(),
+ };
+
+ let result = cast_string_to_timestamp::<i32, TimestampNanosecondType>(
+ &array,
+ &None::<Arc<str>>,
+ &cast_options,
+ );
+
+ assert!(result.is_err());
Review Comment:
I think this assert is unecessary (as `unwrap_err()` will panic if `result`
is not an `Err`
--
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]