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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
