albertusk95 commented on a change in pull request #25077: [SPARK-28301][SQL] 
fix the behavior of table name resolution with multi-catalog
URL: https://github.com/apache/spark/pull/25077#discussion_r306662343
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
 ##########
 @@ -181,29 +181,32 @@ case class CreateViewCommand(
    * Permanent views are not allowed to reference temp objects, including temp 
function and views
    */
   private def verifyTemporaryObjectsNotExists(sparkSession: SparkSession): 
Unit = {
-    import sparkSession.sessionState.analyzer.AsTableIdentifier
-
     if (!isTemporary) {
       // This func traverses the unresolved plan `child`. Below are the 
reasons:
       // 1) Analyzer replaces unresolved temporary views by a SubqueryAlias 
with the corresponding
       // logical plan. After replacement, it is impossible to detect whether 
the SubqueryAlias is
       // added/generated from a temporary view.
       // 2) The temp functions are represented by multiple classes. Most are 
inaccessible from this
       // package (e.g., HiveGenericUDF).
-      child.collect {
+      child.foreach {
         // Disallow creating permanent views based on temporary views.
-        case UnresolvedRelation(AsTableIdentifier(ident))
-            if sparkSession.sessionState.catalog.isTemporaryTable(ident) =>
-          // temporary views are only stored in the session catalog
-          throw new AnalysisException(s"Not allowed to create a permanent view 
$name by " +
-            s"referencing a temporary view $ident")
+        case UnresolvedRelation(parts) =>
+          // The `DataSourceResolution` rule guarantees this.
+          assert(parts.nonEmpty && parts.length <= 2)
+          val tblIdent = TableIdentifier(parts)
+          if (sparkSession.sessionState.catalog.isTemporaryTable(tblIdent)) {
+            // temporary views are only stored in the session catalog
+            throw new AnalysisException(s"Not allowed to create a permanent 
view $name by " +
+              s"referencing a temporary view $tblIdent")
+          }
         case other if !other.resolved => other.expressions.flatMap(_.collect {
           // Disallow creating permanent views based on temporary UDFs.
           case e: UnresolvedFunction
             if sparkSession.sessionState.catalog.isTemporaryFunction(e.name) =>
             throw new AnalysisException(s"Not allowed to create a permanent 
view $name by " +
               s"referencing a temporary function `${e.name}`")
         })
+        case _ =>
 
 Review comment:
   I think it'd be better to add a comment like `do nothing`

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to