ueshin opened a new pull request, #36674:
URL: https://github.com/apache/spark/pull/36674
### What changes were proposed in this pull request?
Fix the accumulator of `ArrayAggregate` to handle complex types properly.
The accumulator of `ArrayAggregate` should copy the intermediate result if
string, struct, array, or map.
### Why are the changes needed?
If the intermediate data of `ArrayAggregate` holds reusable data, the result
will be duplicated.
```scala
import org.apache.spark.sql.functions._
val reverse = udf((s: String) => s.reverse)
val df = Seq(Array("abc", "def")).toDF("array")
val testArray = df.withColumn(
"agg",
aggregate(
col("array"),
array().cast("array<string>"),
(acc, s) => concat(acc, array(reverse(s)))))
aggArray.show(truncate=false)
```
should be:
```
+----------+----------+
|array |agg |
+----------+----------+
|[abc, def]|[cba, fed]|
+----------+----------+
```
but:
```
+----------+----------+
|array |agg |
+----------+----------+
|[abc, def]|[fed, fed]|
+----------+----------+
```
### Does this PR introduce _any_ user-facing change?
Yes, this fixes the correctness issue.
### How was this patch tested?
Added a test.
--
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]