waitingkuo commented on code in PR #3016:
URL: https://github.com/apache/arrow-rs/pull/3016#discussion_r1018342109
##########
arrow-cast/src/cast.rs:
##########
@@ -4090,6 +4291,160 @@ mod tests {
assert!(c.is_null(2));
}
+ #[test]
+ fn test_cast_timestamp_to_time64() {
+ // test timestamp secs
+ let a = TimestampSecondArray::from(vec![Some(86405), Some(1), None])
+ .with_timezone("+01:00".to_string());
+ let array = Arc::new(a) as ArrayRef;
+ let b = cast(&array,
&DataType::Time64(TimeUnit::Microsecond)).unwrap();
+ let c = b.as_any().downcast_ref::<Time64MicrosecondArray>().unwrap();
+ assert_eq!(3605000000, c.value(0));
+ assert_eq!(3601000000, c.value(1));
+ assert!(c.is_null(2));
+ let b = cast(&array, &DataType::Time64(TimeUnit::Nanosecond)).unwrap();
+ let c = b.as_any().downcast_ref::<Time64NanosecondArray>().unwrap();
+ assert_eq!(3605000000000, c.value(0));
+ assert_eq!(3601000000000, c.value(1));
+ assert!(c.is_null(2));
Review Comment:
@tustvold
i used @naosense 's branch this is what i have
```rust
let a = TimestampSecondArray::from(vec![Some(86405), Some(1), None])
.with_timezone("+01:00".to_string());
let array = Arc::new(a) as ArrayRef;
let b = cast(&array,
&DataType::Time64(TimeUnit::Microsecond)).unwrap();
let c = b.as_any().downcast_ref::<Time64MicrosecondArray>().unwrap();
println!("{:?}", c);
```
outputs
```bash
PrimitiveArray<Time64(Microsecond)>
[
01:00:05,
01:00:01,
null,
]
```
while
```rust
let a = TimestampSecondArray::from(vec![Some(86405), Some(1), None])
.with_timezone("+01:00".to_string());
let array = Arc::new(a) as ArrayRef;
let b = cast(&array, &DataType::Timestamp(TimeUnit::Microsecond,
None)).unwrap();
let c = b.as_any().downcast_ref::<TimestampMicrosecondArray>().unwrap();
//println!("{:?}", b);
println!("{:?}", c);
```
outputs
```bash
PrimitiveArray<Timestamp(Microsecond, None)>
[
1970-01-02T00:00:05,
1970-01-01T00:00:01,
null,
]
```
--
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]