Skip to content

Commit 3d0efbc

Browse files
committed
impl take kernel for byte view array.
1 parent 9fda7ea commit 3d0efbc

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

arrow-array/src/cast.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,34 @@ pub trait AsArray: private::Sealed {
779779
self.as_bytes_opt().expect("binary array")
780780
}
781781

782+
/// Downcast this to a [`StringViewArray`] returning `None` if not possible
783+
fn as_string_view(&self) -> &StringViewArray {
784+
self.as_bytes_view_opt().expect("string view array")
785+
}
786+
787+
/// Downcast this to a [`StringViewArray`] returning `None` if not possible
788+
fn as_string_view_opt(&self) -> Option<&StringViewArray> {
789+
self.as_bytes_view_opt()
790+
}
791+
792+
/// Downcast this to a [`StringViewArray`] returning `None` if not possible
793+
fn as_binary_view(&self) -> &BinaryViewArray {
794+
self.as_bytes_view_opt().expect("binary view array")
795+
}
796+
797+
/// Downcast this to a [`BinaryViewArray`] returning `None` if not possible
798+
fn as_binary_view_opt(&self) -> Option<&BinaryViewArray> {
799+
self.as_bytes_view_opt()
800+
}
801+
802+
/// Downcast this to a [`GenericByteViewArray`] returning `None` if not possible
803+
fn as_bytes_view<T: ByteViewType>(&self) -> &GenericByteViewArray<T> {
804+
self.as_bytes_view_opt().expect("byte view array")
805+
}
806+
807+
/// Downcast this to a [`GenericByteViewArray`] returning `None` if not possible
808+
fn as_bytes_view_opt<T: ByteViewType>(&self) -> Option<&GenericByteViewArray<T>>;
809+
782810
/// Downcast this to a [`StructArray`] returning `None` if not possible
783811
fn as_struct_opt(&self) -> Option<&StructArray>;
784812

@@ -852,6 +880,10 @@ impl AsArray for dyn Array + '_ {
852880
self.as_any().downcast_ref()
853881
}
854882

883+
fn as_bytes_view_opt<T: ByteViewType>(&self) -> Option<&GenericByteViewArray<T>> {
884+
self.as_any().downcast_ref()
885+
}
886+
855887
fn as_struct_opt(&self) -> Option<&StructArray> {
856888
self.as_any().downcast_ref()
857889
}
@@ -899,6 +931,10 @@ impl AsArray for ArrayRef {
899931
self.as_ref().as_bytes_opt()
900932
}
901933

934+
fn as_bytes_view_opt<T: ByteViewType>(&self) -> Option<&GenericByteViewArray<T>> {
935+
self.as_ref().as_bytes_view_opt()
936+
}
937+
902938
fn as_struct_opt(&self) -> Option<&StructArray> {
903939
self.as_ref().as_struct_opt()
904940
}

arrow-select/src/take.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ fn take_impl<IndexType: ArrowPrimitiveType>(
143143
DataType::LargeUtf8 => {
144144
Ok(Arc::new(take_bytes(values.as_string::<i64>(), indices)?))
145145
}
146+
DataType::Utf8View => {
147+
Ok(Arc::new(take_byte_view(values.as_string_view(), indices)?))
148+
}
146149
DataType::List(_) => {
147150
Ok(Arc::new(take_list::<_, Int32Type>(values.as_list(), indices)?))
148151
}
@@ -204,6 +207,9 @@ fn take_impl<IndexType: ArrowPrimitiveType>(
204207
DataType::LargeBinary => {
205208
Ok(Arc::new(take_bytes(values.as_binary::<i64>(), indices)?))
206209
}
210+
DataType::BinaryView => {
211+
Ok(Arc::new(take_byte_view(values.as_binary_view(), indices)?))
212+
}
207213
DataType::FixedSizeBinary(size) => {
208214
let values = values
209215
.as_any()
@@ -437,6 +443,20 @@ fn take_bytes<T: ByteArrayType, IndexType: ArrowPrimitiveType>(
437443
Ok(GenericByteArray::from(array_data))
438444
}
439445

446+
/// `take` implementation for byte view arrays
447+
fn take_byte_view<T: ByteViewType, IndexType: ArrowPrimitiveType>(
448+
array: &GenericByteViewArray<T>,
449+
indices: &PrimitiveArray<IndexType>,
450+
) -> Result<GenericByteViewArray<T>, ArrowError> {
451+
let new_views = take_native(array.views(), indices);
452+
let new_nulls = take_nulls(array.nulls(), indices);
453+
Ok(GenericByteViewArray::new(
454+
new_views,
455+
array.data_buffers().to_vec(),
456+
new_nulls,
457+
))
458+
}
459+
440460
/// `take` implementation for list arrays
441461
///
442462
/// Calculates the index and indexed offset for the inner array,

0 commit comments

Comments
 (0)