diff --git a/datafusion/core/src/physical_optimizer/pruning.rs b/datafusion/core/src/physical_optimizer/pruning.rs index 5671345d8a099..420744e028d8d 100644 --- a/datafusion/core/src/physical_optimizer/pruning.rs +++ b/datafusion/core/src/physical_optimizer/pruning.rs @@ -526,26 +526,14 @@ impl PruningPredicate { /// /// See the struct level documentation on [`PruningPredicate`] for more /// details. - pub fn try_new(expr: Arc, schema: SchemaRef) -> Result { + pub fn try_new( + expr: Arc, + schema: SchemaRef, + ) -> Result { let unhandled_hook = Arc::new(ConstantUnhandledPredicateHook::new(Arc::new( phys_expr::Literal::new(ScalarValue::Boolean(Some(true))), ))); - Self::try_new_with_unhandled_hook(expr, schema, unhandled_hook) - } - /// Try to create a new instance of [`PruningPredicate`] with a custom - /// unhandled hook. - /// - /// This is the same as [`PruningPredicate::try_new`] but allows for a custom - /// hook to be used when a predicate can not be handled by DataFusion's - /// transformation rules or is referencing a column that is not in the schema. - /// - /// By default, a constant `true` is returned for unhandled predicates. - pub fn try_new_with_unhandled_hook( - expr: Arc, - schema: SchemaRef, - unhandled_hook: Arc, - ) -> Result { // build predicate expression once let mut required_columns = RequiredColumns::new(); let predicate_expr = build_predicate_expression( @@ -1363,11 +1351,13 @@ const MAX_LIST_VALUE_SIZE_REWRITE: usize = 20; /// Translate logical filter expression into pruning predicate /// expression that will evaluate to FALSE if it can be determined no /// rows between the min/max values could pass the predicates. +/// +/// Any predicates that can not be translated will be passed to `unhandled_hook`. /// /// Returns the pruning predicate as an [`PhysicalExpr`] /// -/// Notice: Does not handle [`phys_expr::InListExpr`] greater than 20, which will be rewritten to TRUE -fn build_predicate_expression( +/// Notice: Does not handle [`phys_expr::InListExpr`] greater than 20, which will fall back to calling `unhandled_hook` +pub fn build_predicate_expression( expr: &Arc, schema: &Schema, required_columns: &mut RequiredColumns, @@ -3465,20 +3455,18 @@ mod tests { if let Some(column) = left.as_any().downcast_ref::() { - if column.name() == "b" - && right - .as_any() - .downcast_ref::() - .is_some() - { - let new_column = - Arc::new(phys_expr::Column::new("c", column.index())) - as _; - return Arc::new(phys_expr::BinaryExpr::new( - new_column, - *expr.op(), - right.clone(), - )); + if column.name() == "b" { + if right.as_any().downcast_ref::().is_some() + { + let new_column = + Arc::new(phys_expr::Column::new("c", column.index())) + as _; + return Arc::new(phys_expr::BinaryExpr::new( + new_column, + *expr.op(), + right.clone(), + )); + } } } }