Skip to content

Commit

Permalink
Optimize filter executor in pull-based executor (#4421)
Browse files Browse the repository at this point in the history
* optimzie filter executor

* Update datafusion/core/src/physical_plan/filter.rs

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
  • Loading branch information
xudong963 and alamb authored Nov 30, 2022
1 parent fdc83e8 commit 522a2a4
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions datafusion/core/src/physical_plan/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,32 @@ impl Stream for FilterExecStream {
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>> {
let poll = self.input.poll_next_unpin(cx).map(|x| match x {
Some(Ok(batch)) => {
let timer = self.baseline_metrics.elapsed_compute().timer();
let filtered_batch = batch_filter(&batch, &self.predicate);
timer.done();
Some(filtered_batch)
let poll;
loop {
match self.input.poll_next_unpin(cx) {
Poll::Ready(value) => match value {
Some(Ok(batch)) => {
let timer = self.baseline_metrics.elapsed_compute().timer();
let filtered_batch = batch_filter(&batch, &self.predicate)?;
// skip entirely filtered batches
if filtered_batch.num_rows() == 0 {
continue;
}
timer.done();
poll = Poll::Ready(Some(Ok(filtered_batch)));
break;
}
_ => {
poll = Poll::Ready(value);
break;
}
},
Poll::Pending => {
poll = Poll::Pending;
break;
}
}
other => other,
});
}
self.baseline_metrics.record_poll(poll)
}

Expand Down

0 comments on commit 522a2a4

Please sign in to comment.