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



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
##########
@@ -541,40 +552,31 @@ object ViewHelper {
   }
 
   /**
-   * Collect all temporary views and functions and return the identifiers 
separately
-   * 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).
+   * Collect all temporary views and functions and return the identifiers 
separately.
    */
   private def collectTemporaryObjects(
       catalog: SessionCatalog, child: LogicalPlan): (Seq[Seq[String]], 
Seq[String]) = {
     def collectTempViews(child: LogicalPlan): Seq[Seq[String]] = {
       child.flatMap {
-        case UnresolvedRelation(nameParts, _, _) if 
catalog.isTempView(nameParts) =>
-          Seq(nameParts)
-        case w: With if !w.resolved => 
w.innerChildren.flatMap(collectTempViews)
-        case plan if !plan.resolved => plan.expressions.flatMap(_.flatMap {
+        case s @ SubqueryAlias(_, view: View) if view.isTempView =>

Review comment:
       > ah it's `child.flatMap`, seems we don't need to match `SubqueryAlias` 
here?
   
   Ah, yes. `SubqueryAlias` is not needed any more as `View` always has 
`CatalogTable`.
    
   > BTW does temp view come with `SubqueryAlias`? What's the qualifier there?
   
   Yes, temp views come with `SubqueryAlias` if used with `LookupTempView`:
   
https://github.com/apache/spark/blob/7f27d33a3c538da6754a6c011b29aa7eb0dafe2c/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala#L884-L889
   
   The qualifier is empty for temp view, and global temp database name for 
global temp view.

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala
##########
@@ -443,21 +444,23 @@ case class InsertIntoDir(
 }
 
 /**
- * A container for holding the view description(CatalogTable), and the output 
of the view. The
- * child should be a logical plan parsed from the `CatalogTable.viewText`, 
should throw an error
- * if the `viewText` is not defined.
+ * A container for holding the view description(CatalogTable) and info whether 
the view is temporary
+ * or not. If the view description is available, the child should be a logical 
plan parsed from the
+ * `CatalogTable.viewText`. Otherwise, the view is a temporary one created 
from a dataframe; in this

Review comment:
       I updated with a bit more info; please let me know if I missed anything.




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



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

Reply via email to