alamb commented on code in PR #9891:
URL: https://github.com/apache/arrow-rs/pull/9891#discussion_r3184395345
##########
arrow-array/src/array/run_array.rs:
##########
@@ -200,6 +219,24 @@ impl<R: RunEndIndexType> RunArray<R> {
&self.values
}
+ /// Returns a new [`RunArray`] with the same `run_ends` and the supplied
`values`.
+ ///
+ /// # Panics
Review Comment:
It would be great (as a follow on PR) if we could add a doc example here
too showing how to use this API
##########
arrow-array/src/array/run_array.rs:
##########
@@ -30,6 +30,25 @@ 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_recurse {
Review Comment:
I wonder if `ree_map!` would be a better name for this macro as it is
mapping one value to another -- and that might be more consistent with the
`map` uses in other Rust APIs
##########
arrow-array/src/array/run_array.rs:
##########
@@ -200,6 +219,24 @@ impl<R: RunEndIndexType> RunArray<R> {
&self.values
}
+ /// Returns a new [`RunArray`] with the same `run_ends` and the supplied
`values`.
+ ///
+ /// # Panics
+ ///
+ /// Panics if `values.len()` does not equal the existing run count.
+ pub fn with_values(&self, values: ArrayRef) -> Self {
+ assert_eq!(values.len(), self.values.len());
+ let data_type = DataType::RunEndEncoded(
+ Arc::new(Field::new("run_ends", R::DATA_TYPE, false)),
Review Comment:
I think we should be able to use the existing Fields and types here rather
than creating our own rather than create a new one (which also allocates a
string etc)
Something like
```rust
let new_datatype = match self.data_type {
DataType::RunEndEncoded(run_ends_type, +) => Arc::clone(run_ends_type),
_ => panic!("RunArray should have type RunEndEncoded");
}
let data_type = DataType::RunEndEncoded(run_ends_type, ...)
```
##########
arrow-arith/src/temporal.rs:
##########
@@ -194,6 +195,15 @@ pub fn date_part(array: &dyn Array, part: DatePart) ->
Result<ArrayRef, ArrowErr
let new_array = array.with_values(values);
Ok(new_array)
}
+ DataType::RunEndEncoded(k, _) => match k.data_type() {
Review Comment:
This is unrelated to adding `with_values`, right? It is adding REE support
to date_part 🤔
--
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]