srowen commented on a change in pull request #26317: [SPARK-29628][SQL] 
Forcibly create a temporary view in CREATE VIEW if referencing a temporary view
URL: https://github.com/apache/spark/pull/26317#discussion_r345847084
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
 ##########
 @@ -110,19 +110,25 @@ case class CreateViewCommand(
 
   private def isTemporary = viewType == LocalTempView || viewType == 
GlobalTempView
 
-  // Disallows 'CREATE TEMPORARY VIEW IF NOT EXISTS' to be consistent with 
'CREATE TEMPORARY TABLE'
-  if (allowExisting && isTemporary) {
-    throw new AnalysisException(
-      "It is not allowed to define a TEMPORARY view with IF NOT EXISTS.")
-  }
+  if (isTemporary) verifyTempView()
+
+  private def verifyTempView(): Unit = {
+    // Disallows 'CREATE TEMPORARY VIEW IF NOT EXISTS'
+    // to be consistent with 'CREATE TEMPORARY TABLE'
+    if (allowExisting) {
+      throw new AnalysisException(
+        "It is not allowed to define a TEMPORARY view with IF NOT EXISTS.")
+    }
 
-  // Temporary view names should NOT contain database prefix like 
"database.table"
-  if (isTemporary && name.database.isDefined) {
-    val database = name.database.get
-    throw new AnalysisException(
-      s"It is not allowed to add database prefix `$database` for the TEMPORARY 
view name.")
+    // Temporary view names should NOT contain database prefix like 
"database.table"
+    name.database.foreach{
+      database => throw new AnalysisException(
+        s"It is not allowed to add database prefix `$database` for the 
TEMPORARY view name.")
+    }
   }
 
+  private var isTempReferred = false
 
 Review comment:
   Yes that's not quite my question. How do we know the code path that sets 
this to true below will execute first?

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


With regards,
Apache Git Services

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

Reply via email to