mustafasrepo opened a new pull request, #6742:
URL: https://github.com/apache/arrow-datafusion/pull/6742
# 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 #6486.
# 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.
-->
`RepartitionExec` , when handling multiple input partitions, creates `N`
channels, where `N` is the output partition count. For each input partition
`tx` of these channels is cloned. This results in a total of `input_partition *
output_partition` effective `tx`s (total of `output_partition` `rx`s (receivers
are not cloned)).
During processing, the channels are pulled for each output partition (single
receiver from multiple inputs (if input partition is greater than 1)).
Depending on the processing time, this paradigm disrupts existing ordering,
since multiple input partitions are interleaved into single receiver (for each
output partitioning).
This is particularly problematic when the input partition count is greater
than 1, as it leads to an unpredictable order of records within the output
partitions. Although this behavior is desirable for most use cases, for some
use cases, we may want to preserve existing ordering during repartitioning.
# What changes are included in this PR?
This PR adds `SortPreservingRepartitionExec` which can preserve ordering
when its input is ordered. In this PR we create total of `n_input*n_output`
channels (sender and receivers). With this approach each channel is dedicated,
to send data from an input partition to an output partition.
When executor receives data for each output partition (It has `n_input`
receivers, that corresponds to data for each input partition [Data is not
interleaved, because we no longer have single receiver], each output partition
can merge (while preserving order) data from its receiver, hence each output
partition can preserve its existing ordering.)
<!--
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.
-->
# Are these changes tested?
Yes fuzzy tests are added, to test ordering is preserved through following
physical plan (input and output of the following physical plan should be same)
```sql
"SortPreservingMergeExec: [a@0 ASC,b@1 ASC,c@2 ASC]",
" SortPreservingRepartitionExec: partitioning=Hash([Column { name: \"c\",
index: 2 }], 2), input_partitions=2", (Partitioning can be roundrobin also)
" SortPreservingRepartitionExec: partitioning=Hash([Column { name: \"c\",
index: 2 }], 2), input_partitions=1", (Partitioning can be roundrobin also)
" MemoryExec: partitions=1, partition_sizes=[75] (with existing
ordering)",
```
<!--
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]