Rich-T-kid commented on code in PR #9959:
URL: https://github.com/apache/arrow-rs/pull/9959#discussion_r3218912470
##########
arrow-array/src/array/run_array.rs:
##########
@@ -781,6 +762,45 @@ where
RunArrayIter::new(self)
}
}
+/// An array that can be downcast to a [`RunArray`] of any run end type and
any value type.
+///
+/// This can be used to efficiently implement kernels for all possible run end
+/// types without needing to create specialized implementations for each key
type.
+pub trait AnyRunEndArray: Array {
+ /// Returns the run ends of this array as a primitive array.
+ fn run_ends(&self) -> ArrayRef;
+
+ /// Returns the values of this array.
+ fn values(&self) -> Arc<dyn Array>;
+
+ /// Returns a new run-end encoded array with the given values, preserving
the
+ /// existing run ends.
+ fn with_values(&self, values: ArrayRef) -> ArrayRef;
+}
+
+impl<R: RunEndIndexType> AnyRunEndArray for RunArray<R> {
+ fn run_ends(&self) -> ArrayRef {
+ let data = unsafe {
+ ArrayDataBuilder::new(R::DATA_TYPE)
+ .len(self.run_ends.values().len())
+ .buffers(vec![self.run_ends.inner().inner().clone()])
+ .build_unchecked()
+ };
+ Arc::new(PrimitiveArray::<R>::from(data))
+ }
+
+ fn values(&self) -> Arc<dyn Array> {
+ self.values.clone()
+ }
+
+ fn with_values(&self, values: ArrayRef) -> ArrayRef {
Review Comment:
Im curious as to what invariants your referring to? for example, swapping
out the values with incorrect data types or `values.len()` mismatches?
--
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]