@@ -52,18 +52,20 @@ use datafusion_common::{
52
52
use datafusion_execution:: {
53
53
object_store:: ObjectStoreUrl , SendableRecordBatchStream , TaskContext ,
54
54
} ;
55
- use datafusion_physical_expr:: expressions:: Column ;
55
+ use datafusion_physical_expr:: { expressions:: Column , utils :: reassign_predicate_columns } ;
56
56
use datafusion_physical_expr:: { EquivalenceProperties , Partitioning } ;
57
57
use datafusion_physical_expr_adapter:: PhysicalExprAdapterFactory ;
58
58
use datafusion_physical_expr_common:: physical_expr:: PhysicalExpr ;
59
59
use datafusion_physical_expr_common:: sort_expr:: { LexOrdering , PhysicalSortExpr } ;
60
- use datafusion_physical_plan:: filter_pushdown:: FilterPushdownPropagation ;
61
60
use datafusion_physical_plan:: {
62
61
display:: { display_orderings, ProjectSchemaDisplay } ,
63
62
metrics:: ExecutionPlanMetricsSet ,
64
63
projection:: { all_alias_free_columns, new_projections_for_columns, ProjectionExec } ,
65
64
DisplayAs , DisplayFormatType , ExecutionPlan ,
66
65
} ;
66
+ use datafusion_physical_plan:: {
67
+ filter:: collect_columns_from_predicate, filter_pushdown:: FilterPushdownPropagation ,
68
+ } ;
67
69
68
70
use datafusion_physical_plan:: coop:: cooperative;
69
71
use datafusion_physical_plan:: execution_plan:: SchedulingType ;
@@ -577,8 +579,31 @@ impl DataSource for FileScanConfig {
577
579
578
580
fn eq_properties ( & self ) -> EquivalenceProperties {
579
581
let ( schema, constraints, _, orderings) = self . project ( ) ;
580
- EquivalenceProperties :: new_with_orderings ( schema, orderings)
581
- . with_constraints ( constraints)
582
+ let mut eq_properties =
583
+ EquivalenceProperties :: new_with_orderings ( Arc :: clone ( & schema) , orderings)
584
+ . with_constraints ( constraints) ;
585
+ if let Some ( filter) = self . file_source . filter ( ) {
586
+ // We need to remap column indexes to match the projected schema since that's what the equivalence properties deal with.
587
+ // Note that this will *ignore* any non-projected columns: these don't factor into ordering / equivalence.
588
+ match reassign_predicate_columns ( filter, & schema, true ) {
589
+ Ok ( filter) => {
590
+ match Self :: add_filter_equivalence_info ( filter, & mut eq_properties) {
591
+ Ok ( ( ) ) => { }
592
+ Err ( e) => {
593
+ warn ! ( "Failed to add filter equivalence info: {e}" ) ;
594
+ #[ cfg( debug_assertions) ]
595
+ panic ! ( "Failed to add filter equivalence info: {e}" ) ;
596
+ }
597
+ }
598
+ }
599
+ Err ( e) => {
600
+ warn ! ( "Failed to reassign predicate columns: {e}" ) ;
601
+ #[ cfg( debug_assertions) ]
602
+ panic ! ( "Failed to reassign predicate columns: {e}" ) ;
603
+ }
604
+ } ;
605
+ }
606
+ eq_properties
582
607
}
583
608
584
609
fn scheduling_type ( & self ) -> SchedulingType {
@@ -724,6 +749,17 @@ impl FileScanConfig {
724
749
) )
725
750
}
726
751
752
+ fn add_filter_equivalence_info (
753
+ filter : Arc < dyn PhysicalExpr > ,
754
+ eq_properties : & mut EquivalenceProperties ,
755
+ ) -> Result < ( ) > {
756
+ let ( equal_pairs, _) = collect_columns_from_predicate ( & filter) ;
757
+ for ( lhs, rhs) in equal_pairs {
758
+ eq_properties. add_equal_conditions ( Arc :: clone ( lhs) , Arc :: clone ( rhs) ) ?
759
+ }
760
+ Ok ( ( ) )
761
+ }
762
+
727
763
pub fn projected_constraints ( & self ) -> Constraints {
728
764
let indexes = self . projection_indices ( ) ;
729
765
self . constraints . project ( & indexes) . unwrap_or_default ( )
0 commit comments