You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "mustafasrepo (via GitHub)" <gi...@apache.org> on 2024/05/09 12:03:23 UTC
[PR] During expression equality, check for new ordering information [datafusion]
mustafasrepo opened a new pull request, #10434:
URL: https://github.com/apache/datafusion/pull/10434
## 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
See [issue9812](https://github.com/apache/datafusion/issues/9812) for rationale.
<!--
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?
When an equality expression is added to the `EquivalenceProperties`. In light of this information, we can deduce new information about ordering and constantness. This PR adds this support.
With the [PR](https://github.com/apache/datafusion/pull/9813) we have this support, in terms of behaviour. However, current solution doesn't update state and cannot generalize well.
<!--
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?
There is an additional TestCase, that showcases increased coverage with this implementation (That test case fails in main branch).
<!--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] During expression equality, check for new ordering information [datafusion]
Posted by "suremarc (via GitHub)" <gi...@apache.org>.
suremarc commented on PR #10434:
URL: https://github.com/apache/datafusion/pull/10434#issuecomment-2109163914
Sorry @alamb @mustafasrepo, I completely missed this. My GH notifications tend to get drowned out by stuff from work, but I've discovered my personal email doesn't have this issue. I will check it every day from now on.
As for this PR, looks great and I'm glad we don't have to declare equivalences backwards (`f(a) = b`) for the sort optimizations to work. I do think the `collapse_monotonic_lex_req` was a bit of a smell, so it's nice to move that logic closer into the `EquivalenceProperties` code 👍
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] During expression equality, check for new ordering information [datafusion]
Posted by "ozankabak (via GitHub)" <gi...@apache.org>.
ozankabak commented on code in PR #10434:
URL: https://github.com/apache/datafusion/pull/10434#discussion_r1595444209
##########
datafusion/physical-expr/src/equivalence/properties.rs:
##########
@@ -198,6 +198,61 @@ impl EquivalenceProperties {
left: &Arc<dyn PhysicalExpr>,
right: &Arc<dyn PhysicalExpr>,
) {
+ // Discover new constants in the light of new ordering
+ if self.is_expr_constant(left) {
+ // Left expression is constant, add right as constant
+ if !physical_exprs_contains(&self.constants, right) {
+ self.constants.push(right.clone());
+ }
+ } else if self.is_expr_constant(right) {
+ // Right expression is constant, add left as constant
+ if !physical_exprs_contains(&self.constants, left) {
+ self.constants.push(left.clone());
+ }
+ }
+
+ // Discover new valid orderings in the light of new equality
+ // See issue: https://github.com/apache/datafusion/issues/9812 for rationale
Review Comment:
```suggestion
// Discover new valid orderings in light of the new equality. For a discussion, see:
// https://github.com/apache/datafusion/issues/9812
```
##########
datafusion/physical-expr/src/equivalence/properties.rs:
##########
@@ -198,6 +198,61 @@ impl EquivalenceProperties {
left: &Arc<dyn PhysicalExpr>,
right: &Arc<dyn PhysicalExpr>,
) {
+ // Discover new constants in the light of new ordering
Review Comment:
```suggestion
// Discover new constants in light of new the equality:
```
##########
datafusion/physical-expr/src/equivalence/mod.rs:
##########
@@ -47,48 +46,8 @@ pub fn collapse_lex_req(input: LexRequirement) -> LexRequirement {
output.push(item);
}
}
- collapse_monotonic_lex_req(output)
-}
-
-/// This function constructs a normalized [`LexRequirement`] by filtering out entries
-/// that are ordered if the next entry is.
-/// Used in `collapse_lex_req`
-fn collapse_monotonic_lex_req(input: LexRequirement) -> LexRequirement {
- input
- .iter()
- .enumerate()
- .filter_map(|(i, item)| {
- // If it's the last entry, there is no next entry
- if i == input.len() - 1 {
- return Some(item);
- }
- let next_expr = &input[i + 1];
-
- // Only handle expressions with exactly one child
- // TODO: it should be possible to handle expressions orderings f(a, b, c), a, b, c
- // if f is monotonic in all arguments
- if !(item.expr.children().len() == 1
- && item.expr.children()[0].eq(&next_expr.expr))
- {
- return Some(item);
- }
-
- let opts = match next_expr.options {
- None => return Some(item),
- Some(opts) => opts,
- };
-
- if item.options.map(SortProperties::Ordered)
- == Some(item.expr.get_ordering(&[SortProperties::Ordered(opts)]))
- {
- // Remove the redundant sort
- return None;
- }
-
- Some(item)
- })
- .cloned()
- .collect::<Vec<_>>()
+ // collapse_monotonic_lex_req(output)
Review Comment:
```suggestion
```
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] During expression equality, check for new ordering information [datafusion]
Posted by "ozankabak (via GitHub)" <gi...@apache.org>.
ozankabak commented on PR #10434:
URL: https://github.com/apache/datafusion/pull/10434#issuecomment-2104334922
Given this is a fairly small piece of code, two reviewers already took a look and all tests pass, I will go ahead and merge it. If there is any issue we discover later on, or @suremarc points out something we are missing, we will address with a follow-on PR. Thanks all
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] During expression equality, check for new ordering information [datafusion]
Posted by "mustafasrepo (via GitHub)" <gi...@apache.org>.
mustafasrepo commented on PR #10434:
URL: https://github.com/apache/datafusion/pull/10434#issuecomment-2102534387
@suremarc, I would appreciate your review if you have time
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] During expression equality, check for new ordering information [datafusion]
Posted by "ozankabak (via GitHub)" <gi...@apache.org>.
ozankabak merged PR #10434:
URL: https://github.com/apache/datafusion/pull/10434
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org