Skip to content

Make ensure_coop optimization rule idempotent#28

Merged
xudong963 merged 6 commits intobranch-51from
rohan/ensure-coop-patch
Jan 22, 2026
Merged

Make ensure_coop optimization rule idempotent#28
xudong963 merged 6 commits intobranch-51from
rohan/ensure-coop-patch

Conversation

@rkrishn7
Copy link
Copy Markdown
Collaborator

Bringing in changes from apache#19757 and relevant dependent commits.

We're seeing multiple CooperativeExec nodes with multiple optimization passes (for access controlled view tables). Hopefully this fixes it,

adriangb and others added 5 commits January 21, 2026 19:30
…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 xudong963 merged commit 5f37deb into branch-51 Jan 22, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants