-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-19736][SQL] refreshByPath should clear all cached plans with the specified path #17064
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -634,4 +634,28 @@ class CachedTableSuite extends QueryTest with SQLTestUtils with SharedSQLContext | |
| assert(getNumInMemoryRelations(cachedPlan2) == 4) | ||
| } | ||
| } | ||
|
|
||
| test("refreshByPath should refresh all cached plans with the specified path") { | ||
| def f(path: String, spark: SparkSession, dataCount: Int): DataFrame = { | ||
| spark.catalog.refreshByPath(path) | ||
|
||
| val data = spark.read.parquet(path) | ||
| assert(data.count == dataCount) | ||
| val df = data.filter("id > 10") | ||
| df.cache | ||
| assert(df.count == dataCount - 11) | ||
| val df1 = df.filter("id > 11") | ||
| df1.cache | ||
| assert(df1.count == dataCount - 12) | ||
| df1 | ||
|
||
| } | ||
|
|
||
| withTempDir { dir => | ||
| val path = dir.getPath() | ||
|
||
| spark.range(100).write.mode("overwrite").parquet(path) | ||
| assert(f(path, spark, 100).count == 88) | ||
|
|
||
| spark.range(1000).write.mode("overwrite").parquet(path) | ||
| assert(f(path, spark, 1000).count == 988) | ||
|
||
| } | ||
| } | ||
| } | ||
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.
why the previous one doesn't work?
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.
This kind of collection can't be modified during iterating. Some elements are not iterated over if we delete/add elements.
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.
but we are still modifying it during iteration, after the
filter. can you be more specific about what the problem is?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.
can we use a java collection so that we can remove elements while iterating?
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.
After
filter, we iterate on a different collection thancachedData, so it is no problem to add/delete elements tocachedData.Uh oh!
There was an error while loading. Please reload this page.
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.
The problem can be shown clearly with an example code snippet:
Output:
The element "2" is never iterated over.