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/05/05 00:04:28 UTC

[GitHub] [arrow-datafusion] andygrove opened a new pull request, #2446: WIP: Add SQL planner support for `ROLLUP` grouping set expressions

andygrove opened a new pull request, #2446:
URL: https://github.com/apache/arrow-datafusion/pull/2446

   # 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.
   -->
   
   Closes https://github.com/apache/arrow-datafusion/issues/2378
   
    # 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.  
   -->
   
   I would like to be able to create a valid logical plan from SQL queries containing ROLLUP grouping sets.
   
   # 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.
   -->
   
   - TBD this is still a work-in-progress
   
   # 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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2446: Add SQL planner support for `ROLLUP` and `CUBE` grouping set expressions

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2446:
URL: https://github.com/apache/arrow-datafusion/pull/2446#discussion_r867982502


##########
datafusion/expr/src/expr_schema.rs:
##########
@@ -198,6 +202,11 @@ impl ExprSchemable for Expr {
                 let data_type = expr.get_type(input_schema)?;
                 get_indexed_field(&data_type, key).map(|x| x.is_nullable())
             }
+            Expr::GroupingSet(_) => {
+                // grouping sets do not really have the concept of nullable and do not appear

Review Comment:
   I wonder if it is worth considering representing the grouping sets in a more specific way (like maybe a specific list on `LogicalPlan::Aggregrate`) rather than an `Expr` that can appear anywhere
   
   
   
   ```rust
   enum GroupingExpr {
     Expr(Expr),
     GroupingSet(GroupingSet),
   }
   
   /// Aggregates its input based on a set of grouping and aggregate
   /// expressions (e.g. SUM).
   #[derive(Clone)]
   pub struct Aggregate {
       /// The incoming logical plan
       pub input: Arc<LogicalPlan>,
       /// Grouping expressions
       pub group_expr: Vec<AggExprs>,
       /// Aggregate expressions
       pub aggr_expr: Vec<Expr>,
       /// The schema description of the aggregate output
       pub schema: DFSchemaRef,
   }
   ```
   
   Or something?



##########
datafusion/expr/src/expr.rs:
##########
@@ -249,6 +249,24 @@ pub enum Expr {
     Wildcard,
     /// Represents a reference to all fields in a specific schema.
     QualifiedWildcard { qualifier: String },
+    /// List of grouping set expressions. Only valid in the context of an aggregate

Review Comment:
   While reviewing this PR I was wondering how you aim to plan these queries
   
   it seems like a simple way would be to expand them to a set of `UNION ALL` queries, though then we will likely do the same input query many times which may be unideal. 
   
   Anyhow, I am looking forward to the next installment



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


[GitHub] [arrow-datafusion] alamb commented on pull request #2446: Add SQL planner support for `ROLLUP` and `CUBE` grouping set expressions

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #2446:
URL: https://github.com/apache/arrow-datafusion/pull/2446#issuecomment-1121066256

   I think this is good to merge; There are some comments, but we can address them as part of follow on PRs if appropriate.


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


[GitHub] [arrow-datafusion] alamb commented on pull request #2446: Add SQL planner support for `ROLLUP` and `CUBE` grouping set expressions

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #2446:
URL: https://github.com/apache/arrow-datafusion/pull/2446#issuecomment-1121066415

   Nice work @andygrove 


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


[GitHub] [arrow-datafusion] andygrove commented on a diff in pull request #2446: Add SQL planner support for `ROLLUP` and `CUBE` grouping set expressions

Posted by GitBox <gi...@apache.org>.
andygrove commented on code in PR #2446:
URL: https://github.com/apache/arrow-datafusion/pull/2446#discussion_r867166355


##########
datafusion/core/src/logical_plan/expr.rs:
##########
@@ -138,9 +139,33 @@ pub fn create_udaf(
 /// Create field meta-data from an expression, for use in a result set schema
 pub fn exprlist_to_fields<'a>(
     expr: impl IntoIterator<Item = &'a Expr>,
-    input_schema: &DFSchema,
+    plan: &LogicalPlan,

Review Comment:
   note that we pass in a plan now instead of a schema



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


[GitHub] [arrow-datafusion] andygrove commented on pull request #2446: Add SQL planner support for `ROLLUP` and `CUBE` grouping set expressions

Posted by GitBox <gi...@apache.org>.
andygrove commented on PR #2446:
URL: https://github.com/apache/arrow-datafusion/pull/2446#issuecomment-1119955111

   @alamb Yet another SQL planner PR for review when you have time.
   
   Also @Jimexist I think you may be interested in this one.


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


[GitHub] [arrow-datafusion] alamb commented on pull request #2446: Add SQL planner support for `ROLLUP` and `CUBE` grouping set expressions

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #2446:
URL: https://github.com/apache/arrow-datafusion/pull/2446#issuecomment-1121054431

   > LGTM, I really like how you split features into steps.
   
   I agree -- it makes the review process much easier ❤️ 


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


[GitHub] [arrow-datafusion] alamb commented on pull request #2446: Add SQL planner support for `ROLLUP` and `CUBE` grouping set expressions

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #2446:
URL: https://github.com/apache/arrow-datafusion/pull/2446#issuecomment-1120414580

   > @alamb Yet another SQL planner PR for review when you have time.
   
   Thanks @andygrove  -- I have put this on my queue for review tomorrow


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


[GitHub] [arrow-datafusion] yjshen commented on a diff in pull request #2446: Add SQL planner support for `ROLLUP` and `CUBE` grouping set expressions

Posted by GitBox <gi...@apache.org>.
yjshen commented on code in PR #2446:
URL: https://github.com/apache/arrow-datafusion/pull/2446#discussion_r867877950


##########
datafusion/expr/src/expr_schema.rs:
##########
@@ -124,6 +124,10 @@ impl ExprSchemable for Expr {
                 "QualifiedWildcard expressions are not valid in a logical query plan"
                     .to_owned(),
             )),
+            Expr::GroupingSet(_) => {
+                // grouping sets do not really have a type and do not appear in projections
+                Ok(DataType::Null)

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

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


[GitHub] [arrow-datafusion] alamb merged pull request #2446: Add SQL planner support for `ROLLUP` and `CUBE` grouping set expressions

Posted by GitBox <gi...@apache.org>.
alamb merged PR #2446:
URL: https://github.com/apache/arrow-datafusion/pull/2446


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