You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/04/13 01:01:52 UTC

[GitHub] [arrow-datafusion] yjshen commented on a diff in pull request #2218: Use `filter` (filter_record_batch) instead of `take` to avoid using indices

yjshen commented on code in PR #2218:
URL: https://github.com/apache/arrow-datafusion/pull/2218#discussion_r848981975


##########
datafusion/physical-expr/src/physical_expr.rs:
##########
@@ -51,24 +47,13 @@ pub trait PhysicalExpr: Send + Sync + Display + Debug {
         batch: &RecordBatch,
         selection: &BooleanArray,
     ) -> Result<ColumnarValue> {
-        if selection.iter().all(|b| b == Some(true)) {
-            return self.evaluate(batch);
-        }
-        let mut indices = vec![];
-        for (i, b) in selection.iter().enumerate() {
-            if let Some(true) = b {
-                indices.push(i as u64);
-            }
-        }
-        let indices = UInt64Array::from_iter_values(indices);
-        let tmp_columns = batch
-            .columns()
-            .iter()
-            .map(|c| take(c.as_ref(), &indices, None))
-            .collect::<ArrowResult<Vec<Arc<dyn Array>>>>()?;
-
-        let tmp_batch = RecordBatch::try_new(batch.schema(), tmp_columns)?;
+        let tmp_batch = filter_record_batch(batch, selection)?;

Review Comment:
   Cool, you do have a great sense of code smell!
   
   TIL the new `filter` kernel, it's great to read.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org