You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "berkaysynnada (via GitHub)" <gi...@apache.org> on 2023/05/07 11:50:15 UTC

[GitHub] [arrow-datafusion] berkaysynnada opened a new pull request, #6273: Remove the PhysicalSortExpr restriction on union get meet

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

   # 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 #6272 .
   
   # 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.  
   -->
   
   Union get meet can only consider sort option and corresponding vector index during comparison. No need to check for PhysicalExpr equality.
   
   # 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 PhysicalSortExpr's can be downcasted to Column, compare the Column's indexes and sort options. Otherwise, the existing comparison is sustained.
   
   # 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)?
   -->
   
   Existing tests are sufficient.
   
   # 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] mingmwang commented on pull request #6273: Remove the PhysicalSortExpr restriction on union get meet

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

   @berkaysynnada 
   
   Can you extend the optimization to non-column cases?
   
   For example
   
   ```sql
   select a + b from table_2 order by a + b
   union all
   select x + y from table_2  order by x + y
   ```


-- 
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] berkaysynnada commented on pull request #6273: Remove the PhysicalSortExpr restriction on union get meet

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

   > 
   
   My last commit can succeed in the cases of your example. However, for the cases like (a+b+c), the build order of the binary expression is important. We can get false negative results. Actually, I think this is a general problem with binary expression structure.


-- 
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 #6273: Remove the PhysicalSortExpr restriction on union get meet

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


-- 
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] mingmwang commented on pull request #6273: Remove the PhysicalSortExpr restriction on union get meet

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

   Nice optimization


-- 
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 #6273: Remove the PhysicalSortExpr restriction on union get meet

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

   Thanks @berkaysynnada and @ozankabak 


-- 
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] berkaysynnada commented on pull request #6273: Remove the PhysicalSortExpr restriction on union get meet

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

   > Is there and SQL / plan level test that could be written that would cover this code? It seems like a neat optimization but I don't fully understand how to map it to how it would affect queries
   
   This PR optimizes the plan such:
   ```
   query TT
   explain
   SELECT c1 FROM(
   (   
       SELECT c1 FROM t1
   )  
   UNION ALL
   (   
       SELECT c1a FROM t2
   ))
   ORDER BY c1
   ----
   logical_plan
     Sort: t1.c1 ASC NULLS LAST
       Union
         TableScan: t1 projection=[c1]
         Projection: t2.c1a AS t1.c1
           TableScan: t2 projection=[c1a]
   physical_plan
     SortPreservingMergeExec: [c1@0 ASC NULLS LAST]
       UnionExec
         CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/testing/data/csv/aggregate_test_100.csv]]}, projection=[c1], output_ordering=[c1@0 ASC NULLS LAST], has_header=true
           ProjectionExec: expr=[c1a@0 as t1.c1]
         CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/testing/data/csv/aggregate_test_100.csv]]}, projection=[c1a], output_ordering=[c1a@0 ASC NULLS LAST], has_header=true
   ```
   
   However, the main version results such:
   ```
   logical_plan
     Sort: t1.c1 ASC NULLS LAST
       Union
         TableScan: t1 projection=[c1]
         Projection: t2.c1a AS t1.c1
           TableScan: t2 projection=[c1a]
   physical_plan
     SortPreservingMergeExec: [c1@0 ASC NULLS LAST]
       UnionExec
         CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/testing/data/csv/aggregate_test_100.csv]]}, projection=[c1], output_ordering=[c1@0 ASC NULLS LAST], has_header=true
         SortExec: expr=[c1@0 ASC NULLS LAST]
           ProjectionExec: expr=[c1a@0 as t1.c1]
             CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/testing/data/csv/aggregate_test_100.csv]]}, projection=[c1a], output_ordering=[c1a@0 ASC NULLS LAST], has_header=true
   ```


-- 
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] ozankabak commented on pull request #6273: Remove the PhysicalSortExpr restriction on union get meet

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

   Done, thank you


-- 
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 #6273: Remove the PhysicalSortExpr restriction on union get meet

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

   For some reason github claims this PR has conflicts that must be resolved 🤔  since I can't push changes to your branch to resolve this myself, @ozankabak  or @berkaysynnada  can you please resolve the problem? I will then merge it
   
   <img width="1210" alt="Screenshot 2023-05-09 at 7 45 10 PM" src="https://github.com/apache/arrow-datafusion/assets/490673/b219d165-8b76-408c-8872-e2b71a3d3d52">
   


-- 
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] berkaysynnada commented on pull request #6273: Remove the PhysicalSortExpr restriction on union get meet

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

   > @berkaysynnada
   > 
   > Can you extend the optimization to non-column cases?
   > 
   > For example
   > 
   > ```sql
   > select a + b from table_2 order by a + b
   > union all
   > select x + y from table_2  order by x + y
   > ```
   
   
   
   > @berkaysynnada
   > 
   > Can you extend the optimization to non-column cases?
   > 
   > For example
   > 
   > ```sql
   > select a + b from table_2 order by a + b
   > union all
   > select x + y from table_2  order by x + y
   > ```
   
   My last commit can succeed in the cases of your example. However, for the cases like a+b+c (having two or more depth), the build order of the binary expression is important. We can get false negative results. Actually, I think this is a general problem with binary expressions in Datafusion. 


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