cloud-fan commented on a change in pull request #32303:
URL: https://github.com/apache/spark/pull/32303#discussion_r647207140
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/ResolveSubquerySuite.scala
##########
@@ -53,4 +58,117 @@ class ResolveSubquerySuite extends AnalysisTest {
JoinHint.NONE)
assertAnalysisSuccess(expr)
}
+
+ test("deduplicate lateral subquery") {
+ val plan = LateralJoin(t1, LateralSubquery(t0.select('a)), Inner, None)
+ // The subquery's output OuterReference(a#0) conflicts with the left child
output
+ // attribute a#0. So an alias should be added to deduplicate the
subquery's outputs.
+ val expected = LateralJoin(
+ t1,
+ LateralSubquery(Project(Seq(OuterReference(a).as(a.name)), t0), Seq(a)),
+ Inner,
+ None)
+ checkAnalysis(plan, expected)
+ }
+
+ test("lateral join with ambiguous join conditions") {
+ val plan = LateralJoin(t1, LateralSubquery(t0.select('b)), Inner, Some('b
=== 1))
+ assertAnalysisError(plan, "Reference 'b' is ambiguous, could be: b, b." ::
Nil)
+ }
+
+ test("prefer resolving lateral subquery attributes from the inner query") {
+ val plan = LateralJoin(t1, LateralSubquery(t2.select('a, 'b, 'c)), Inner,
None)
+ val expected = LateralJoin(
+ t1,
+ LateralSubquery(Project(Seq(OuterReference(a).as(a.name), b, c), t2),
Seq(a)),
+ Inner, None)
+ checkAnalysis(plan, expected)
+ }
+
+ test("qualified column names in lateral subquery") {
+ val t1b = b.withQualifier(Seq("t1"))
+ val t2b = b.withQualifier(Seq("t2"))
+ checkAnalysis(
+ LateralJoin(t1.as("t1"), LateralSubquery(t0.select($"t1.b")), Inner,
None),
+ LateralJoin(
+ t1,
+ LateralSubquery(Project(Seq(OuterReference(t1b).as(b.name)), t0),
Seq(t1b)),
+ Inner, None)
+ )
+ checkAnalysis(
+ LateralJoin(
+ t1.as("t1"),
+ LateralSubquery(t2.as("t2").select($"t1.b", $"t2.b")),
+ Inner, None),
+ LateralJoin(
+ t1,
+ LateralSubquery(Project(Seq(OuterReference(t1b).as(b.name), t2b),
t2.as("t2")), Seq(t1b)),
+ Inner, None)
+ )
+ }
+
+ test("resolve nested lateral subqueries") {
+ // SELECT * FROM t1, LATERAL (SELECT * FROM t2, LATERAL (SELECT b, c))
+ val plan = LateralJoin(t1,
+ LateralSubquery(
+ LateralJoin(t2, LateralSubquery(t0.select('b, 'c)), Inner, None)),
Review comment:
can we test a query here that refers to the outer plan instead of just
t2? e.g. `t2.select('a, 'b, 'c)`
--
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]