Skip to content

Commit

Permalink
Add FixedSizedList[1] => FixeSizedList[1] tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sadboy committed May 17, 2024
1 parent 3428ad5 commit 76a085b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions arrow-cast/src/cast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6677,6 +6677,46 @@ mod tests {
let expected = Int32Array::from(vec![Some(5)]);
assert_eq!(&expected, actual);

// FixedSizeList<T>[1] => FixedSizeList<U>[1]
let from_array = Arc::new(FixedSizeListArray::from_iter_primitive::<Int16Type, _, _>(
[(Some([Some(5)]))],
1,
)) as ArrayRef;
let to_field = Arc::new(Field::new("dummy", DataType::Float32, false));
let actual = cast(&from_array, &DataType::FixedSizeList(to_field.clone(), 1)).unwrap();
let expected = Arc::new(FixedSizeListArray::new(
to_field.clone(),
1,
Arc::new(Float32Array::from(vec![Some(5.0)])) as ArrayRef,
None,
)) as ArrayRef;
assert_eq!(*expected, *actual);

// FixedSizeList<T>[1] => FixedSizeList<FixdSizedList<U>[1]>[1]
let from_array = Arc::new(FixedSizeListArray::from_iter_primitive::<Int16Type, _, _>(
[(Some([Some(5)]))],
1,
)) as ArrayRef;
let to_field_inner = Arc::new(Field::new("item", DataType::Float32, false));
let to_field = Arc::new(Field::new(
"dummy",
DataType::FixedSizeList(to_field_inner.clone(), 1),
false,
));
let actual = cast(&from_array, &DataType::FixedSizeList(to_field.clone(), 1)).unwrap();
let expected = Arc::new(FixedSizeListArray::new(
to_field.clone(),
1,
Arc::new(FixedSizeListArray::new(
to_field_inner.clone(),
1,
Arc::new(Float32Array::from(vec![Some(5.0)])) as ArrayRef,
None,
)) as ArrayRef,
None,
)) as ArrayRef;
assert_eq!(*expected, *actual);

// T => FixedSizeList<T>[1] (non-nullable)
let field = Arc::new(Field::new("dummy", DataType::Float32, false));
let from_array = Arc::new(Int8Array::from(vec![Some(5)])) as ArrayRef;
Expand Down

0 comments on commit 76a085b

Please sign in to comment.