-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-33817][SQL] CACHE TABLE uses a logical plan when caching a query to avoid creating a dataframe #30815
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 all commits
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 |
|---|---|---|
|
|
@@ -88,12 +88,34 @@ class CacheManager extends Logging with AdaptiveSparkPlanHelper { | |
| query: Dataset[_], | ||
| tableName: Option[String] = None, | ||
| storageLevel: StorageLevel = MEMORY_AND_DISK): Unit = { | ||
| val planToCache = query.logicalPlan | ||
| cacheQuery(query.sparkSession, query.logicalPlan, tableName, storageLevel) | ||
| } | ||
|
|
||
| /** | ||
| * Caches the data produced by the given [[LogicalPlan]]. | ||
| * Unlike `RDD.cache()`, the default storage level is set to be `MEMORY_AND_DISK` because | ||
| * recomputing the in-memory columnar representation of the underlying table is expensive. | ||
| */ | ||
| def cacheQuery( | ||
| spark: SparkSession, | ||
| planToCache: LogicalPlan, | ||
| tableName: Option[String]): Unit = { | ||
| cacheQuery(spark, planToCache, tableName, MEMORY_AND_DISK) | ||
| } | ||
|
|
||
| /** | ||
| * Caches the data produced by the given [[LogicalPlan]]. | ||
| */ | ||
| def cacheQuery( | ||
| spark: SparkSession, | ||
| planToCache: LogicalPlan, | ||
| tableName: Option[String], | ||
| storageLevel: StorageLevel): Unit = { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps we can just keep a single method with default value of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The scala compiler will complain if we do that. See #30815 (comment)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah got it. Thanks. |
||
| if (lookupCachedData(planToCache).nonEmpty) { | ||
| logWarning("Asked to cache already cached data.") | ||
| } else { | ||
| val sessionWithConfigsOff = SparkSession.getOrCloneSessionWithConfigsOff( | ||
| query.sparkSession, forceDisableConfigs) | ||
| spark, forceDisableConfigs) | ||
| val inMemoryRelation = sessionWithConfigsOff.withActive { | ||
| val qe = sessionWithConfigsOff.sessionState.executePlan(planToCache) | ||
| InMemoryRelation( | ||
|
|
||
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.
+1 on this! I think we may replace one more usage in
DataSourceV2Strategy.invalidateCacheas well.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.
thanks, updated.