Skip to content

[SPARK-52312][SQL] Ignore V2WriteCommand when caching DataFrame #51032

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

Conversation

qiyuandong-db
Copy link
Contributor

What changes were proposed in this pull request?

We found an issue that V2WriteCommand plans were not properly excluded from DataFrame caching, which can cause unintended side effects.

For example, when cache() is called on a DataFrame created from an INSERT SQL statement, the INSERT command gets re-executed during the caching process because the underlying plan is not being ignored.

This PR fixes this by

  • making V2WriteCommand extend the IgnoreCachedData trait
  • updating the caching logic to skip plans that extend IgnoreCachedData, preventing inapplicable plans from being cached

Why are the changes needed?

This is a bug, since calling cache() on a DataFrame shouldn't re-execute the command that created it.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

New tests were added.

Was this patch authored or co-authored using generative AI tooling?

No.

@github-actions github-actions bot added the SQL label May 27, 2025
@qiyuandong-db qiyuandong-db requested a review from cloud-fan May 28, 2025 11:35
@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in 6422256 May 30, 2025
yhuang-db pushed a commit to yhuang-db/spark that referenced this pull request Jun 9, 2025
### What changes were proposed in this pull request?

We found an issue that `V2WriteCommand` plans were not properly excluded from `DataFrame` caching, which can cause unintended side effects.

For example, when `cache()` is called on a `DataFrame` created from an `INSERT` SQL statement, the `INSERT` command gets re-executed during the caching process because the underlying plan is not being ignored.

This PR fixes this by

- making `V2WriteCommand` extend the `IgnoreCachedData` trait
- updating the caching logic to skip plans that extend `IgnoreCachedData`, preventing inapplicable plans from being cached

### Why are the changes needed?

This is a bug, since calling `cache()` on a `DataFrame` shouldn't re-execute the command that created it.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

New tests were added.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes apache#51032 from qiyuandong-db/SPARK-52312-ignore-v2writecommand-caching.

Authored-by: Qiyuan Dong <qiyuan.dong@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants