imback82 commented on a change in pull request #30825:
URL: https://github.com/apache/spark/pull/30825#discussion_r546174646



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/RenameTableExec.scala
##########
@@ -27,14 +27,26 @@ import org.apache.spark.sql.connector.catalog.{Identifier, 
TableCatalog}
 case class RenameTableExec(
     catalog: TableCatalog,
     oldIdent: Identifier,
-    newIdent: Identifier) extends V2CommandExec {
+    newIdent: Identifier,
+    invalidateCache: () => Option[CacheInfo],
+    cacheTable: (DataSourceV2Relation, CacheInfo) => Unit)
+  extends V2CommandExec {
 
   override def output: Seq[Attribute] = Seq.empty
 
   override protected def run(): Seq[InternalRow] = {
+    import 
org.apache.spark.sql.connector.catalog.CatalogV2Implicits.IdentifierHelper
+
+    val optOldCacheInfo = invalidateCache()
     catalog.invalidateTable(oldIdent)
+
     catalog.renameTable(oldIdent, newIdent)
 
+    optOldCacheInfo.foreach { cacheInfo =>
+      val tbl = catalog.loadTable(newIdent)
+      val newRelation = DataSourceV2Relation.create(tbl, Some(catalog), 
Some(newIdent))
+      cacheTable(newRelation, CacheInfo(Some(newIdent.quoted), 
cacheInfo.storageLevel))

Review comment:
       If we canonicalize `DataSourceV2Relation`, we may be able to avoid 
recaching. Canonicalizing `Table` could be tricky and I am not sure if it's 
worthwhile exploring.




----------------------------------------------------------------
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]

Reply via email to