-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-33786][SQL] The storage level for a cache should be respected when a table name is altered. #30774
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
[SPARK-33786][SQL] The storage level for a cache should be respected when a table name is altered. #30774
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 |
|---|---|---|
|
|
@@ -195,16 +195,21 @@ case class AlterTableRenameCommand( | |
| DDLUtils.verifyAlterTableType(catalog, table, isView) | ||
| // If an exception is thrown here we can just assume the table is uncached; | ||
| // this can happen with Hive tables when the underlying catalog is in-memory. | ||
| val wasCached = Try(sparkSession.catalog.isCached(oldName.unquotedString)).getOrElse(false) | ||
| if (wasCached) { | ||
| // If `optStorageLevel` is defined, the old table was cached. | ||
| val optStorageLevel = Try { | ||
|
||
| val optCachedData = sparkSession.sharedState.cacheManager.lookupCachedData( | ||
| sparkSession.table(oldName.unquotedString)) | ||
| optCachedData.map(_.cachedRepresentation.cacheBuilder.storageLevel) | ||
| }.getOrElse(None) | ||
| optStorageLevel.foreach { _ => | ||
|
||
| CommandUtils.uncacheTableOrView(sparkSession, oldName.unquotedString) | ||
| } | ||
| // Invalidate the table last, otherwise uncaching the table would load the logical plan | ||
| // back into the hive metastore cache | ||
| catalog.refreshTable(oldName) | ||
| catalog.renameTable(oldName, newName) | ||
| if (wasCached) { | ||
| sparkSession.catalog.cacheTable(newName.unquotedString) | ||
| optStorageLevel.foreach { storageLevel => | ||
| sparkSession.catalog.cacheTable(newName.unquotedString, storageLevel) | ||
|
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. Does this miss the
Contributor
Author
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. Sorry, I didn't get this question. This is creating a new cache with a new table name.
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. Hm, you can check the change like #30769. Especially how it recaches the table. There is a val cache = session.sharedState.cacheManager.lookupCachedData(v2Relation)
session.sharedState.cacheManager.uncacheQuery(session, v2Relation, cascade = true)
session.sharedState.cacheManager.uncacheQuery(session, v2Relation, cascade = true)
if (recacheTable && cache.isDefined) {
// save the cache name and cache level for recreation
val cacheName = cache.get.cachedRepresentation.cacheBuilder.tableName
val cacheLevel = cache.get.cachedRepresentation.cacheBuilder.storageLevel
// recache with the same name and cache level.
val ds = Dataset.ofRows(session, v2Relation)
session.sharedState.cacheManager.cacheQuery(ds, cacheName, cacheLevel)
}
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 previous code seems also recache with the new name?
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. No, the refresh table command for v2 doesn't recache the table before #30769.
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. I mean the previous code in
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. Hmm okay, actually it also sounds like a bug if alter table command changes the cache name. I'm fine to leave it unchanged here.
Contributor
Author
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. I believe cache name is used for debug purpose only (for |
||
| } | ||
| } | ||
| Seq.empty[Row] | ||
|
|
||
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 existing implementation uses
CatalogAPIs (isCached), whereas this PR usesCacheManagerdirectly. If this approach is not desired, we can updateCatalogAPI to exposeStorageLevel.