maropu commented on a change in pull request #32787:
URL: https://github.com/apache/spark/pull/32787#discussion_r659464716



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -1571,6 +1582,30 @@ 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 {
+              // Only a few unary nodes (Project/Aggregate) can host star 
expressions.
+              case u: UnaryNode =>

Review comment:
       we cannot filter project/aggregate nodes here?

##########
File path: sql/core/src/test/resources/sql-tests/results/join-lateral.sql.out
##########
@@ -80,6 +80,46 @@ struct<c1:int,c2:int,c1:int,c2:int>
 1      2       0       3
 
 
+-- !query
+SELECT * FROM t1, LATERAL (SELECT t1.*)
+-- !query schema
+struct<c1:int,c2:int,c1:int,c2:int>
+-- !query output
+0      1       0       1
+1      2       1       2
+
+
+-- !query
+SELECT * FROM t1, LATERAL (SELECT t1.*, t2.* FROM t2)
+-- !query schema
+struct<c1:int,c2:int,c1:int,c2:int,c1:int,c2:int>
+-- !query output
+0      1       0       1       0       2
+0      1       0       1       0       3
+1      2       1       2       0       2
+1      2       1       2       0       3
+
+
+-- !query
+SELECT * FROM t1, LATERAL (SELECT t1.* FROM t2 AS t1)
+-- !query schema
+struct<c1:int,c2:int,c1:int,c2:int>
+-- !query output
+0      1       0       2
+0      1       0       3
+1      2       0       2
+1      2       0       3
+
+
+-- !query
+SELECT * FROM t1, LATERAL (SELECT t1.*, t2.* FROM t2, LATERAL (SELECT t1.*, 
t2.*, t3.* FROM t2 AS t3))

Review comment:
       Q: We cannot accept this query? It seems pogresql can though;
   ```
   postgres=# SELECT * FROM t1, LATERAL (SELECT t1.*, t2.* FROM t2, LATERAL 
(SELECT t1.*, t2.*, t3.* FROM t2 AS t3) t) t;
    c1 | c2 | c1 | c2 | c1 | c2 
   ----+----+----+----+----+----
     0 |  1 |  0 |  1 |  0 |  2
     0 |  1 |  0 |  1 |  0 |  2
     0 |  1 |  0 |  1 |  0 |  3
     0 |  1 |  0 |  1 |  0 |  3
     1 |  2 |  1 |  2 |  0 |  2
     1 |  2 |  1 |  2 |  0 |  2
     1 |  2 |  1 |  2 |  0 |  3
     1 |  2 |  1 |  2 |  0 |  3
   ```




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