friendlymatthew commented on code in PR #7141:
URL: https://github.com/apache/arrow-rs/pull/7141#discussion_r1962233471
##########
arrow-cast/src/cast/mod.rs:
##########
@@ -1806,55 +1806,63 @@ pub fn cast_with_options(
})?,
))
}
- (Date64, Timestamp(TimeUnit::Second, to_tz)) => Ok(Arc::new(
- array
+ (Date64, Timestamp(TimeUnit::Second, _)) => {
+ let array = array
.as_primitive::<Date64Type>()
- .unary::<_, TimestampSecondType>(|x| x / MILLISECONDS)
- .with_timezone_opt(to_tz.clone()),
- )),
- (Date64, Timestamp(TimeUnit::Millisecond, to_tz)) => Ok(Arc::new(
- array
+ .unary::<_, TimestampSecondType>(|x| x / MILLISECONDS);
+
+ cast_with_options(&array, to_type, cast_options)
+ }
Review Comment:
We can split into two arms if we don't like how we're eagerly recasting a
`Timestamp`.
```rust
(Date64, Timestamp(TimeUnit::Second, None)) => {
// single cast here
},
(Date64, Timestamp(TimeUnit::Second, Some(_))) => {
// first cast to Timestamp, then recast with time zone
}
```
##########
arrow-cast/src/cast/mod.rs:
##########
@@ -5228,6 +5236,29 @@ mod tests {
}};
}
+ #[test]
+ fn test_cast_date32_to_timestamp_and_timestamp_with_timezone() {
+ let tz = "+0545"; // UTC + 0545 is Asia/Kathmandu
+ let a = Date32Array::from(vec![Some(18628), None, 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>();
+ let string_array = cast(&c, &DataType::Utf8).unwrap();
+ let result = string_array.as_string::<i32>();
+ assert_eq!("2021-01-01T00:00:00+05:45", result.value(0));
+
+ let b = cast(&array, &DataType::Timestamp(TimeUnit::Second,
None)).unwrap();
+ let c = b.as_primitive::<TimestampSecondType>();
+ let string_array = cast(&c, &DataType::Utf8).unwrap();
+ let result = string_array.as_string::<i32>();
+ assert_eq!("2021-01-01T00:00:00", result.value(0));
+ }
Review Comment:
Proof that casting a `Date` to a `Timestamp` with/without time zones result
in the same string.
Not the biggest fan of this test case, would appreciate some comments if we
would want to a test case that compares the cast results (with/without time
zone).
--
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]