allisonwang-db commented on a change in pull request #32787:
URL: https://github.com/apache/spark/pull/32787#discussion_r658953235



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -1571,6 +1582,26 @@ class Analyzer(override val catalogManager: 
CatalogManager)
       }
     }
 
+    // Expand the star expression using the input plan first. If failed, try 
resolve
+    // the star expression using the outer query plan and wrap the resolved 
attributes
+    // in outer references. Otherwise throw the original exception.
+    private def expand(s: Star, plan: LogicalPlan): Seq[NamedExpression] = {
+      withPosition(s) {
+        try {
+          s.expand(plan, resolver)
+        } catch {
+          case e: AnalysisException =>
+            AnalysisContext.get.outerPlan.map(p =>
+              // Only a few unary nodes (Project/Aggregate) can host star 
expressions.
+              Try(s.expand(p.children.head, resolver)) match {

Review comment:
       The error message is confusing when there are star usages other than 
Project and Filter. Will update CheckAnslysis.
   ```
   scala> sql("select * from t1 join t2 on t1.* = t2.c1")
   org.apache.spark.sql.AnalysisException: Invalid call to dataType on 
unresolved object;
   'Project [*]
   +- 'Join Inner, (ArrayBuffer(t1).* = c1#76)
      :- SubqueryAlias spark_catalog.default.t1
      :  +- View (`default`.`t1`, [c1#72,c2#73])
      :     +- Project [cast(col1#74 as int) AS c1#72, cast(col2#75 as int) AS 
c2#73]
      :        +- LocalRelation [col1#74, col2#75]
      +- SubqueryAlias spark_catalog.default.t2
         +- View (`default`.`t2`, [c1#76,c2#77])
            +- Project [cast(col1#78 as int) AS c1#76, cast(col2#79 as int) AS 
c2#77]
               +- LocalRelation [col1#78, col2#79]
   ```




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

To unsubscribe, e-mail: [email protected]

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