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

   # 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 #.
   
   # 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.  
   -->
   Currently, there are 2 rules for handling distribution within the physical 
plan:
   - `Repartition` rule: Its responsibility is to increase parallelism in the 
plan (plan generated may not valid in terms of distribution requirement)
   - `EnforceDistribution` Rule: Its responsibility is to satisfy requirements 
so that physical plan is valid in terms of distribution requirements.
   
   These two rules should be called consecutively to produce valid plans as far 
as distribution is concerned.
   Also plan generated after the `Repartition` + `EnforceDistribution` pair may 
be invalid in terms of ordering requirements even if the input plan was valid 
in terms of ordering requirements.
   
   In this PR, we combined (`Repartition`+`EnforceDistribution`) rule into a 
single rule `EnforceDistribution`, which will henceforth be called 
`EnforceDistributionV2` in this text to prevent confusion.
   
   Please note that, `repartition.rs` file still exists in this PR, where 
previously `Repartition` rule is implemented. It now contains only test codes. 
I kept this file to not introduce additional diff to this PR. In subsequent PRs 
I will move these tests to under `dist_enforcement.rs` file.
   
   
   `EnforceDistributionV2` rule
   - is idempotent; i.e. `EnforceDistributionV2`  rule can be used multiple 
times during optimization if necessary.
   - doesn't invalidate ordering requirements; i.e. if its input physical plan 
is valid in terms of ordering requirements, the output will also be valid. 
(Note that if input ordering is *invalid*, the rule will not fix it as that 
responsibility belongs to the `EnforceSorting` rule). Hence; with this rule, 
both the `EnforceDistributionV2` + `EnforceSorting` and `EnforceSorting` + 
`EnforceDistributionV2` stack will produce valid plans.
   
   # What changes are included in this PR?
   
   A refactor of distribution handling rules that satisfy the above properties.
   
   <!--
   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, existing tests all pass. New tests are also added 
   - to assert that `EnforceDistributionV2` rule is idempotent. 
   - to ensure that both (`EnforceDistributionV2` + `EnforceSorting`) and 
(`EnforceSorting` + `EnforceDistributionV2`) stack produce valid plans (The 
resulting plans may not be same).
   <!--
   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?
   
   No, only some plans will be more optimal now.
   
   <!--
   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]

Reply via email to