@@ -702,6 +702,11 @@ fn create_join(
702
702
. map ( |c| c. name ( ) . to_string ( ) )
703
703
. collect ( ) ;
704
704
705
+ // If both solutions are disjoint, we can use a cross join.
706
+ if lhs_keys. is_disjoint ( & rhs_keys) && filter. is_none ( ) {
707
+ return lhs. cross_join ( rhs. build ( ) ?) ;
708
+ }
709
+
705
710
let mut join_schema = lhs. schema ( ) . as_ref ( ) . clone ( ) ;
706
711
join_schema. merge ( rhs. schema ( ) ) ;
707
712
@@ -869,10 +874,22 @@ fn create_distinct_on_expr(
869
874
. collect ( ) ) ;
870
875
} ;
871
876
872
- let mut on_exprs = create_initial_columns_from_sort ( sort_exprs) ?;
877
+ let mut on_exprs = Vec :: new ( ) ;
878
+
879
+ // TODO: This should be easier to do.
880
+ let on_exprs_order = create_initial_columns_from_sort ( sort_exprs) ?;
881
+ for on_expr in & on_exprs_order {
882
+ let column = schema
883
+ . columns ( )
884
+ . into_iter ( )
885
+ . find ( |c| c. name ( ) == on_expr)
886
+ . expect ( "Column must exist" ) ;
887
+ on_exprs. push ( column) ;
888
+ }
889
+
873
890
for column in schema. columns ( ) {
874
891
if !on_exprs. contains ( & column) {
875
- on_exprs. push ( column. clone ( ) ) ;
892
+ on_exprs. push ( column) ;
876
893
}
877
894
}
878
895
@@ -885,11 +902,11 @@ fn create_distinct_on_expr(
885
902
/// When creating a DISTINCT ON node, the initial `on_expr` expressions must match the given
886
903
/// `sort_expr` (if they exist). This function creates these initial columns from the order
887
904
/// expressions.
888
- fn create_initial_columns_from_sort ( sort_exprs : & Vec < OrderExpression > ) -> DFResult < Vec < Column > > {
905
+ fn create_initial_columns_from_sort ( sort_exprs : & Vec < OrderExpression > ) -> DFResult < Vec < String > > {
889
906
sort_exprs
890
907
. iter ( )
891
908
. map ( |sort_expr| match sort_expr. expression ( ) {
892
- Expression :: Variable ( var) => Ok ( Column :: new_unqualified ( var. as_str ( ) ) ) ,
909
+ Expression :: Variable ( var) => Ok ( var. as_str ( ) . to_owned ( ) ) ,
893
910
_ => plan_err ! (
894
911
"Expression {} not supported for ORDER BY in combination with DISTINCT." ,
895
912
sort_expr
0 commit comments