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


##########
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(),
+        ))
+    }
+}
+
+/// Filter any supported [`RunArray`] based on a [`FilterPredicate`]
+#[allow(clippy::type_complexity)]
+fn filter_run_end_array_generic<R: RunEndIndexType>(
+    re_arr: &RunArray<R>,
+    pred: &FilterPredicate,

Review Comment:
   I guess we can leave a TODO item to utilize the `IterationStrategy` within 
`FilterPredicate` for potential performance benefit to keep this PR as more an 
initial version of filter for run end arrays?



##########
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:
   Is there a need to do this explicit downcasting if 
`filter_run_end_array_generic` is already generic over `RunEndIndexType`?



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