You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Lordworms (via GitHub)" <gi...@apache.org> on 2024/07/07 00:01:01 UTC

[PR] Implement TPCH substrait integration teset, support tpch_4 and tpch_5 [datafusion]

Lordworms opened a new pull request, #11311:
URL: https://github.com/apache/datafusion/pull/11311

   ## Which issue does this PR close?
   part of #10710 
   <!--
   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.
   -->
   
   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.  
   -->
   
   ## 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.
   -->
   
   ## 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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement TPCH substrait integration test, support tpch_4 and tpch_5 [datafusion]

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


##########
datafusion/substrait/src/logical_plan/consumer.rs:
##########
@@ -1297,6 +1297,32 @@ pub async fn from_substrait_rex(
                         outer_ref_columns,
                     })))
                 }
+                SubqueryType::SetPredicate(predicate) => {
+                    match predicate.predicate_op {

Review Comment:
   It looks like we could use https://docs.rs/substrait/0.35.0/substrait/proto/expression/subquery/struct.SetPredicate.html#method.predicate_op to match on `PredicateOp` rather than a constant
   
   So lke
   
   ```rust
   match predicate.predicate_op() { 
     PredicateOp::Exists => ...
     other_type => ...
   }
   ```



##########
datafusion/substrait/tests/cases/consumer_integration.rs:
##########
@@ -180,4 +214,56 @@ mod tests {
         \n                  TableScan: FILENAME_PLACEHOLDER_1 projection=[o_orderkey, o_custkey, o_orderstatus, o_totalprice, o_orderdate, o_orderpriority, o_clerk, o_shippriority, o_comment]\n                TableScan: FILENAME_PLACEHOLDER_2 projection=[l_orderkey, l_partkey, l_suppkey, l_linenumber, l_quantity, l_extendedprice, l_discount, l_tax, l_returnflag, l_linestatus, l_shipdate, l_commitdate, l_receiptdate, l_shipinstruct, l_shipmode, l_comment]");
         Ok(())
     }
+
+    #[tokio::test]
+    async fn tpch_test_4() -> Result<()> {
+        let ctx = create_context_tpch4().await?;
+        let path = "tests/testdata/tpch_substrait_plans/query_4.json";
+        let proto = serde_json::from_reader::<_, Plan>(BufReader::new(
+            File::open(path).expect("file not found"),
+        ))
+        .expect("failed to parse json");
+        let plan = from_substrait_plan(&ctx, &proto).await?;
+        let plan_str = format!("{:?}", plan);
+        assert_eq!(plan_str, "Projection: FILENAME_PLACEHOLDER_0.o_orderpriority AS O_ORDERPRIORITY, count(Int64(1)) AS ORDER_COUNT\
+        \n  Sort: FILENAME_PLACEHOLDER_0.o_orderpriority ASC NULLS LAST\
+        \n    Aggregate: groupBy=[[FILENAME_PLACEHOLDER_0.o_orderpriority]], aggr=[[count(Int64(1))]]\
+        \n      Projection: FILENAME_PLACEHOLDER_0.o_orderpriority\
+        \n        Filter: FILENAME_PLACEHOLDER_0.o_orderdate >= CAST(Utf8(\"1993-07-01\") AS Date32) AND FILENAME_PLACEHOLDER_0.o_orderdate < CAST(Utf8(\"1993-10-01\") AS Date32) AND EXISTS (<subquery>)\

Review Comment:
   👍 



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement TPCH substrait integration test, support tpch_4 and tpch_5 [datafusion]

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

   🚀 


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement TPCH substrait integration test, support tpch_4 and tpch_5 [datafusion]

Posted by "Blizzara (via GitHub)" <gi...@apache.org>.
Blizzara commented on code in PR #11311:
URL: https://github.com/apache/datafusion/pull/11311#discussion_r1668128566


##########
datafusion/substrait/tests/cases/consumer_integration.rs:
##########
@@ -90,6 +90,40 @@ mod tests {
         Ok(ctx)
     }
 
+    async fn create_context_tpch4() -> Result<SessionContext> {
+        let ctx = SessionContext::new();
+
+        let registrations = vec![

Review Comment:
   doesn't need to be part of this PR, but how about having a general create_context_tpch(registrations: Vec<(string, string)>)? and then writing the vec in the test functions 



##########
datafusion/substrait/src/logical_plan/consumer.rs:
##########
@@ -1297,6 +1298,32 @@ pub async fn from_substrait_rex(
                         outer_ref_columns,
                     })))
                 }
+                SubqueryType::SetPredicate(predicate) => {
+                    match predicate.predicate_op() {
+                        // exist
+                        PredicateOp::Exists => {
+                            let relations = &predicate.tuples;

Review Comment:
   super nit:
   ```suggestion
                               let relation = &predicate.tuples;
   ```



##########
datafusion/substrait/src/logical_plan/consumer.rs:
##########
@@ -1297,6 +1298,32 @@ pub async fn from_substrait_rex(
                         outer_ref_columns,
                     })))
                 }
+                SubqueryType::SetPredicate(predicate) => {
+                    match predicate.predicate_op() {
+                        // exist
+                        PredicateOp::Exists => {
+                            let relations = &predicate.tuples;
+                            let plan = from_substrait_rel(
+                                ctx,
+                                &relations.clone().unwrap_or_default(),
+                                extensions,
+                            )
+                            .await?;
+                            let outer_ref_columns = plan.all_out_ref_exprs();
+                            Ok(Arc::new(Expr::Exists(Exists::new(
+                                Subquery {
+                                    subquery: Arc::new(plan),
+                                    outer_ref_columns,
+                                },
+                                false,
+                            ))))
+                        }
+                        other_type => Err(DataFusionError::Substrait(format!(
+                            "unimplemented type {:?} for set predicate",
+                            other_type
+                        ))),

Review Comment:
   would 
   ```suggestion
                           other_type => substrait_datafusion_err!(
                               "unimplemented type {:?} for set predicate",
                               other_type
                           ),
   ```
   work here as well?



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement TPCH substrait integration test, support tpch_4 and tpch_5 [datafusion]

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


##########
datafusion/substrait/src/logical_plan/consumer.rs:
##########
@@ -1297,6 +1298,32 @@ pub async fn from_substrait_rex(
                         outer_ref_columns,
                     })))
                 }
