Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor: use ready! macro to simplify FilterExec #11649

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions datafusion/physical-plan/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use std::any::Any;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
use std::task::{ready, Context, Poll};

use super::{
ColumnStatistics, DisplayAs, ExecutionPlanProperties, PlanProperties,
Expand Down Expand Up @@ -59,6 +59,7 @@ pub struct FilterExec {
metrics: ExecutionPlanMetricsSet,
/// Selectivity for statistics. 0 = no rows, 100 = all rows
default_selectivity: u8,
/// Properties equivalence properties, partitioning, etc.
cache: PlanProperties,
}

Expand Down Expand Up @@ -375,26 +376,20 @@ impl Stream for FilterExecStream {
) -> Poll<Option<Self::Item>> {
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;
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)?;
// skip entirely filtered batches
if filtered_batch.num_rows() == 0 {
continue;
}
_ => {
poll = Poll::Ready(value);
break;
}
},
Poll::Pending => {
poll = Poll::Pending;
timer.done();
poll = Poll::Ready(Some(Ok(filtered_batch)));
break;
}
value => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ready! macro returns if the poll is not ready: https://doc.rust-lang.org/std/task/macro.ready.html

This does skip calling baseline_metrics.record_poll below, however, that doesn't do anything with PollPending:
https://docs.rs/datafusion-physical-plan/40.0.0/src/datafusion_physical_plan/metrics/baseline.rs.html#127

poll = Poll::Ready(value);
break;
}
}
Expand Down