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

[GitHub] [arrow-datafusion] mustafasrepo opened a new pull request, #6036: Unordered PARTITION BY column implementation (to prevent pipeline breaking)

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

   # 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 [#6035](https://github.com/apache/arrow-datafusion/issues/6035).
   
   # 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.  
   -->
   Current `BoundedWindowAggExec` implementation assumes that its input is ordered both by PARTITION BY and ORDER BY columns. This enables us to calculate partition separation points easily and fast. However, this assumption results in some queries to break pipeline. Even if there is no theoretical reason to break pipeline. 
   
   # 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.
   -->
   This PR extends functionality to support above mentioned cases. Consider query below
   ```sql
   SELECT SUM(inc_col) OVER(PARTITION BY unsorted_col ORDER BY low_card_col1 ASC ROWS BETWEEN 2 PRECEDING AND 1 FOLLOWING) as sum1
   FROM annotated_data2
   ```
   where `low_card_col1` is ascending sorted. There is no fundamental reason for above query to sort table according `unsorted_col` column (This helps with partition calculation). When input source is marked as `infinite`, this PR would turn physical plan for above query from
   ```sql
   "ProjectionExec: expr=[SUM(annotated_data2.inc_col) PARTITION BY [annotated_data2.unsorted_col] ORDER BY [annotated_data2.low_card_col1 ASC NULLS LAST] ROWS BETWEEN 2 PRECEDING AND 1 FOLLOWING@4 as sum1]",
   "  BoundedWindowAggExec: wdw=[SUM(annotated_data2.inc_col): Ok(Field { name: \"SUM(annotated_data2.inc_col)\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Rows, start_bound: Preceding(UInt64(2)), end_bound: Following(UInt64(1)) }], mode=[Sorted]",
   "    SortExec: expr=[unsorted_col@3 ASC NULLS LAST,low_card_col1@0 ASC NULLS LAST]",
   "      CsvExec: files={1 group: [[table_path]]}, has_header=true, limit=None, projection=[low_card_col1, low_card_col2, inc_col, unsorted_col]",
   
   ```
   to
   ```sql
   "ProjectionExec: expr=[SUM(annotated_data2.inc_col) PARTITION BY [annotated_data2.unsorted_col] ORDER BY [annotated_data2.low_card_col1 ASC NULLS LAST] ROWS BETWEEN 2 PRECEDING AND 1 FOLLOWING@4 as sum1]",
   "  BoundedWindowAggExec: wdw=[SUM(annotated_data2.inc_col): Ok(Field { name: \"SUM(annotated_data2.inc_col)\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Rows, start_bound: Preceding(UInt64(2)), end_bound: Following(UInt64(1)) }], mode=[Linear]",
   "    CsvExec: files={1 group: [[table_path]]}, has_header=true, limit=None, projection=[low_card_col1, low_card_col2, inc_col, unsorted_col]",
   
   ```
   
   
   # Are these changes tested?
   Existing fuzzy tests are extended to test this case. Also new tests are added.
   <!--
   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] alamb commented on pull request #6036: Unordered PARTITION BY column implementation (to prevent pipeline breaking)

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

   I will also try and review this change as well over the coming few days 
   
   > Even if there is no theoretical reason to break pipeline.
   
   It seems to me from reading the description on this PR that the tradeoff is:
   1. Save a sort, (e.g. don't sort by `unsorted_col` ) so faster CPU
   2. the BoundedWindowExec operator has to potentially buffer a large number of partitions (e.g. if `unsorted_column` has a large number of distrinct values) and thus requires more memory in some cases
   
   Is this a fair assesment


-- 
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 #6036: Unordered PARTITION BY column implementation (to prevent pipeline breaking)

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


-- 
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 #6036: Unordered PARTITION BY column implementation (to prevent pipeline breaking)

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

   Yes. At this time, we enable this mode only when the input is unbounded (where a sort is not even possible).
   
   For other use cases, we made some initial experiments. These experiments suggest that when you have enough memory to do a full sort without external spills, you should do that instead of using this mode. When you don't have enough memory to do a full sort in memory, using this mode vs. sort-with-spills will likely depend on cardinalities. When we have more data about this, we will send a follow-on PR that will focus on when to enable this outside of streaming.


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