@@ -814,12 +814,40 @@ impl EquivalenceGroup {
814814
815815 /// Combine equivalence groups of the given join children.
816816 pub fn join (
817+ & self ,
818+ right_equivalences : & Self ,
819+ join_type : & JoinType ,
820+ left_size : usize ,
821+ on : & [ ( PhysicalExprRef , PhysicalExprRef ) ] ,
822+ ) -> Result < Self > {
823+ self . join_with_optional_schema ( right_equivalences, join_type, left_size, None , on)
824+ }
825+
826+ /// Combine equivalence groups for a join with its output schema available.
827+ pub ( crate ) fn join_with_schema (
817828 & self ,
818829 right_equivalences : & Self ,
819830 join_type : & JoinType ,
820831 left_size : usize ,
821832 join_schema : & SchemaRef ,
822833 on : & [ ( PhysicalExprRef , PhysicalExprRef ) ] ,
834+ ) -> Result < Self > {
835+ self . join_with_optional_schema (
836+ right_equivalences,
837+ join_type,
838+ left_size,
839+ Some ( join_schema) ,
840+ on,
841+ )
842+ }
843+
844+ fn join_with_optional_schema (
845+ & self ,
846+ right_equivalences : & Self ,
847+ join_type : & JoinType ,
848+ left_size : usize ,
849+ join_schema : Option < & SchemaRef > ,
850+ on : & [ ( PhysicalExprRef , PhysicalExprRef ) ] ,
823851 ) -> Result < Self > {
824852 let group = match join_type {
825853 JoinType :: Inner | JoinType :: Left | JoinType :: Full | JoinType :: Right => {
@@ -836,21 +864,25 @@ impl EquivalenceGroup {
836864 // null-extended row; expressions such as coalesce(a, 0) do
837865 // not, even when they were equivalent to a column before the
838866 // join.
839- match join_type {
840- JoinType :: Left => {
841- right = right
842- . with_null_preserving_expressions ( & null_batch ( join_schema) ?) ;
843- }
844- JoinType :: Right => {
845- left = left
846- . with_null_preserving_expressions ( & null_batch ( join_schema) ?) ;
867+ if let Some ( join_schema) = join_schema {
868+ match join_type {
869+ JoinType :: Left => {
870+ right = right. with_null_preserving_expressions ( & null_batch (
871+ join_schema,
872+ ) ?) ;
873+ }
874+ JoinType :: Right => {
875+ left = left. with_null_preserving_expressions ( & null_batch (
876+ join_schema,
877+ ) ?) ;
878+ }
879+ JoinType :: Full => {
880+ let batch = null_batch ( join_schema) ?;
881+ left = left. with_null_preserving_expressions ( & batch) ;
882+ right = right. with_null_preserving_expressions ( & batch) ;
883+ }
884+ _ => { }
847885 }
848- JoinType :: Full => {
849- let batch = null_batch ( join_schema) ?;
850- left = left. with_null_preserving_expressions ( & batch) ;
851- right = right. with_null_preserving_expressions ( & batch) ;
852- }
853- _ => { }
854886 }
855887
856888 let mut result =
@@ -1033,7 +1065,7 @@ mod tests {
10331065 let left = EquivalenceGroup :: new ( vec ! [ ] ) ;
10341066 let right = EquivalenceGroup :: new ( vec ! [ ] ) ;
10351067
1036- let result = left. join ( & right, & JoinType :: Full , 0 , & schema, & [ ] ) ?;
1068+ let result = left. join_with_schema ( & right, & JoinType :: Full , 0 , & schema, & [ ] ) ?;
10371069
10381070 assert_eq ! ( result. iter( ) . count( ) , 0 ) ;
10391071 Ok ( ( ) )
0 commit comments