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/02 15:25:47 UTC

[GitHub] [arrow-datafusion] andygrove opened a new pull request, #2416: Fix bug in subquery join filters referencing outer query

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

   # 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/2415
   
    # 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.  
   -->
   
   Fixes a bug.
   
   # 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.
   -->
   
   The issue was that the SQL parser was delegating to the DataFrame API to build a filter expression and the DataFrame implementation is not aware of subqueries and outer query schemas, so it failed to resolve columns in some cases.
   
   The SQL planner now just creates the `Filter` expression directly.
   
   
   # Are there any user-facing changes?
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   No
   
   <!--
   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 pull request #2416: Fix bug in subquery join filters referencing outer query

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

   @alamb @Dandandan @yjshen This is ready for review. I'm not sure why we're normalizing column names when building the logical plan rather than during optimization but this is the approach that the logical plan builder was already taking so I just kept things consistent to avoid any test regressions.


-- 
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 #2416: Fix bug in subquery join filters referencing outer query

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


##########
datafusion/core/src/sql/planner.rs:
##########
@@ -889,9 +889,10 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
 
                 // remove join expressions from filter
                 match remove_join_expressions(&filter_expr, &all_join_keys)? {
-                    Some(filter_expr) => {
-                        LogicalPlanBuilder::from(left).filter(filter_expr)?.build()
-                    }
+                    Some(filter_expr) => Ok(LogicalPlan::Filter(Filter {
+                        predicate: filter_expr,
+                        input: Arc::new(left),
+                    })),

Review Comment:
   This is the bug fix. We cannot delegate to the `LogicalPlanBuilder` to build this `Filter` expression because it is not subquery-aware.



-- 
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 #2416: Fix bug in subquery join filters referencing outer query

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


-- 
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 #2416: Fix bug in subquery join filters referencing outer query

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

   >  I'm not sure why we're normalizing column names when building the logical plan rather than during optimization but this is the approach that the logical plan builder was already taking so I just kept things consistent to avoid any test regressions.
   
   I think this was part of @houqp 's work (maybe in  https://github.com/apache/arrow-datafusion/pull/1023) to properly handle multiple relations in a query


-- 
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 #2416: Fix bug in subquery join filters referencing outer query

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


##########
datafusion/core/src/sql/planner.rs:
##########
@@ -4523,6 +4562,35 @@ mod tests {
         quick_test(sql, &expected);
     }
 
+    #[test]
+    fn scalar_subquery_reference_outer_field() {
+        let sql = "SELECT j1_string, j2_string \
+        FROM j1, j2 \
+        WHERE j1_id = j2_id - 1 \
+        AND j2_id < (SELECT count(*) \

Review Comment:
   Oh so tricky 👍 



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