Skip to content

Commit

Permalink
Use existing array type in take kernel (#1046)
Browse files Browse the repository at this point in the history
* Need to use type from data so that we do not lose, for example, timezone information

* add test for take preseving timezone
  • Loading branch information
maxburke committed Dec 17, 2021
1 parent fc343e7 commit 2d28534
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion arrow/src/compute/kernels/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ where

let data = unsafe {
ArrayData::new_unchecked(
T::DATA_TYPE,
values.data_type().clone(),
indices.len(),
None,
nulls,
Expand Down Expand Up @@ -1241,6 +1241,23 @@ mod tests {
.unwrap();
}

#[test]
fn test_take_preserve_timezone() {
let index = Int64Array::from(vec![Some(0), None]);

let input = TimestampNanosecondArray::from_vec(
vec![1_639_715_368_000_000_000, 1_639_715_368_000_000_000],
Some("UTC".to_owned()),
);
let result = take_impl(&input, &index, None).unwrap();
match result.data_type() {
DataType::Timestamp(TimeUnit::Nanosecond, tz) => {
assert_eq!(tz.clone(), Some("UTC".to_owned()))
}
_ => panic!(),
}
}

#[test]
fn test_take_impl_primitive_with_int64_indices() {
let index = Int64Array::from(vec![Some(3), None, Some(1), Some(3), Some(2)]);
Expand Down

0 comments on commit 2d28534

Please sign in to comment.