Skip to content

Commit

Permalink
Added cast for FixedSizeBinary to (Large)Binary (jorgecarleitao#1403)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored and jgmartin committed Feb 22, 2023
1 parent 8ddaaa0 commit bc3a407
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
25 changes: 5 additions & 20 deletions src/compute/cast/binary_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,29 +130,14 @@ fn fixed_size_to_offsets<O: Offset>(values_len: usize, fixed_size: usize) -> Off
unsafe { Offsets::new_unchecked(offsets) }
}

/// Conversion of large-binary
pub fn fixed_size_binary_to_large_binary(
/// Conversion of `FixedSizeBinary` to `Binary`.
pub fn fixed_size_binary_binary<O: Offset>(
from: &FixedSizeBinaryArray,
to_data_type: DataType,
) -> BinaryArray<i64> {
) -> BinaryArray<O> {
let values = from.values().clone();
let offsets = fixed_size_to_offsets(values.len(), from.fixed_size());
BinaryArray::<i64>::new(
to_data_type,
offsets.into(),
values,
from.validity().cloned(),
)
}

/// Conversion of binary
pub fn fixed_size_binary_to_binary(
from: &FixedSizeBinaryArray,
to_data_type: DataType,
) -> BinaryArray<i32> {
let values = from.values().clone();
let offsets = fixed_size_to_offsets(values.len(), from.fixed_size());
BinaryArray::<i32>::new(
let offsets = fixed_size_to_offsets(values.len(), from.size());
BinaryArray::<O>::new(
to_data_type,
offsets.into(),
values,
Expand Down
4 changes: 2 additions & 2 deletions src/compute/cast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,12 +687,12 @@ pub fn cast(array: &dyn Array, to_type: &DataType, options: CastOptions) -> Resu
))),
},
(FixedSizeBinary(_), _) => match to_type {
Binary => Ok(fixed_size_binary_to_binary(
Binary => Ok(fixed_size_binary_binary::<i32>(
array.as_any().downcast_ref().unwrap(),
to_type.clone(),
)
.boxed()),
LargeBinary => Ok(fixed_size_binary_to_large_binary(
LargeBinary => Ok(fixed_size_binary_binary::<i64>(
array.as_any().downcast_ref().unwrap(),
to_type.clone(),
)
Expand Down

0 comments on commit bc3a407

Please sign in to comment.