You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/04/15 15:41:45 UTC

[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2240: Fix join without constraints

alamb commented on code in PR #2240:
URL: https://github.com/apache/arrow-datafusion/pull/2240#discussion_r851338721


##########
datafusion/core/src/sql/planner.rs:
##########
@@ -524,7 +524,18 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
                     keys.into_iter().unzip();
 
                 // return the logical plan representing the join
-                if filter.is_empty() {
+                if left_keys.is_empty() {
+                    // When we don't have join keys, use cross join

Review Comment:
   yeah, that is the classic implementation, infortunately



##########
datafusion/core/src/sql/planner.rs:
##########
@@ -524,7 +524,18 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
                     keys.into_iter().unzip();
 
                 // return the logical plan representing the join
-                if filter.is_empty() {
+                if left_keys.is_empty() {
+                    // When we don't have join keys, use cross join
+                    let join = LogicalPlanBuilder::from(left).cross_join(&right)?;
+
+                    let join_filter_init = filter.remove(0);
+                    join.filter(
+                        filter
+                            .into_iter()
+                            .fold(join_filter_init, |acc, e| acc.and(e)),
+                    )?
+                    .build()

Review Comment:
   I wonder if you can use `reduce` here rather than fold: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.reduce
   
   Something like (untested):
   
   ```suggestion
                       join.filter(
                           filter
                               .reduce(|acc, e| acc.and(e)),
                       )?
                       .build()
   ```
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org