kelvinjian-db commented on code in PR #46780:
URL: https://github.com/apache/spark/pull/46780#discussion_r1617970968
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/CollapseProjectSuite.scala:
##########
@@ -266,4 +267,35 @@ class CollapseProjectSuite extends PlanTest {
val expected = relation.select(($"a" + $"b").as("C")).analyze
comparePlans(optimized, expected)
}
+
+ test("ES-1102888: collapse project duplicating aggregate expressions in
UDF") {
+ withSQLConf(SQLConf.AVOID_COLLAPSE_UDF_WITH_EXPENSIVE_EXPR.key -> "true") {
+ val pythonUdf = (e: Expression) => {
+ PythonUDF("udf", null, ArrayType(IntegerType), Seq(e), 0,
udfDeterministic = true)
+ }
+
+ val query = testRelation
+ .groupBy($"a")(collectList($"b").as("l1"))
+ .select(pythonUdf($"l1").as("l2"))
+ .select(CreateArray(Seq(
+ GetArrayItem($"l2", 0),
+ GetArrayItem($"l2", 1),
+ GetArrayItem($"l2", 2),
+ GetArrayItem($"l2", 3)
+ )))
+ .analyze
+
+ val optimized = Optimize.execute(query)
+ val expected = testRelation
+ .groupBy($"a")(pythonUdf(collectList($"b")).as("l2"))
Review Comment:
this technically is also a negative test, since before this change, this
would've been collapsed into a single `Aggregate` node (without the `Project`)
--
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]