From 64ce06f5f7d57002a2150b5fd2b20940c8d0ecbe Mon Sep 17 00:00:00 2001 From: abi Date: Tue, 7 May 2024 00:10:49 +0200 Subject: [PATCH 1/4] improved the error message --- arrow-cast/src/cast/string.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arrow-cast/src/cast/string.rs b/arrow-cast/src/cast/string.rs index e9c1ff58d62f..4b83a2a5e7da 100644 --- a/arrow-cast/src/cast/string.rs +++ b/arrow-cast/src/cast/string.rs @@ -112,8 +112,11 @@ fn cast_string_to_timestamp_impl ArrowError::CastError(format!( + "Overflow converting {naive} to Nanosecond. 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" + )), + _ => ArrowError::CastError(format!( "Overflow converting {naive} to {:?}", T::UNIT )) From 4b65f4ebfc1444361d42d87ba497157b22131537 Mon Sep 17 00:00:00 2001 From: abi Date: Tue, 7 May 2024 00:54:32 +0200 Subject: [PATCH 2/4] added a test to test the overflow --- arrow-cast/src/cast/mod.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arrow-cast/src/cast/mod.rs b/arrow-cast/src/cast/mod.rs index 171267f80543..92a9c06155f4 100644 --- a/arrow-cast/src/cast/mod.rs +++ b/arrow-cast/src/cast/mod.rs @@ -8057,6 +8057,26 @@ 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::(&array, &None::>, &cast_options); + + assert!(result.is_err()); + let err = result.unwrap_err(); + assert_eq!(err.to_string(), format!("Cast error: Overflow converting {} to Nanosecond. {}", array.value(0), EXPECTED_ERROR_MESSAGE)); + } + #[test] fn test_cast_date32_to_timestamp() { let a = Date32Array::from(vec![Some(18628), Some(18993), None]); // 2021-1-1, 2022-1-1 From 4ff686e375fcc2f38bbbc061f4067088c690ba7b Mon Sep 17 00:00:00 2001 From: abi Date: Tue, 7 May 2024 11:36:54 +0200 Subject: [PATCH 3/4] fixed the format arrow --- arrow-cast/src/cast/mod.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/arrow-cast/src/cast/mod.rs b/arrow-cast/src/cast/mod.rs index 92a9c06155f4..e3de351d8f24 100644 --- a/arrow-cast/src/cast/mod.rs +++ b/arrow-cast/src/cast/mod.rs @@ -8061,20 +8061,29 @@ mod tests { 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 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::(&array, &None::>, &cast_options); - + let result = cast_string_to_timestamp::( + &array, + &None::>, + &cast_options, + ); + assert!(result.is_err()); let err = result.unwrap_err(); - assert_eq!(err.to_string(), format!("Cast error: Overflow converting {} to Nanosecond. {}", array.value(0), EXPECTED_ERROR_MESSAGE)); + assert_eq!( + err.to_string(), + format!( + "Cast error: Overflow converting {} to Nanosecond. {}", + array.value(0), + EXPECTED_ERROR_MESSAGE + ) + ); } #[test] From 681a3bd709da2eba2cc6edd9bc7d9538176f7a41 Mon Sep 17 00:00:00 2001 From: abi Date: Tue, 14 May 2024 13:13:32 +0200 Subject: [PATCH 4/4] removed assert --- arrow-cast/src/cast/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/arrow-cast/src/cast/mod.rs b/arrow-cast/src/cast/mod.rs index e3de351d8f24..ccbc8727f7d9 100644 --- a/arrow-cast/src/cast/mod.rs +++ b/arrow-cast/src/cast/mod.rs @@ -8074,7 +8074,6 @@ mod tests { &cast_options, ); - assert!(result.is_err()); let err = result.unwrap_err(); assert_eq!( err.to_string(),