friendlymatthew commented on code in PR #7141:
URL: https://github.com/apache/arrow-rs/pull/7141#discussion_r1958789376
##########
arrow-cast/src/cast/mod.rs:
##########
@@ -5217,6 +5228,374 @@ mod tests {
}};
}
+ #[test]
+ fn test_cast_date32_to_timestamp_with_timezone() {
+ let tz = "+0545"; // UTC + 0545 is Asia/Kathmandu
+ let a = Date32Array::from(vec![Some(18628), Some(18993), None]); //
2021-1-1, 2022-1-1
+ let array = Arc::new(a) as ArrayRef;
+ let b = cast(
+ &array,
+ &DataType::Timestamp(TimeUnit::Second, Some(tz.into())),
+ )
+ .unwrap();
+ let c = b.as_primitive::<TimestampSecondType>();
+ assert_eq!(1609459200, c.value(0));
+ assert_eq!(1640995200, c.value(1));
+ assert!(c.is_null(2));
+
+ let expected = vec![
+ Some("2021-01-01 05:45:00.000000"),
+ Some("2022-01-01 05:45:00.000000"),
+ None,
+ ];
+
+ let ts_format = "%Y-%m-%d %H:%M:%S%.6f";
+ let cast_options = CastOptions {
+ safe: true,
+ format_options: FormatOptions::default()
+ .with_timestamp_format(Some(ts_format))
+ .with_timestamp_tz_format(Some(ts_format)),
+ };
+
+ assert_cast_timestamp_to_string!(
+ c,
+ DataType::Utf8View,
+ StringViewArray,
+ cast_options,
+ expected
+ );
+ assert_cast_timestamp_to_string!(c, DataType::Utf8, StringArray,
cast_options, expected);
+ assert_cast_timestamp_to_string!(
+ c,
+ DataType::LargeUtf8,
+ LargeStringArray,
+ cast_options,
+ expected
+ );
+ }
+
+ #[test]
+ fn test_cast_date32_to_timestamp_with_timezone_ms() {
+ let tz = "+0545"; // UTC + 0545 is Asia/Kathmandu
+ let a = Date32Array::from(vec![Some(18628), Some(18993), None]); //
2021-1-1, 2022-1-1
+ let array = Arc::new(a) as ArrayRef;
+ let b = cast(
+ &array,
+ &DataType::Timestamp(TimeUnit::Millisecond, Some(tz.into())),
+ )
+ .unwrap();
+ let c = b.as_primitive::<TimestampMillisecondType>();
+ assert_eq!(1609459200000, c.value(0));
+ assert_eq!(1640995200000, c.value(1));
+ assert!(c.is_null(2));
+
+ let expected = vec![
+ Some("2021-01-01 05:45:00.000000"),
+ Some("2022-01-01 05:45:00.000000"),
+ None,
+ ];
+
+ let ts_format = "%Y-%m-%d %H:%M:%S%.6f";
+ let cast_options = CastOptions {
+ safe: true,
+ format_options: FormatOptions::default()
+ .with_timestamp_format(Some(ts_format))
+ .with_timestamp_tz_format(Some(ts_format)),
+ };
+
+ assert_cast_timestamp_to_string!(
+ c,
+ DataType::Utf8View,
+ StringViewArray,
+ cast_options,
+ expected
+ );
+ assert_cast_timestamp_to_string!(c, DataType::Utf8, StringArray,
cast_options, expected);
+ assert_cast_timestamp_to_string!(
+ c,
+ DataType::LargeUtf8,
+ LargeStringArray,
+ cast_options,
+ expected
+ );
+ }
+
+ #[test]
+ fn test_cast_date32_to_timestamp_with_timezone_us() {
+ let tz = "+0545"; // UTC + 0545 is Asia/Kathmandu
+ let a = Date32Array::from(vec![Some(18628), Some(18993), None]); //
2021-1-1, 2022-1-1
+ let array = Arc::new(a) as ArrayRef;
+ let b = cast(
+ &array,
+ &DataType::Timestamp(TimeUnit::Microsecond, Some(tz.into())),
+ )
+ .unwrap();
+ let c = b.as_primitive::<TimestampMicrosecondType>();
Review Comment:
I'm confused what this comment means. `_us` stands for microsecond.
This test case is primarily concerned with casting dates to timestamps with
a `TimeUnit::Microsecond`. Here's a similar test case:
https://github.com/apache/arrow-rs/blob/38d6e691f4ee1b356f28d77b6820de67166c51c3/arrow-cast/src/cast/mod.rs#L8990-L9002
Here, we cast `c` as `TimestampMicrosecondType`.
--
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]