You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "yukkit (via GitHub)" <gi...@apache.org> on 2023/04/18 03:02:43 UTC

[GitHub] [arrow-datafusion] yukkit opened a new pull request, #6039: fix: incorrect column pruning in sql with window operations

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

   # 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 #6001 .
   
   # 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.
   -->
   
   If the node that window's child has outputs not in referenced inputs, then add a projection
   
   # 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


[GitHub] [arrow-datafusion] jackwener commented on a diff in pull request #6039: fix: incorrect column pruning in sql with window operations

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


##########
datafusion/optimizer/src/push_down_projection.rs:
##########
@@ -312,11 +312,31 @@ impl OptimizerRule for PushDownProjection {
 
                 if new_window_expr.is_empty() {
                     // none columns in window expr are needed, remove the window expr
-                    let new_window = window.input.as_ref().clone();
+                    let new_window = window.input.clone();
+
+                    let new_window = restrict_outputs(&new_window, &required_columns)?
+                        .unwrap_or((*new_window).clone());

Review Comment:
   ```suggestion
                       let input = window.input.as_ref();
   
                       let new_input = restrict_outputs(input, &required_columns)?
                           .unwrap_or(input.clone());
   ```



##########
datafusion/optimizer/src/push_down_projection.rs:
##########
@@ -312,11 +312,31 @@ impl OptimizerRule for PushDownProjection {
 
                 if new_window_expr.is_empty() {
                     // none columns in window expr are needed, remove the window expr
-                    let new_window = window.input.as_ref().clone();
+                    let new_window = window.input.clone();
+
+                    let new_window = restrict_outputs(&new_window, &required_columns)?
+                        .unwrap_or((*new_window).clone());
 
                     generate_plan!(projection_is_empty, plan, new_window)
                 } else {
-                    let new_window = LogicalPlanBuilder::from((*(window.input)).clone())
+                    let mut referenced_inputs = HashSet::new();
+                    exprlist_to_columns(&new_window_expr, &mut referenced_inputs)?;
+                    window
+                        .input
+                        .schema()
+                        .fields()
+                        .iter()
+                        .filter(|f| required_columns.contains(&f.qualified_column()))
+                        .for_each(|f| {
+                            referenced_inputs.insert(f.qualified_column());
+                        });
+
+                    let window_child = window.input.clone();
+                    let new_window_child =
+                        restrict_outputs(&window_child, &referenced_inputs)?
+                            .unwrap_or((*window_child).clone());
+
+                    let new_window = LogicalPlanBuilder::from(new_window_child)

Review Comment:
   ```suggestion
                       let input = window.input.as_ref();
                       let new_input = restrict_outputs(input, &referenced_inputs)?
                           .unwrap_or(input.clone());
   
                       let new_window = LogicalPlanBuilder::from(new_input)
   ```



##########
datafusion/optimizer/src/push_down_projection.rs:
##########
@@ -553,6 +573,21 @@ fn push_down_scan(
     }))
 }
 
+fn restrict_outputs(
+    plan: &Arc<LogicalPlan>,

Review Comment:
   ```suggestion
       plan: &LogicalPlan,
   ```



##########
datafusion/optimizer/src/push_down_projection.rs:
##########
@@ -553,6 +573,21 @@ fn push_down_scan(
     }))
 }
 
+fn restrict_outputs(
+    plan: &Arc<LogicalPlan>,
+    permitted_outputs: &HashSet<Column>,
+) -> Result<Option<LogicalPlan>> {
+    let schema = plan.schema();
+    if permitted_outputs.len() == schema.fields().len() {
+        return Ok(None);
+    }
+    Ok(Some(generate_projection(
+        permitted_outputs,
+        schema,
+        plan.clone(),

Review Comment:
   ```suggestion
           Arc::new(plan.clone()),
   ```



-- 
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] yukkit commented on pull request #6039: fix: incorrect column pruning in sql with window operations

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

   @jackwener Thanks for your suggestion. I modified the variable naming, but I don't understand the modification here   https://github.com/apache/arrow-datafusion/pull/6039#discussion_r1170046496 as it results in a clone LogicalPlan instead of a pointer, I expect to know your thoughts. 
               


-- 
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] jackwener commented on pull request #6039: fix: incorrect column pruning in sql with window operations

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

   > @jackwener Thanks for your suggestion. I modified the variable naming, but I don't understand the modification here [#6039 (comment)](https://github.com/apache/arrow-datafusion/pull/6039#discussion_r1170046496) as it results in a clone LogicalPlan instead of a pointer, I expect to know your thoughts.
   
   Oh, It's my fault, I don't notice it. Thank you. @yukkit 


-- 
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] jackwener merged pull request #6039: fix: incorrect column pruning in sql with window operations

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


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