mustafasrepo opened a new pull request, #8006:
URL: https://github.com/apache/arrow-datafusion/pull/8006
## 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
In the existing code base we have two different methods to keep track of
equivalences in the `Arc<dyn PhysicalPlan>`.
Which are `equivalence_properties` and `ordering_equivalence_properties`.
As a background `EquivalenceProperties` keeps track of equivalent columns
such as `a=b=c`, `e=f`.
`OrderingEquivalenceProperties` alternative orderings that table satisfies.
such `[a ASC, b ASC]`, and `[c ASC, d ASC]`.
`OrderingEquivalenceProperties` keeps track of constant expressions also
(e.g expression that are known to have a constant value. This can arise after
filter, join, etc.).
Inherently, this information is coupled, as an example
Assume that
- existing table satisfies following orderings `[a ASC, b ASC]` and `[c ASC,
d ASC]`.
- table have equivalent columns `a=e`.
- It is known that `f` is constant.
If an operator requires ordering at its input `[e ASC, f ASC, b ASC]`.
During the analysis for whether this requirement is satisfied by existing
ordering, we need to consider all orderings, equivalences, and constants at the
same time.
Following naive algorithm can be followed for this analysis (Please note
that algorithm in this PR is more elaborate.)
- Remove constant expressions from the requirement (This converts
requirement `[e ASC, f ASC, b ASC]` to `[e ASC, b ASC]`)
- Rewrite requirement such that it uses only representative expression for
each distinct equivalent group (This converts requirement `[e ASC, b ASC]` to
`[a ASC, b ASC]`).
- Apply same procedures above each of the orderings inside the
`OrderingEquivalences` (This converts ordering `[a ASC, b ASC]` to `[a ASC, b
ASC]` and `[c ASC, d ASC]` to `[c ASC, d ASC]` no change ).
- Check whether normalized requirement `[a ASC, b ASC]` is satisfied by any
of normalized orderings `[a ASC, b ASC]`, `[c ASC, d ASC]`.
As can be seen from the example above. Keeping track of these information
separately, is a bit cumbersome.
Also for the user implementing new functionality is a bit hard, and existing
APIs are a bit involved also. Such as `ordering_satisfy`,
`requirements_compatible`, etc.
I think it is better to unify these information in a single `struct` so that
- We can expose better, and more friendly `API`s from struct.
- Move utils, functions, to method calls
- Keep the invariants in the state (not relying on correct arguments).
- All of the implementations, algorithms resides in a single place, and
logic is not scatterred in different files.
<!--
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.
-->
## What changes are included in this PR?
This PR unifies `EquivalenceProperties` and `OrderingEquivalenceProperties`
to single struct called `EquivalenceProperties` (equivalence now involves,
exact equivalence, ordering equivalence, constants).
And all of the implementation that depend on this information is moved to
method calls (such as `projection`, `ordering_satisfy`, etc.)
- Additional tests to show that better plans can be produced with new
design. (As an example `ordering_satisfy` no longer just depends on single
ordering, which is output ordering. Bu considers all of the valid orderings for
the table. This enables additional optimizations. See new tests under
`window.slt` as an example)
<!--
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 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?
`api change` `ordering_equivalence_properties` is removed from the
`ExecutionPlan` and now `equivalence_properties` contains additional
information.
<!--
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]