ryan-johnson-databricks commented on code in PR #37879:
URL: https://github.com/apache/spark/pull/37879#discussion_r974198718


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala:
##########
@@ -28,8 +28,14 @@ class ResolveCatalogs(val catalogManager: CatalogManager)
   extends Rule[LogicalPlan] with LookupCatalog {
 
   override def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators {
-    case UnresolvedIdentifier(CatalogAndIdentifier(catalog, identifier)) =>
-      ResolvedIdentifier(catalog, identifier)
+    case UnresolvedIdentifier(nameParts, allowTemp) =>
+      if (allowTemp && catalogManager.v1SessionCatalog.isTempView(nameParts)) {
+        val ident = Identifier.of(nameParts.dropRight(1).toArray, 
nameParts.last)

Review Comment:
   nit: `nameParts.init` is the counterpart to `nameParts.last`:
   
https://www.scala-lang.org/api/2.12.5/scala/collection/Seq.html#inits:Iterator[Repr]



##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DDLParserSuite.scala:
##########
@@ -685,15 +685,15 @@ class DDLParserSuite extends AnalysisTest {
     val cmd = "DROP VIEW"
     val hint = Some("Please use DROP TABLE instead.")
     parseCompare(s"DROP VIEW testcat.db.view",
-      DropView(UnresolvedView(Seq("testcat", "db", "view"), cmd, true, hint), 
ifExists = false))

Review Comment:
   why does `UnresolvedView` even continue to exist, if it's not useful for 
dropping? Do we still use it for add/select/etc?



##########
sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSessionCatalog.scala:
##########
@@ -216,19 +216,23 @@ class ResolveSessionCatalog(val catalogManager: 
CatalogManager)
         c
       }
 
-    case DropTable(ResolvedV1TableIdentifier(ident), ifExists, purge) =>
+    case DropTable(ResolvedV1Identifier(ident), ifExists, purge) =>
       DropTableCommand(ident, ifExists, isView = false, purge = purge)
 
-    case DropTable(_: ResolvedPersistentView, ifExists, purge) =>
-      throw QueryCompilationErrors.cannotDropViewWithDropTableError
-
     // v1 DROP TABLE supports temp view.
-    case DropTable(ResolvedTempView(ident, _), ifExists, purge) =>
-      DropTableCommand(ident.asTableIdentifier, ifExists, isView = false, 
purge = purge)
+    case DropTable(ResolvedIdentifier(FakeSystemCatalog, ident), _, _) =>
+      DropTempViewCommand(ident)
 
-    case DropView(ResolvedViewIdentifier(ident), ifExists) =>
+    case DropView(ResolvedV1Identifier(ident), ifExists) =>
       DropTableCommand(ident, ifExists, isView = true, purge = false)
 
+    case DropView(r @ ResolvedIdentifier(catalog, ident), _) =>
+      if (catalog == FakeSystemCatalog) {
+        DropTempViewCommand(ident)
+      } else {
+        throw QueryCompilationErrors.catalogOperationNotSupported(catalog, 
"views")
+      }

Review Comment:
   nit: `r` not used? And if you make `FakeSystemCatalog` a `case object` it 
can participate directly in matching here:
   ```scala
   case DropView(ResolvedIdentifier(FakeSystemCatalog, ident), _) => 
     DropTempViewCommand(ident)
   case DropView(ResolvedIdentifier(catalog, _), _) => 
     throw ...
   ```



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