@@ -60,7 +60,7 @@ use datafusion_common::{
60
60
use datafusion_expr:: execution_props:: ExecutionProps ;
61
61
use datafusion_expr:: logical_plan:: CreateExternalTable ;
62
62
use datafusion_expr:: simplify:: SimplifyContext ;
63
- use datafusion_expr:: utils:: conjunction;
63
+ use datafusion_expr:: utils:: { conjunction, split_conjunction } ;
64
64
use datafusion_expr:: {
65
65
col, BinaryExpr , Expr , Extension , LogicalPlan , Operator , TableProviderFilterPushDown ,
66
66
Volatility ,
@@ -565,6 +565,8 @@ impl<'a> DeltaScanBuilder<'a> {
565
565
let context = SessionContext :: new ( ) ;
566
566
let df_schema = logical_schema. clone ( ) . to_dfschema ( ) ?;
567
567
568
+ // TODO: extract to method and untangle pushdown filter from the full logical filter
569
+ let mut pushdown_filter = None ;
568
570
let logical_filter = self . filter . map ( |expr| {
569
571
// Simplify the expression first
570
572
let props = ExecutionProps :: new ( ) ;
@@ -573,6 +575,27 @@ impl<'a> DeltaScanBuilder<'a> {
573
575
let simplifier = ExprSimplifier :: new ( simplify_context) . with_max_cycles ( 10 ) ;
574
576
let simplified = simplifier. simplify ( expr) . unwrap ( ) ;
575
577
578
+ // FIXME: we probably want to do this before simplification
579
+ let predicates = split_conjunction ( & simplified) ;
580
+ let pushdown_filters =
581
+ get_pushdown_filters ( & predicates, self . snapshot . metadata ( ) . partition_columns . clone ( ) ) ;
582
+
583
+ let filtered_predicates = predicates
584
+ . into_iter ( )
585
+ . zip ( pushdown_filters. into_iter ( ) )
586
+ . filter_map ( |( filter, pushdown) | {
587
+ if pushdown == TableProviderFilterPushDown :: Inexact {
588
+ Some ( filter. clone ( ) )
589
+ } else {
590
+ None
591
+ }
592
+ } ) ;
593
+ let pushdown_filter = conjunction ( filtered_predicates) . map ( |e| {
594
+ context
595
+ . create_physical_expr ( e, & df_schema)
596
+ . unwrap ( )
597
+ } ) ;
598
+
576
599
context
577
600
. create_physical_expr ( simplified, & df_schema)
578
601
. unwrap ( )
@@ -728,7 +751,7 @@ impl<'a> DeltaScanBuilder<'a> {
728
751
// Sometimes (i.e Merge) we want to prune files that don't make the
729
752
// filter and read the entire contents for files that do match the
730
753
// filter
731
- if let Some ( predicate) = logical_filter {
754
+ if let Some ( predicate) = pushdown_filter {
732
755
if config. enable_parquet_pushdown {
733
756
file_source = file_source. with_predicate ( Arc :: clone ( & file_schema) , predicate) ;
734
757
}
0 commit comments