alamb commented on code in PR #12039:
URL: https://github.com/apache/datafusion/pull/12039#discussion_r1720948947
##########
datafusion/physical-plan/src/filter.rs:
##########
@@ -345,19 +360,55 @@ struct FilterExecStream {
input: SendableRecordBatchStream,
/// runtime metrics recording
baseline_metrics: BaselineMetrics,
+ /// Whether to allow an input batch to be returned unmodified in the case
where
+ /// the predicate evaluates to true for all rows in the batch
+ reuse_input_batches: bool,
}
pub(crate) fn batch_filter(
batch: &RecordBatch,
predicate: &Arc<dyn PhysicalExpr>,
+ reuse_input_batches: bool,
) -> Result<RecordBatch> {
predicate
.evaluate(batch)
.and_then(|v| v.into_array(batch.num_rows()))
.and_then(|array| {
Ok(match as_boolean_array(&array) {
// apply filter array to record batch
- Ok(filter_array) => filter_record_batch(batch, filter_array)?,
+ Ok(filter_array) => {
+ if reuse_input_batches {
+ filter_record_batch(batch, filter_array)?
+ } else {
+ if filter_array.true_count() == batch.num_rows() {
Review Comment:
Specifically, I think the `optimize` function would be a natural place to
put this:
https://docs.rs/arrow-select/52.2.0/src/arrow_select/filter.rs.html#181
##########
datafusion/physical-plan/src/filter.rs:
##########
@@ -345,19 +360,55 @@ struct FilterExecStream {
input: SendableRecordBatchStream,
/// runtime metrics recording
baseline_metrics: BaselineMetrics,
+ /// Whether to allow an input batch to be returned unmodified in the case
where
+ /// the predicate evaluates to true for all rows in the batch
+ reuse_input_batches: bool,
}
pub(crate) fn batch_filter(
batch: &RecordBatch,
predicate: &Arc<dyn PhysicalExpr>,
+ reuse_input_batches: bool,
) -> Result<RecordBatch> {
predicate
.evaluate(batch)
.and_then(|v| v.into_array(batch.num_rows()))
.and_then(|array| {
Ok(match as_boolean_array(&array) {
// apply filter array to record batch
- Ok(filter_array) => filter_record_batch(batch, filter_array)?,
+ Ok(filter_array) => {
+ if reuse_input_batches {
+ filter_record_batch(batch, filter_array)?
+ } else {
+ if filter_array.true_count() == batch.num_rows() {
+ // special case where we just make an exact copy
Review Comment:
I think I am missing something -- why go through all the effort with
`MutableArrayData`
In other words, why isn't thus simply
```rust
Ok(batch.clone())
```
To literally return the input batch?
I think that would be less code and faster
##########
datafusion/physical-plan/src/filter.rs:
##########
@@ -379,7 +430,8 @@ impl Stream for FilterExecStream {
match ready!(self.input.poll_next_unpin(cx)) {
Some(Ok(batch)) => {
let timer =
self.baseline_metrics.elapsed_compute().timer();
- let filtered_batch = batch_filter(&batch,
&self.predicate)?;
+ let filtered_batch =
Review Comment:
I recommend adding a test so we don't accidentally break the feature by
accident
--
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]