-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implement AnyRee #9959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Implement AnyRee #9959
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -245,15 +245,22 @@ impl<R: RunEndIndexType> RunArray<R> { | |||||||||||||||||||||||||||||
| /// assert_eq!(new_run_array.run_ends().values(), &[2, 3, 5]); | ||||||||||||||||||||||||||||||
| /// ``` | ||||||||||||||||||||||||||||||
| pub fn with_values(&self, values: ArrayRef) -> Self { | ||||||||||||||||||||||||||||||
| assert_eq!(values.len(), self.values().len()); | ||||||||||||||||||||||||||||||
| assert_eq!(values.len(), self.values.len()); | ||||||||||||||||||||||||||||||
| let (run_ends_field, values_field) = match &self.data_type { | ||||||||||||||||||||||||||||||
| DataType::RunEndEncoded(r, v) => (r, v), | ||||||||||||||||||||||||||||||
| DataType::RunEndEncoded(r, v) => ( | ||||||||||||||||||||||||||||||
| r, | ||||||||||||||||||||||||||||||
| Arc::new( | ||||||||||||||||||||||||||||||
| v.as_ref() | ||||||||||||||||||||||||||||||
| .clone() | ||||||||||||||||||||||||||||||
| .with_data_type(values.data_type().clone()), | ||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||
| _ => unreachable!("RunArray should have type RunEndEncoded"), | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
| let data_type = | ||||||||||||||||||||||||||||||
| DataType::RunEndEncoded(Arc::clone(run_ends_field), Arc::clone(values_field)); | ||||||||||||||||||||||||||||||
| let dt = DataType::RunEndEncoded(Arc::clone(run_ends_field), Arc::clone(&values_field)); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Self { | ||||||||||||||||||||||||||||||
| data_type, | ||||||||||||||||||||||||||||||
| data_type: dt, | ||||||||||||||||||||||||||||||
| run_ends: self.run_ends.clone(), | ||||||||||||||||||||||||||||||
| values, | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
@@ -781,6 +788,41 @@ 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 | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| fn with_values(&self, values: ArrayRef) -> ArrayRef { | ||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I just realized we could have delegated to the existing arrow-rs/arrow-array/src/array/run_array.rs Lines 247 to 260 in 7abb225
Though it looks like it also doesn't verify the incoming values has the correct datatype 😬
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmmm, I'll replace the current |
||||||||||||||||||||||||||||||
| Arc::new(RunArray::<R>::with_values(self, values)) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| #[cfg(test)] | ||||||||||||||||||||||||||||||
| mod tests { | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.