Make ensure_coop optimization rule idempotent#28
Merged
Conversation
…t into optimizer rules (apache#18739) Co-authored-by: Gabriel Musat Mestre <gabriel.musatmestre@datadoghq.com>
This reverts apache#18739 by reverting b990987 and 7b4593f. Due to feedback in apache#18739 we've decided to revert it at least for the time being. Since this change has not been released this is not be a breaking API change.
## Which issue does this PR close? This addresses part of apache#15804 but does not close it. ## Rationale for this change Now that we are on MSRV 1.88 we can use rust edition 2024, which brings let chains and other nice features. It also improves `unsafe` checking. In order to introduce these changes in slower way instead of one massive PR that is too difficult to manage we are updating a few crates at a time. ## What changes are included in this PR? Updates these crates to 2024. - datafusion-catalog - datafusion-datasource-arrow - datafusion-datasource-avro - datafusion-datasource-csv - datafusion-datasource-json - datafusion-datasource-parquet - datafusion-pruning - datafusion-functions-table - datafusion-physical-optimizer - datafusion-spark - datafusion-catalog-listing ## Are these changes tested? Existing unit tests. There are no functional code changes. ## Are there any user-facing changes? None. ## Note It is recommended to review with the ignore whitespace setting: https://github.com/apache/datafusion/pull/19258/files?w=1 --------- Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
## 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 apache#123` indicates that this PR will close issue apache#123. --> - Closes apache#19380. ## 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. --> Snapshot test passes but the existing value is in a legacy format. Updated insta snapshots to new format by running `cargo insta test --force-update-snapshots` ## What changes are included in this PR? Snapshots in various directories. <!-- 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? <!-- 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)? --> Yes ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> No <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> No
…ultiple runs (apache#19757) ## 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 apache#123` indicates that this PR will close issue apache#123. --> - Closes apache#19756. ## 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. --> The previous logic of `EnsureCooperative` optimizer lacked context awareness regarding ancestor nodes, making it not idempotent across multiple runs. Specifically, we need to ensure that: 1. **Idempotency**: Running the rule multiple times does not produce nested `CooperativeExec` wrappers. 2. **Context Awareness**: If a subtree is already protected by a `CooperativeExec`, we should skip and not double-wrap its children. ## What changes are included in this PR? To solve this, we cannot rely solely on `transform_up` (which lacks parent context) or `transform_down` (which makes safe mutation difficult). This PR adopts `transform_down_up` with a depth counter to strictly enforce that nodes are only wrapped when they are not currently under a `CooperativeExec` scope. <!-- 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? More unit tests coverage <!-- 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 <!-- 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. -->
xudong963
approved these changes
Jan 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bringing in changes from apache#19757 and relevant dependent commits.
We're seeing multiple
CooperativeExecnodes with multiple optimization passes (for access controlled view tables). Hopefully this fixes it,