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]: Unknown input statistics in FilterExec #7544

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 28 additions & 0 deletions datafusion/common/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

use std::fmt::Display;

use arrow::datatypes::SchemaRef;

use crate::ScalarValue;

/// Statistics for a relation
Expand Down Expand Up @@ -70,3 +72,29 @@ pub struct ColumnStatistics {
/// Number of distinct values
pub distinct_count: Option<usize>,
}

impl ColumnStatistics {
/// Returns the [`Vec<ColumnStatistics>`] corresponding to the given schema by assigning
/// infinite bounds to each column in the schema. This is useful when even the input statistics
/// are not known, as the current executor can shrink the bounds of some columns.
pub fn new_with_unbounded_columns(schema: SchemaRef) -> Vec<ColumnStatistics> {
let data_types = schema
.fields()
.iter()
.map(|field| field.data_type())
.collect::<Vec<_>>();

data_types
.into_iter()
.map(|data_type| {
let dt = ScalarValue::try_from(data_type.clone()).ok();
ColumnStatistics {
null_count: None,
max_value: dt.clone(),
min_value: dt,
distinct_count: None,
}
})
.collect()
}
}
2 changes: 1 addition & 1 deletion datafusion/core/src/physical_plan/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl ExecutionPlan for FilterExec {
let input_stats = self.input.statistics();
let input_column_stats = match input_stats.column_statistics {
Some(stats) => stats,
None => return Statistics::default(),
None => ColumnStatistics::new_with_unbounded_columns(self.schema()),
};

let starter_ctx =
Expand Down