Try to create a new instance of [`PruningPredicate`] This will translate the provided `expr` filter expression into a *pruning predicate*. A pruning predicate is one that has been rewritten in terms of the min and max values of column references and that evaluates to FALSE if the filter predicate would evaluate FALSE *for every row* whose values fell within the min / max ranges (aka could be pru
(mut expr: Arc<dyn PhysicalExpr>, schema: SchemaRef)
| 461 | /// It is recommended that you pass the expressions through [`PhysicalExprSimplifier`] |
| 462 | /// before calling this method to make sure the expressions can be used for pruning. |
| 463 | pub fn try_new(mut expr: Arc<dyn PhysicalExpr>, schema: SchemaRef) -> Result<Self> { |
| 464 | // Get a (simpler) snapshot of the physical expr here to use with `PruningPredicate`. |
| 465 | // In particular this unravels any `DynamicFilterPhysicalExpr`s by snapshotting them |
| 466 | // so that PruningPredicate can work with a static expression. |
| 467 | let tf = snapshot_physical_expr_opt(expr)?; |
| 468 | if tf.transformed { |
| 469 | // If we had an expression such as Dynamic(part_col < 5 and col < 10) |
| 470 | // (this could come from something like `select * from t order by part_col, col, limit 10`) |
| 471 | // after snapshotting and because `DynamicFilterPhysicalExpr` applies child replacements to its |
| 472 | // children after snapshotting and previously `replace_columns_with_literals` may have been called with partition values |
| 473 | // the expression we have now is `8 < 5 and col < 10`. |
| 474 | // Thus we need as simplifier pass to get `false and col < 10` => `false` here. |
| 475 | let simplifier = PhysicalExprSimplifier::new(&schema); |
| 476 | expr = simplifier.simplify(tf.data)?; |
| 477 | } else { |
| 478 | expr = tf.data; |
| 479 | } |
| 480 | let unhandled_hook = Arc::new(ConstantUnhandledPredicateHook::default()) as _; |
| 481 | |
| 482 | // build predicate expression once |
| 483 | let mut required_columns = RequiredColumns::new(); |
| 484 | let predicate_expr = build_predicate_expression( |
| 485 | &expr, |
| 486 | &schema, |
| 487 | &mut required_columns, |
| 488 | &unhandled_hook, |
| 489 | ); |
| 490 | let predicate_schema = required_columns.schema(); |
| 491 | // Simplify the newly created predicate to get rid of redundant casts, comparisons, etc. |
| 492 | let predicate_expr = |
| 493 | PhysicalExprSimplifier::new(&predicate_schema).simplify(predicate_expr)?; |
| 494 | let literal_guarantees = LiteralGuarantee::analyze(&expr); |
| 495 | |
| 496 | Ok(Self { |
| 497 | schema, |
| 498 | predicate_expr, |
| 499 | required_columns, |
| 500 | orig_expr: expr, |
| 501 | literal_guarantees, |
| 502 | }) |
| 503 | } |
| 504 | |
| 505 | /// For each set of statistics, evaluates the pruning predicate |
| 506 | /// and returns a `bool` with the following meaning for a |
nothing calls this directly
no test coverage detected