imback82 commented on a change in pull request #31273:
URL: https://github.com/apache/spark/pull/31273#discussion_r579493961



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -862,7 +862,13 @@ class Analyzer(override val catalogManager: CatalogManager)
   }
 
   private def isResolvingView: Boolean = 
AnalysisContext.get.catalogAndNamespace.nonEmpty
-  private def referredTempViewNames: Seq[Seq[String]] = 
AnalysisContext.get.referredTempViewNames
+  private def isReferredTempViewName(nameParts: Seq[String]): Boolean = {
+    AnalysisContext.get.referredTempViewNames.exists { n =>
+      (n.length == nameParts.length) && n.zip(nameParts).forall {

Review comment:
       That doesn't compile?
   ```
   [error]  found   : org.apache.spark.sql.catalyst.analysis.Resolver
   [error]     (which expands to)  (String, String) => Boolean
   [error]  required: ((String, String)) => Boolean
   [error]       (n.length == nameParts.length) && 
n.zip(nameParts).forall(resolver)
   ```

##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
##########
@@ -541,40 +539,33 @@ object ViewHelper {
   }
 
   /**
-   * Collect all temporary views and functions and return the identifiers 
separately
-   * This func traverses the unresolved plan `child`. Below are the reasons:

Review comment:
       This comment is not relevant any more since analyzed plan is now used.

##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
##########
@@ -152,10 +152,10 @@ case class CreateViewCommand(
             sparkSession,
             analyzedPlan,
             aliasedPlan.schema,
-            originalText,
-            child))
+            originalText))
       } else {
-        aliasedPlan
+        assert(isTemporary)

Review comment:
       Removed.

##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
##########
@@ -152,10 +152,10 @@ case class CreateViewCommand(
             sparkSession,
             analyzedPlan,
             aliasedPlan.schema,
-            originalText,
-            child))
+            originalText))
       } else {
-        aliasedPlan
+        assert(isTemporary)
+        View(None, isTemporary, aliasedPlan)

Review comment:
       Thanks, moved to `SessionCatalog .getTempViewPlan`.

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -143,6 +143,7 @@ abstract class Optimizer(catalogManager: CatalogManager)
       EliminateResolvedHint,
       EliminateSubqueryAliases,
       EliminateView,
+      EliminateDataFrameTempViews,

Review comment:
       Thanks, removed.

##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
##########
@@ -129,10 +129,10 @@ case class CreateViewCommand(
             sparkSession,
             analyzedPlan,
             aliasedPlan.schema,
-            originalText,
-            child))
+            originalText))
       } else {
-        aliasedPlan
+        assert(isTemporary)

Review comment:
       Removed.

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
##########
@@ -840,14 +840,9 @@ class SessionCatalog(
     plan match {
       case viewInfo: TemporaryViewRelation =>
         fromCatalogTable(viewInfo.tableMeta, isTempView = true)
-      case v => v
-    }
-  }
-
-  def getTempViewSchema(plan: LogicalPlan): StructType = {

Review comment:
       This def was not being used, so I am removing it.

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -923,9 +933,9 @@ class Analyzer(override val catalogManager: CatalogManager)
     def lookupTempView(
         identifier: Seq[String], isStreaming: Boolean = false): 
Option[LogicalPlan] = {
       // Permanent View can't refer to temp views, no need to lookup at all.
-      if (isResolvingView && !referredTempViewNames.contains(identifier)) 
return None
+      if (isResolvingView && !isReferredTempViewName(identifier)) return None
 
-      val tmpView = identifier match {
+      val tmpView = expandRelationName(identifier) match {

Review comment:
       Thanks, can be removed now (after `isReferredTempViewName` fix)




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



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

Reply via email to