findinpath commented on code in PR #9830:
URL: https://github.com/apache/iceberg/pull/9830#discussion_r3092353615


##########
spark/v4.1/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DropV2ViewExec.scala:
##########
@@ -30,6 +35,33 @@ case class DropV2ViewExec(catalog: ViewCatalog, ident: 
Identifier, ifExists: Boo
   override lazy val output: Seq[Attribute] = Nil
 
   override protected def run(): Seq[InternalRow] = {
+    // If the catalog is a SparkCatalog, check for materialized view storage 
table cleanup
+    catalog match {
+      case sparkCatalog: SparkCatalog =>
+        val icebergCatalog = sparkCatalog.icebergCatalog()
+        val icebergViewCatalog = 
icebergCatalog.asInstanceOf[org.apache.iceberg.catalog.ViewCatalog]
+        var view: Option[View] = None
+        try {
+          val ns = Namespace.of(ident.namespace(): _*)
+          val viewId = TableIdentifier.of(ns, ident.name())
+          view = Some(icebergViewCatalog.loadView(viewId))
+        } catch {
+          case _: exceptions.NoSuchViewException =>
+            if (!ifExists) {
+              throw new NoSuchViewException(ident)
+            }
+        }
+        // if view is a materialized view, drop the storage table first
+        view.foreach { v =>
+          val storageTable = v.currentVersion().storageTable()
+          if (storageTable != null) {
+            val storageIdent = 
Identifier.of(storageTable.namespace().levels(), storageTable.name())
+            sparkCatalog.dropTable(storageIdent)

Review Comment:
   What needs to be done in `RESTCatalog` to ensure that both the view and the 
storage table get dropped?



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

To unsubscribe, e-mail: [email protected]

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