+                SubqueryType::SetPredicate(predicate) => {
+                    match predicate.predicate_op() {
+                        // exist
+                        PredicateOp::Exists => {
+                            let relations = &predicate.tuples;
+                            let plan = from_substrait_rel(
+                                ctx,
+                                &relations.clone().unwrap_or_default(),
+                                extensions,
+                            )
+                            .await?;
+                            let outer_ref_columns = plan.all_out_ref_exprs();
+                            Ok(Arc::new(Expr::Exists(Exists::new(
+                                Subquery {
+                                    subquery: Arc::new(plan),
+                                    outer_ref_columns,
+                                },
+                                false,
+                            ))))
+                        }
+                        other_type => Err(DataFusionError::Substrait(format!(
+                            "unimplemented type {:?} for set predicate",
+                            other_type
+                        ))),

Review Comment:
   in f1ae84c10



##########
datafusion/substrait/src/logical_plan/consumer.rs:
##########
@@ -1297,6 +1298,32 @@ pub async fn from_substrait_rex(
                         outer_ref_columns,
                     })))
                 }
+                SubqueryType::SetPredicate(predicate) => {
+                    match predicate.predicate_op() {
+                        // exist
+                        PredicateOp::Exists => {
+                            let relations = &predicate.tuples;

Review Comment:
   in 489b96c01



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement TPCH substrait integration teset, support tpch_4 and tpch_5 [datafusion]

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

   not much to change for these two queries.


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement TPCH substrait integration test, support tpch_4 and tpch_5 [datafusion]

Posted by "Lordworms (via GitHub)" <gi...@apache.org>.
Lordworms commented on code in PR #11311:
URL: https://github.com/apache/datafusion/pull/11311#discussion_r1667780236


##########
datafusion/substrait/src/logical_plan/consumer.rs:
##########
@@ -1297,6 +1297,32 @@ pub async fn from_substrait_rex(
                         outer_ref_columns,
                     })))
                 }
+                SubqueryType::SetPredicate(predicate) => {
+                    match predicate.predicate_op {

Review Comment:
   Sure, I'll fix it.



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement TPCH substrait integration test, support tpch_4 and tpch_5 [datafusion]

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


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org