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/10/06 18:11:36 UTC

[GitHub] [arrow-datafusion] andygrove opened a new pull request, #3739: Build aggregate schema in Aggregate::try_new

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

   # 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/3738
   
    # 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.  
   -->
   
   We had duplicate code for building an aggregate schema. This code is now inside `Aggregate::try_new` so we don't have to duplicate it everwhere,
   
   # 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.
   -->
   
   Refactoring to eliminate duplicate code for building aggregate schema
   
   # 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] andygrove commented on a diff in pull request #3739: Build aggregate schema in Aggregate::try_new

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


##########
datafusion/expr/src/logical_plan/builder.rs:
##########
@@ -700,20 +698,10 @@ impl LogicalPlanBuilder {
     ) -> Result<Self> {
         let group_expr = normalize_cols(group_expr, &self.plan)?;
         let aggr_expr = normalize_cols(aggr_expr, &self.plan)?;
-
-        let grouping_expr: Vec<Expr> = grouping_set_to_exprlist(group_expr.as_slice())?;
-
-        let all_expr = grouping_expr.iter().chain(aggr_expr.iter());
-        validate_unique_names("Aggregations", all_expr.clone())?;
-        let aggr_schema = DFSchema::new_with_metadata(
-            exprlist_to_fields(all_expr, &self.plan)?,
-            self.plan.schema().metadata().clone(),
-        )?;

Review Comment:
   This code is moved into `Aggregate::try_new`



-- 
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 #3739: Build aggregate schema in Aggregate::try_new

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


##########
datafusion/expr/src/logical_plan/plan.rs:
##########
@@ -1334,10 +1337,28 @@ pub struct Aggregate {
 }
 
 impl Aggregate {
+    /// Create a new aggregate operator.
     pub fn try_new(
         input: Arc<LogicalPlan>,
         group_expr: Vec<Expr>,
         aggr_expr: Vec<Expr>,
+    ) -> datafusion_common::Result<Self> {
+        let grouping_expr: Vec<Expr> = grouping_set_to_exprlist(group_expr.as_slice())?;
+        let all_expr = grouping_expr.iter().chain(aggr_expr.iter());
+        validate_unique_names("Aggregations", all_expr.clone())?;
+        let schema = DFSchema::new_with_metadata(
+            exprlist_to_fields(all_expr, &input)?,
+            input.schema().metadata().clone(),
+        )?;
+        Self::try_new_with_schema(input, group_expr, aggr_expr, Arc::new(schema))
+    }
+
+    /// Create a new aggregate operator using the provided schema to avoid the overhead of
+    /// building the schema again when the schema is already known.
+    pub fn try_new_with_schema(

Review Comment:
   So we do call this from other crates (such as the optimizer crate) so I added some more docs here.



-- 
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 #3739: Build aggregate schema in Aggregate::try_new

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

   CI failure appears unrelated: https://github.com/apache/arrow-datafusion/issues/3743


-- 
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] ursabot commented on pull request #3739: Build aggregate schema in Aggregate::try_new

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

   Benchmark runs are scheduled for baseline = 8dcef91806443f9b9b512bf6d819dc20961b29c8 and contender = 38cf2eb9dfb83817078e85dd4d0808cd0ed74cf2. 38cf2eb9dfb83817078e85dd4d0808cd0ed74cf2 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/30213f91a0cc4fe8b0433a36372cd7ca...8d00c35a4c30448bbb96f40602a4c381/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/8d0acb0298f044d89e62732638f971a7...0c9dbc1507fa4c4da4a7d4d7a39153e9/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/ab1e80405c7c4e418f12ec34c4dfc38f...66f358c0cca6434aa9618ee547f74e93/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/e6bd297f2e8e49d58fd81e02a72b9329...9ebb9cac1752480bb5553e89d9e20c4f/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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 #3739: Build aggregate schema in Aggregate::try_new

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


##########
datafusion/expr/src/logical_plan/plan.rs:
##########
@@ -1338,6 +1341,21 @@ impl Aggregate {
         input: Arc<LogicalPlan>,
         group_expr: Vec<Expr>,
         aggr_expr: Vec<Expr>,
+    ) -> datafusion_common::Result<Self> {
+        let grouping_expr: Vec<Expr> = grouping_set_to_exprlist(group_expr.as_slice())?;
+        let all_expr = grouping_expr.iter().chain(aggr_expr.iter());
+        validate_unique_names("Aggregations", all_expr.clone())?;
+        let schema = DFSchema::new_with_metadata(
+            exprlist_to_fields(all_expr, &input)?,
+            input.schema().metadata().clone(),
+        )?;

Review Comment:
   This is the code moved from `LogicalPlanBuilder::aggregate`



-- 
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 #3739: Build aggregate schema in Aggregate::try_new

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


##########
datafusion/optimizer/src/projection_push_down.rs:
##########
@@ -332,16 +330,6 @@ fn optimize_plan(
                 }
             })?;
 
-            let new_schema = DFSchema::new_with_metadata(
-                schema
-                    .fields()
-                    .iter()
-                    .filter(|x| new_required_columns.contains(&x.qualified_column()))
-                    .cloned()
-                    .collect(),
-                schema.metadata().clone(),
-            )?;

Review Comment:
   This code was problematic and is now replaced with the code used elsewhere



-- 
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 #3739: Build aggregate schema in Aggregate::try_new

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


##########
datafusion/optimizer/src/projection_push_down.rs:
##########
@@ -332,16 +330,6 @@ fn optimize_plan(
                 }
             })?;
 
-            let new_schema = DFSchema::new_with_metadata(
-                schema
-                    .fields()
-                    .iter()
-                    .filter(|x| new_required_columns.contains(&x.qualified_column()))
-                    .cloned()
-                    .collect(),
-                schema.metadata().clone(),
-            )?;

Review Comment:
   yes I agree having the caller have to specify (correctly) the aggregate schema is a recipe for disaster



##########
datafusion/expr/src/logical_plan/plan.rs:
##########
@@ -1334,10 +1337,28 @@ pub struct Aggregate {
 }
 
 impl Aggregate {
+    /// Create a new aggregate operator.
     pub fn try_new(
         input: Arc<LogicalPlan>,
         group_expr: Vec<Expr>,
         aggr_expr: Vec<Expr>,
+    ) -> datafusion_common::Result<Self> {
+        let grouping_expr: Vec<Expr> = grouping_set_to_exprlist(group_expr.as_slice())?;
+        let all_expr = grouping_expr.iter().chain(aggr_expr.iter());
+        validate_unique_names("Aggregations", all_expr.clone())?;
+        let schema = DFSchema::new_with_metadata(
+            exprlist_to_fields(all_expr, &input)?,
+            input.schema().metadata().clone(),
+        )?;
+        Self::try_new_with_schema(input, group_expr, aggr_expr, Arc::new(schema))
+    }
+
+    /// Create a new aggregate operator using the provided schema to avoid the overhead of
+    /// building the schema again when the schema is already known.
+    pub fn try_new_with_schema(

Review Comment:
   I recommend making this code non pub as to use it requires a lot of knowledge about how to use it.
   
   If we have to make it pub to call from other crates, I recommend putting a big warning on it telling others not to use it as it is intended for internal use
   
   ```suggestion
      fn try_new_with_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 merged pull request #3739: Build aggregate schema in Aggregate::try_new

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


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