Skip to content

Commit 5a5fa91

Browse files
committed
Move PruningPredicate to physical-optimizer crate
1 parent 300a08c commit 5a5fa91

File tree

6 files changed

+25
-18
lines changed

6 files changed

+25
-18
lines changed

datafusion/core/src/physical_optimizer/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ pub mod join_selection;
2929
pub mod limited_distinct_aggregation;
3030
pub mod optimizer;
3131
pub mod projection_pushdown;
32-
pub mod pruning;
3332
pub mod replace_with_order_preserving_variants;
3433
pub mod sanity_checker;
3534
#[cfg(test)]

datafusion/expr-common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
[package]
1919
name = "datafusion-expr-common"
20-
description = "Logical plan and expression representation for DataFusion query engine"
20+
description = "Common types and traits for plan and expression representation for DataFusion query engine"
2121
keywords = ["datafusion", "logical", "plan", "expressions"]
2222
readme = "README.md"
2323
version = { workspace = true }

datafusion/expr-common/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717

1818
//! Logical Expr types and traits for [DataFusion]
1919
//!
20-
//! This crate contains types and traits that are used by both Logical and Physical expressions.
21-
//! They are kept in their own crate to avoid physical expressions depending on logical expressions.
22-
//!
20+
//! This crate contains types and traits that are used by both Logical and
21+
//! Physical expressions. They are kept in their own crate to avoid physical
22+
//! expressions depending on logical expressions.
23+
//!
24+
//! Note this crate is not intended to have substantial logic itself, but rather
25+
//! to provide a common set of types and traits that can be used by both logical
26+
//! and physical expressions.
2327
//!
2428
//! [DataFusion]: <https://crates.io/crates/datafusion>
2529
@@ -34,3 +38,5 @@ pub mod operator;
3438
pub mod signature;
3539
pub mod sort_properties;
3640
pub mod type_coercion;
41+
42+
pub use operator::Operator;

datafusion/physical-optimizer/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ rust-version = { workspace = true }
3232
workspace = true
3333

3434
[dependencies]
35+
arrow = { workspace = true }
3536
datafusion-common = { workspace = true, default-features = true }
3637
datafusion-execution = { workspace = true }
38+
datafusion-expr-common = { workspace = true }
3739
datafusion-physical-expr = { workspace = true }
3840
datafusion-physical-plan = { workspace = true }
41+
log = { workspace = true }

datafusion/physical-optimizer/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ mod optimizer;
2323
pub mod output_requirements;
2424

2525
pub use optimizer::PhysicalOptimizerRule;
26+
27+
pub mod pruning;

datafusion/core/src/physical_optimizer/pruning.rs renamed to datafusion/physical-optimizer/src/pruning.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,24 @@
2222
use std::collections::HashSet;
2323
use std::sync::Arc;
2424

25-
use crate::{
26-
common::{Column, DFSchema},
27-
error::{DataFusionError, Result},
28-
logical_expr::Operator,
29-
physical_plan::{ColumnarValue, PhysicalExpr},
30-
};
31-
25+
use arrow::array::AsArray;
3226
use arrow::{
3327
array::{new_null_array, ArrayRef, BooleanArray},
3428
datatypes::{DataType, Field, Schema, SchemaRef},
3529
record_batch::{RecordBatch, RecordBatchOptions},
3630
};
37-
use arrow_array::cast::AsArray;
3831
use datafusion_common::tree_node::TransformedResult;
3932
use datafusion_common::{
4033
internal_err, plan_datafusion_err, plan_err,
4134
tree_node::{Transformed, TreeNode},
42-
ScalarValue,
35+
Column, DFSchema, ScalarValue,
4336
};
37+
use datafusion_common::{DataFusionError, Result};
4438
use datafusion_physical_expr::utils::{collect_columns, Guarantee, LiteralGuarantee};
45-
use datafusion_physical_expr::{expressions as phys_expr, PhysicalExprRef};
39+
use datafusion_physical_expr::{expressions as phys_expr, PhysicalExpr, PhysicalExprRef};
4640

41+
use datafusion_expr_common::operator::Operator;
42+
use datafusion_physical_plan::ColumnarValue;
4743
use log::trace;
4844

4945
/// A source of runtime statistical information to [`PruningPredicate`]s.
@@ -615,7 +611,8 @@ impl PruningPredicate {
615611
is_always_true(&self.predicate_expr) && self.literal_guarantees.is_empty()
616612
}
617613

618-
pub(crate) fn required_columns(&self) -> &RequiredColumns {
614+
/// Return the columns that are required to evaluate the pruning predicate
615+
pub fn required_columns(&self) -> &RequiredColumns {
619616
&self.required_columns
620617
}
621618

@@ -724,7 +721,7 @@ fn is_always_true(expr: &Arc<dyn PhysicalExpr>) -> bool {
724721
/// Handles creating references to the min/max statistics
725722
/// for columns as well as recording which statistics are needed
726723
#[derive(Debug, Default, Clone)]
727-
pub(crate) struct RequiredColumns {
724+
pub struct RequiredColumns {
728725
/// The statistics required to evaluate this predicate:
729726
/// * The unqualified column in the input schema
730727
/// * Statistics type (e.g. Min or Max or Null_Count)
@@ -746,7 +743,7 @@ impl RequiredColumns {
746743
/// * `a > 5 OR a < 10` returns `Some(a)`
747744
/// * `a > 5 OR b < 10` returns `None`
748745
/// * `true` returns None
749-
pub(crate) fn single_column(&self) -> Option<&phys_expr::Column> {
746+
pub fn single_column(&self) -> Option<&phys_expr::Column> {
750747
if self.columns.windows(2).all(|w| {
751748
// check if all columns are the same (ignoring statistics and field)
752749
let c1 = &w[0].0;

0 commit comments

Comments
 (0)