Jefffrey commented on code in PR #9959:
URL: https://github.com/apache/arrow-rs/pull/9959#discussion_r3216742263


##########
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:
   I think we need to do validation here otherwise it can break invariants



##########
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>;

Review Comment:
   Maybe we should return `&Arc<dyn Array>` here to let callers decide if they 
wanna clone? It'll fit with 
[`AnyDictionaryArray::values`](https://docs.rs/arrow/latest/arrow/array/trait.AnyDictionaryArray.html#tymethod.values)
 too



##########
arrow-array/src/array/run_array.rs:
##########
@@ -30,25 +30,6 @@ use crate::{
     types::{Int16Type, Int32Type, Int64Type, RunEndIndexType},
 };
 
-/// Recursively applies a function to the values of a RunEndEncoded array, 
preserving the run structure.
-///
-/// # Example
-///
-/// ```ignore
-/// let result = ree_recurse!(array, Int32Type, my_function)?;
-/// ```
-///
-/// This macro is useful for implementing functions that should work on the 
logical values
-/// of a REE array while preserving the run-end encoding structure.
-#[macro_export]
-macro_rules! ree_map {

Review Comment:
   Worth noting I think this is included in the upcoming `58.3.0` release so 
removing this would be a breaking change when that release goes live



-- 
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]

Reply via email to