Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix eq properties regression from #10434 #11363

Merged
merged 4 commits into from
Jul 10, 2024

Conversation

suremarc
Copy link
Contributor

@suremarc suremarc commented Jul 9, 2024

Which issue does this PR close?

Closes #11362.

Rationale for this change

This PR fixes a regression in #10434. The previous PR implements "discovery" of new orderings when equal conditions are added. However, this discovery process is not carried out when constants are added.
As a result, adding equality conditions tends to leave the properties in a normalized state, but adding constants does not leave the properties in a normalized state. Thus the order in which one constructs the properties matters.

Since the existing test for this feature applied equal conditions after adding constants, this path dependence was not caught.

What changes are included in this PR?

We extract out the "discovery" logic into a helper method, and we ensure it is called not only when adding equal conditions, but also when adding constants.

Are these changes tested?

Yes; we modify the test to construct the equivalence properties in different orders.

Are there any user-facing changes?

No, aside from improved physical plans in some cases

@github-actions github-actions bot added the physical-expr Physical Expressions label Jul 9, 2024
Copy link
Contributor

@mustafasrepo mustafasrepo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!. Thanks @suremarc for this PR. This is really nice.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Add equal expressions to the state
self.eq_group.add_equal_conditions(left, right);

// Discover any new orderings
self.discover_new_orderings(left)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

col(name, &schema).map(|col| PhysicalSortExpr {
expr: col,
options: SortOptions::default(),
// Construct the equivalence properties in different orders
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also verified test coverage by running these tests without the code changes and verified they do in fact fail ✅


thread 'equivalence::properties::tests::test_eliminate_redundant_monotonic_sorts' panicked at datafusion/physical-expr/src/equivalence/properties.rs:2493:17:
assertion `left == right` failed: failed test '(a, b, c) -> (c)'
  left: false
 right: true
stack backtrace:
   0: rust_begin_unwind
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:652:5
   1: core::panicking::panic_fmt
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:72:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:364:5
   4: datafusion_physical_expr::equivalence::properties::tests::test_eliminate_redundant_monotonic_sorts
             at ./src/equivalence/properties.rs:2493:17
   5: datafusion_physical_expr::equivalence::properties::tests::test_eliminate_redundant_monotonic_sorts::{{closure}}
             at ./src/equivalence/properties.rs:2382:54
   6: core::ops::function::FnOnce::call_once
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ops/function.rs:250:5
   7: core::ops::function::FnOnce::call_once
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: test failed, to rerun pass `--lib`
error: 1 target failed:
    `--lib`

@alamb alamb merged commit 9a8f8b7 into apache:main Jul 10, 2024
23 checks passed
Lordworms pushed a commit to Lordworms/arrow-datafusion that referenced this pull request Jul 12, 2024
* discover new orderings when constants are added

* more comments

* reduce nesting + describe argument

* lint?
appletreeisyellow pushed a commit to influxdata/arrow-datafusion that referenced this pull request Jul 12, 2024
* discover new orderings when constants are added

* more comments

* reduce nesting + describe argument

* lint?
findepi pushed a commit to findepi/datafusion that referenced this pull request Jul 16, 2024
* discover new orderings when constants are added

* more comments

* reduce nesting + describe argument

* lint?
xinlifoobar pushed a commit to xinlifoobar/datafusion that referenced this pull request Jul 18, 2024
* discover new orderings when constants are added

* more comments

* reduce nesting + describe argument

* lint?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
physical-expr Physical Expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression in eliminating monotonic sorts
3 participants