@@ -48,21 +48,21 @@ use datafusion_common::{
4848use datafusion_execution:: {
4949 object_store:: ObjectStoreUrl , SendableRecordBatchStream , TaskContext ,
5050} ;
51- use datafusion_physical_expr:: { expressions:: Column , utils:: reassign_predicate_columns} ;
52- use datafusion_physical_expr:: { EquivalenceProperties , Partitioning } ;
51+ use datafusion_expr:: Operator ;
52+ use datafusion_physical_expr:: expressions:: BinaryExpr ;
53+ use datafusion_physical_expr:: { expressions:: Column , utils:: reassign_expr_columns} ;
54+ use datafusion_physical_expr:: { split_conjunction, EquivalenceProperties , Partitioning } ;
5355use datafusion_physical_expr_adapter:: PhysicalExprAdapterFactory ;
5456use datafusion_physical_expr_common:: physical_expr:: PhysicalExpr ;
5557use datafusion_physical_expr_common:: sort_expr:: { LexOrdering , PhysicalSortExpr } ;
58+ use datafusion_physical_plan:: filter_pushdown:: FilterPushdownPropagation ;
5659use datafusion_physical_plan:: projection:: ProjectionExpr ;
5760use datafusion_physical_plan:: {
5861 display:: { display_orderings, ProjectSchemaDisplay } ,
5962 metrics:: ExecutionPlanMetricsSet ,
6063 projection:: { all_alias_free_columns, new_projections_for_columns} ,
6164 DisplayAs , DisplayFormatType ,
6265} ;
63- use datafusion_physical_plan:: {
64- filter:: collect_columns_from_predicate, filter_pushdown:: FilterPushdownPropagation ,
65- } ;
6666
6767use datafusion_physical_plan:: coop:: cooperative;
6868use datafusion_physical_plan:: execution_plan:: SchedulingType ;
@@ -588,27 +588,14 @@ impl DataSource for FileScanConfig {
588588 if let Some ( filter) = self . file_source . filter ( ) {
589589 // We need to remap column indexes to match the projected schema since that's what the equivalence properties deal with.
590590 // Note that this will *ignore* any non-projected columns: these don't factor into ordering / equivalence.
591- match reassign_predicate_columns ( filter, & schema, true ) {
592- Ok ( filter) => {
593- match Self :: add_filter_equivalence_info (
594- filter,
595- & mut eq_properties,
596- & schema,
597- ) {
598- Ok ( ( ) ) => { }
599- Err ( e) => {
600- warn ! ( "Failed to add filter equivalence info: {e}" ) ;
601- #[ cfg( debug_assertions) ]
602- panic ! ( "Failed to add filter equivalence info: {e}" ) ;
603- }
604- }
605- }
591+ match Self :: add_filter_equivalence_info ( filter, & mut eq_properties, & schema) {
592+ Ok ( ( ) ) => { }
606593 Err ( e) => {
607- warn ! ( "Failed to reassign predicate columns : {e}" ) ;
594+ warn ! ( "Failed to add filter equivalence info : {e}" ) ;
608595 #[ cfg( debug_assertions) ]
609- panic ! ( "Failed to reassign predicate columns : {e}" ) ;
596+ panic ! ( "Failed to add filter equivalence info : {e}" ) ;
610597 }
611- } ;
598+ }
612599 }
613600 eq_properties
614601 }
@@ -764,24 +751,24 @@ impl FileScanConfig {
764751 eq_properties : & mut EquivalenceProperties ,
765752 schema : & Schema ,
766753 ) -> Result < ( ) > {
767- macro_rules! ignore_dangling_col {
768- ( $col: expr) => {
769- if let Some ( col) = $col. as_any( ) . downcast_ref:: <Column >( ) {
770- if schema. index_of( col. name( ) ) . is_err( ) {
771- continue ;
754+ // Gather valid equality pairs from the filter expression
755+ let equal_pairs = split_conjunction ( & filter) . into_iter ( ) . filter_map ( |expr| {
756+ // Ignore any binary expressions that reference non-existent columns in the current schema
757+ // (e.g. due to unnecessary projections being removed)
758+ reassign_expr_columns ( Arc :: clone ( expr) , schema)
759+ . ok ( )
760+ . and_then ( |expr| match expr. as_any ( ) . downcast_ref :: < BinaryExpr > ( ) {
761+ Some ( expr) if expr. op ( ) == & Operator :: Eq => {
762+ Some ( ( Arc :: clone ( expr. left ( ) ) , Arc :: clone ( expr. right ( ) ) ) )
772763 }
773- }
774- } ;
775- }
764+ _ => None ,
765+ } )
766+ } ) ;
776767
777- let ( equal_pairs, _) = collect_columns_from_predicate ( & filter) ;
778768 for ( lhs, rhs) in equal_pairs {
779- // Ignore any binary expressions that reference non-existent columns in the current schema
780- // (e.g. due to unnecessary projections being removed)
781- ignore_dangling_col ! ( lhs) ;
782- ignore_dangling_col ! ( rhs) ;
783- eq_properties. add_equal_conditions ( Arc :: clone ( lhs) , Arc :: clone ( rhs) ) ?
769+ eq_properties. add_equal_conditions ( lhs, rhs) ?
784770 }
771+
785772 Ok ( ( ) )
786773 }
787774
0 commit comments