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


##########
arrow-select/src/filter.rs:
##########
@@ -368,6 +378,86 @@ fn filter_array(values: &dyn Array, predicate: 
&FilterPredicate) -> Result<Array
     }
 }
 
+fn filter_run_end_array<R: RunEndIndexType>(
+    ree_arr: &RunArray<R>,
+    pred: &FilterPredicate,
+) -> Result<ArrayRef, ArrowError> {
+    fn downcast_safe<A: RunEndIndexType, T: RunEndIndexType>(
+        re_arr: &RunArray<A>,
+    ) -> Option<&RunArray<T>> {
+        re_arr.as_any().downcast_ref::<RunArray<T>>()
+    }
+
+    if let Some(ree_array) = downcast_safe::<R, Int64Type>(ree_arr) {
+        let (run_ends, values) = filter_run_end_array_generic(ree_array, 
pred)?;
+        let ree_arr: RunArray<Int64Type> =
+            RunArray::try_new(&PrimitiveArray::from(run_ends), &values)?;
+        Ok(Arc::new(ree_arr))
+    } else if let Some(ree_array) = downcast_safe::<R, Int32Type>(ree_arr) {
+        let (run_ends, values) = filter_run_end_array_generic(ree_array, 
pred)?;
+        let ree_arr: RunArray<Int32Type> =
+            RunArray::try_new(&PrimitiveArray::from(run_ends), &values)?;
+        Ok(Arc::new(ree_arr))
+    } else if let Some(ree_array) = downcast_safe::<R, Int16Type>(ree_arr) {
+        let (run_ends, values) = filter_run_end_array_generic(ree_array, 
pred)?;
+        let ree_arr: RunArray<Int16Type> =
+            RunArray::try_new(&PrimitiveArray::from(run_ends), &values)?;
+        Ok(Arc::new(ree_arr))
+    } else {
+        Err(ArrowError::CastError(
+            "Run ends for RunArray must be i16 or i32 or i64".to_string(),
+        ))
+    }

Review Comment:
   ```rust
       let run_ends = PrimitiveArray::<R>::new(new_run_ends.into(), None);
       let ree_arr = RunArray::try_new(&run_ends, &new_values)?;
       let arr = Arc::new(ree_arr);
   ```
   
   Something like this should work, since `PrimitiveArray::new` uses 
`ScalarBuffer<<T as ArrowPrimitiveType>::Native>` which is exactly what you need
   
   - 
https://docs.rs/arrow/latest/arrow/array/struct.PrimitiveArray.html#method.new



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