killme2008 commented on code in PR #27160:
URL: https://github.com/apache/datafusion/pull/27160#discussion_r4509571593
##########
datafusion/physical-expr/src/expressions/case.rs:
##########
@@ -385,6 +385,24 @@ fn filter_record_batch(
}
}
+fn take_case_rows<'a>(
+ batch: &'a RecordBatch,
+ indices: &dyn Array,
+) -> std::result::Result<Cow<'a, RecordBatch>, ArrowError> {
+ // These indices are an ordered subset of the original batch's rows.
+ if indices.len() == batch.num_rows() {
+ return Ok(Cow::Borrowed(batch));
+ }
+ let columns = arrow::compute::take_arrays(batch.columns(), indices, None)?;
+ Ok(Cow::Owned(RecordBatch::try_new_with_options(
+ batch.schema(),
+ columns,
+ &RecordBatchOptions::new()
+ .with_match_field_names(false)
+ .with_row_count(Some(indices.len())),
+ )?))
Review Comment:
The filter is relative to the remaining rows, but the indices refer to the
original batch. Using filter on the original batch would require a full-length
mask for each branch.
take uses the selected indices directly. This avoids copying unmatched rows
between branches.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]