-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[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
base: master
Are you sure you want to change the base?
[SPARK-52312][SQL] Ignore V2WriteCommand when caching DataFrame #51032
Conversation
tableName, | ||
storageLevel | ||
) | ||
if (query.queryExecution.analyzed.isInstanceOf[IgnoreCachedData]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we do it in cacheQueryInternal
which is lower level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that would be better. We have two cacheQuery()
variants and they both call cacheQueryInternal()
.
Moved the check there.
@@ -875,4 +875,53 @@ class DataFrameWriterV2Suite extends QueryTest with SharedSparkSession with Befo | |||
} | |||
} | |||
} | |||
|
|||
test("SPARK-52312: caching dataframe created from INSERT shouldn't re-execute the command") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with this test only. It's a unit test, and we don't need to iterate all v2 commands to prove the fix. Testing a common v2 command (table INSERT) is good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I've removed repeated ones.
@@ -127,6 +127,11 @@ class CacheManager extends Logging with AdaptiveSparkPlanHelper { | |||
// Do nothing for StorageLevel.NONE since it will not actually cache any data. | |||
} else if (lookupCachedDataInternal(normalizedPlan).nonEmpty) { | |||
logWarning("Asked to cache already cached data.") | |||
} else if (unnormalizedPlan.isInstanceOf[IgnoreCachedData]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we move it before the above else if
? For IgnoreCachedData
, we don't even need to do a lookup.
What changes were proposed in this pull request?
We found an issue that
V2WriteCommand
plans were not properly excluded fromDataFrame
caching, which can cause unintended side effects.For example, when
cache()
is called on aDataFrame
created from anINSERT
SQL statement, theINSERT
command gets re-executed during the caching process because the underlying plan is not being ignored.This PR fixes this by
V2WriteCommand
extend theIgnoreCachedData
traitIgnoreCachedData
, preventing inapplicable plans from being cachedWhy are the changes needed?
This is a bug, since calling
cache()
on aDataFrame
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.