You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "my-vegetable-has-exploded (via GitHub)" <gi...@apache.org> on 2023/12/05 14:18:35 UTC

[PR] Support crossjoin in substrait. [arrow-datafusion]

my-vegetable-has-exploded opened a new pull request, #8427:
URL: https://github.com/apache/arrow-datafusion/pull/8427

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   ref: #8149
   
   Closes #.
   
   ## Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   part of #8149.
   
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   Translate [cross product](https://substrait.io/relations/logical_relations/#cross-product-operation)  to LogicalPlan::CrossJoin.
   
   ## Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
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


Re: [PR] Support crossjoin in substrait. [arrow-datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #8427:
URL: https://github.com/apache/arrow-datafusion/pull/8427#discussion_r1416235766


##########
datafusion/substrait/src/logical_plan/producer.rs:
##########
@@ -332,6 +333,18 @@ pub fn to_substrait_rel(
                 }))),
             }))
         }
+        LogicalPlan::CrossJoin(cross_join) => {
+            let left = to_substrait_rel(cross_join.left.as_ref(), ctx, extension_info)?;

Review Comment:
   👍 
   I double checked there are no extra fields that are missed: https://github.com/apache/arrow-datafusion/blob/2e5ad7a3cb3b3f3e96f931b903eb8bb6639329ff/datafusion/expr/src/logical_plan/plan.rs#L2050
   
   One way to potentially make this code more future proof if we add fields to `CrossJoin` in the future (aka have the compiler tell about places that may need updates) would be to use a direct restructuring
   
   Like
   
   ```suggestion
               let CrossJoin { left, right, schema: _} = cross_join
               let left = to_substrait_rel(left.as_ref(), ctx, extension_info)?;
   ```
   ...



##########
datafusion/substrait/src/logical_plan/producer.rs:
##########
@@ -332,6 +333,18 @@ pub fn to_substrait_rel(
                 }))),
             }))
         }
+        LogicalPlan::CrossJoin(cross_join) => {
+            let left = to_substrait_rel(cross_join.left.as_ref(), ctx, extension_info)?;

Review Comment:
   👍 
   I double checked there are no extra fields that are missed: https://github.com/apache/arrow-datafusion/blob/2e5ad7a3cb3b3f3e96f931b903eb8bb6639329ff/datafusion/expr/src/logical_plan/plan.rs#L2050
   
   One way to potentially make this code more future proof if we add fields to `CrossJoin` in the future (aka have the compiler tell about places that may need updates) would be to use a direct restructuring
   
   Like
   
   ```suggestion
               let CrossJoin { left, right, schema: _} = cross_join
               let left = to_substrait_rel(left.as_ref(), ctx, extension_info)?;
   ```
   ...



-- 
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


Re: [PR] Support crossjoin in substrait. [arrow-datafusion]

Posted by "my-vegetable-has-exploded (via GitHub)" <gi...@apache.org>.
my-vegetable-has-exploded commented on code in PR #8427:
URL: https://github.com/apache/arrow-datafusion/pull/8427#discussion_r1417029726


##########
datafusion/substrait/src/logical_plan/consumer.rs:
##########
@@ -434,6 +434,16 @@ pub async fn from_substrait_rel(
                 None => plan_err!("JoinRel without join condition is not allowed"),
             }
         }
+        Some(RelType::Cross(cross)) => {
+            let left: LogicalPlanBuilder = LogicalPlanBuilder::from(
+                from_substrait_rel(ctx, cross.left.as_ref().unwrap(), extensions).await?,
+            );
+            let right = LogicalPlanBuilder::from(
+                from_substrait_rel(ctx, cross.right.as_ref().unwrap(), extensions)
+                    .await?,
+            );
+            left.cross_join(right.build()?)?.build()

Review Comment:
   get it! thanks @waynexia 



-- 
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


Re: [PR] Support crossjoin in substrait. [arrow-datafusion]

Posted by "waynexia (via GitHub)" <gi...@apache.org>.
waynexia merged PR #8427:
URL: https://github.com/apache/arrow-datafusion/pull/8427


-- 
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


Re: [PR] Support crossjoin in substrait. [arrow-datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8427:
URL: https://github.com/apache/arrow-datafusion/pull/8427#issuecomment-1843792220

   🎉 


-- 
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


Re: [PR] Support crossjoin in substrait. [arrow-datafusion]

Posted by "my-vegetable-has-exploded (via GitHub)" <gi...@apache.org>.
my-vegetable-has-exploded commented on code in PR #8427:
URL: https://github.com/apache/arrow-datafusion/pull/8427#discussion_r1416593701


##########
datafusion/substrait/src/logical_plan/producer.rs:
##########
@@ -332,6 +333,18 @@ pub fn to_substrait_rel(
                 }))),
             }))
         }
+        LogicalPlan::CrossJoin(cross_join) => {
+            let left = to_substrait_rel(cross_join.left.as_ref(), ctx, extension_info)?;

Review Comment:
   good idea.



-- 
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


Re: [PR] Support crossjoin in substrait. [arrow-datafusion]

Posted by "waynexia (via GitHub)" <gi...@apache.org>.
waynexia commented on code in PR #8427:
URL: https://github.com/apache/arrow-datafusion/pull/8427#discussion_r1417020862


##########
datafusion/substrait/src/logical_plan/consumer.rs:
##########
@@ -434,6 +434,16 @@ pub async fn from_substrait_rel(
                 None => plan_err!("JoinRel without join condition is not allowed"),
             }
         }
+        Some(RelType::Cross(cross)) => {
+            let left: LogicalPlanBuilder = LogicalPlanBuilder::from(
+                from_substrait_rel(ctx, cross.left.as_ref().unwrap(), extensions).await?,
+            );
+            let right = LogicalPlanBuilder::from(
+                from_substrait_rel(ctx, cross.right.as_ref().unwrap(), extensions)
+                    .await?,
+            );
+            left.cross_join(right.build()?)?.build()

Review Comment:
   `LogicalPlanBuilder` to right side hand plan is unnecessary -- You create a builder from a plan and freeze it to plan immediately. 



-- 
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