imback82 commented on a change in pull request #30774:
URL: https://github.com/apache/spark/pull/30774#discussion_r543109646
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala
##########
@@ -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)
Review comment:
Sorry, I didn't get this question. This is creating a new cache with a
new table name.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]