You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/12/18 06:06:20 UTC

[GitHub] [spark] imback82 commented on a change in pull request #26921: [SPARK-30282][SQL] UnresolvedV2Relation should be resolved to temp view first

imback82 commented on a change in pull request #26921: [SPARK-30282][SQL] UnresolvedV2Relation should be resolved to temp view first
URL: https://github.com/apache/spark/pull/26921#discussion_r359164909
 
 

 ##########
 File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
 ##########
 @@ -759,22 +761,29 @@ class Analyzer(
           .getOrElse(i)
 
       case desc @ DescribeTable(u: UnresolvedV2Relation, _) =>
-        CatalogV2Util.loadRelation(u.catalog, u.tableName)
-            .map(rel => desc.copy(table = rel))
-            .getOrElse(desc)
+        resolveV2Relation(u).map(rel => desc.copy(table = rel)).getOrElse(desc)
 
       case alter @ AlterTable(_, _, u: UnresolvedV2Relation, _) =>
-        CatalogV2Util.loadRelation(u.catalog, u.tableName)
-            .map(rel => alter.copy(table = rel))
-            .getOrElse(alter)
+        resolveV2Relation(u).map(rel => alter.copy(table = rel)).getOrElse(alter)
 
       case show @ ShowTableProperties(u: UnresolvedV2Relation, _) =>
-        CatalogV2Util.loadRelation(u.catalog, u.tableName)
-          .map(rel => show.copy(table = rel))
-          .getOrElse(show)
+        resolveV2Relation(u).map(rel => show.copy(table = rel)).getOrElse(show)
 
       case u: UnresolvedV2Relation =>
-        CatalogV2Util.loadRelation(u.catalog, u.tableName).getOrElse(u)
+        resolveV2Relation(u).getOrElse(u)
+    }
+
+    private def resolveV2Relation(unresolved: UnresolvedV2Relation) : Option[NamedRelation] = {
+      val maybeTempView = unresolved.originalNameParts match {
+        case Seq(part) => v1SessionCatalog.lookupTempView(part)
+        case _ => None
+      }
+      if (maybeTempView.isDefined) {
+        unresolved.failAnalysis(
+          s"Invalid command: '${unresolved.originalNameParts.quoted}' is a view not a table.")
 
 Review comment:
   I left this to the same message used in checkAnalysis to minimize the changes in tests. Please let me know if this neds to updated to more descriptive message such as 'A temp view 't' cannot be handled by V2 commands'

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org