cloud-fan commented on code in PR #44645:
URL: https://github.com/apache/spark/pull/44645#discussion_r1448871669
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/RemoveRedundantAliasAndProjectSuite.scala:
##########
@@ -130,4 +131,63 @@ class RemoveRedundantAliasAndProjectSuite extends PlanTest
{
correlated = false)
comparePlans(optimized, expected)
}
+
+ test("SPARK-46640: do not remove outer references from a subquery
expression") {
+ val a = AttributeReference("a", IntegerType)() // a#0
+ // Keep the same name, otherwise the alias is not removed fearing schema
change.
+ val a_alias = Alias(a, "a")() // a#0 as a#1
+ val a_alias_expression = AttributeReference("a", IntegerType)(exprId =
a_alias.exprId) // a#1
+ val b = AttributeReference("b", IntegerType)()
+
+ // The original input query
+ // Filter exists [a#1 && (a#1 = b#2)]
+ // : +- LocalRelation <empty>, [b#2]
+ // +- Project [a#0 AS a#1]
+ // +- LocalRelation <empty>, [a#0]
+ val query = Filter(
+ Exists(
+ LocalRelation(b),
+ outerAttrs = Seq(a_alias_expression),
+ joinCond = Seq(EqualTo(a_alias_expression, b))
+ ),
+ Project(Seq(a_alias), LocalRelation(a))
+ )
+
+ // The alias would not be removed if excluding subquery references is
enabled.
+ // Filter exists [a#1 && (a#1 = b#2)]
+ // : +- LocalRelation <empty>, [b#2]
+ // +- Project [a#0 AS a#1]
+ // +- LocalRelation <empty>, [a#0]
+ val expectedWhenExcluded = Filter(
Review Comment:
`val expectedWhenExcluded = query`?
--
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]