[SPARK-21203][SQL] Fix wrong results of insertion of Array of Struct
### What changes were proposed in this pull request? ```SQL CREATE TABLE `tab1` (`custom_fields` ARRAY<STRUCT<`id`: BIGINT, `value`: STRING>>) USING parquet INSERT INTO `tab1` SELECT ARRAY(named_struct('id', 1, 'value', 'a'), named_struct('id', 2, 'value', 'b')) SELECT custom_fields.id, custom_fields.value FROM tab1 ``` The above query always return the last struct of the array, because the rule `SimplifyCasts` incorrectly rewrites the query. The underlying cause is we always use the same `GenericInternalRow` object when doing the cast. ### How was this patch tested? Author: gatorsmile <gatorsmile@gmail.com> Closes #18412 from gatorsmile/castStruct.
Showing
- sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala 2 additions, 2 deletions...cala/org/apache/spark/sql/catalyst/expressions/Cast.scala
- sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala 21 additions, 0 deletions...test/scala/org/apache/spark/sql/sources/InsertSuite.scala
Loading
Please register or sign in to comment