cloud-fan commented on code in PR #58084:
URL: https://github.com/apache/spark/pull/58084#discussion_r3823271053
##########
sql/core/src/test/scala/org/apache/spark/sql/SQLInsertTestSuite.scala:
##########
@@ -591,6 +591,71 @@ trait SQLInsertTestSuite extends QueryTest with
AdaptiveSparkPlanHelper {
}
}
}
+
+ test("SPARK-58816: insert with column list resolves structs inside arrays
positionally") {
+ withTable("t") {
+ createTable("t", Seq("arr"), Seq("ARRAY<STRUCT<x: INT, y: INT>>"))
+ sql("INSERT INTO t (arr) SELECT array(named_struct('y', 20, 'x', 10))")
+ checkAnswer(spark.table("t"), Row(Seq(Row(20, 10))))
+ }
+ }
+
+ test("SPARK-58816: insert with column list resolves structs inside maps
positionally") {
+ withTable("t") {
+ createTable("t", Seq("m"), Seq("MAP<STRING, STRUCT<x: INT, y: INT>>"))
+ sql("INSERT INTO t (m) SELECT map('k', named_struct('y', 20, 'x', 10))")
+ checkAnswer(spark.table("t"), Row(Map("k" -> Row(20, 10))))
+ }
+ }
+
+ test("SPARK-58816: insert with column list resolves structs in map keys
positionally") {
+ // Hive Metastore only supports primitive types for Map keys.
+ if (!format.startsWith("hive")) {
+ withTable("t") {
+ createTable("t", Seq("m"), Seq("MAP<STRUCT<x: INT, y: INT>, STRING>"))
+ sql("INSERT INTO t (m) SELECT map(named_struct('y', 20, 'x', 10),
'val')")
+ checkAnswer(spark.table("t"), Row(Map(Row(20, 10) -> "val")))
+ }
+ }
+ }
+
+ test("SPARK-58816: insert with column list resolves structs positionally " +
+ "at all nesting levels") {
+ withTable("t") {
+ createTable(
+ "t",
+ Seq("s", "arr", "m"),
+ Seq(
+ "STRUCT<x: INT, y: INT>",
+ "ARRAY<STRUCT<x: INT, y: INT>>",
+ "MAP<STRING, STRUCT<x: INT, y: INT>>"))
+ sql(
+ """INSERT INTO t (s, arr, m)
+ |SELECT
+ | named_struct('y', 20, 'x', 10),
+ | array(named_struct('y', 20, 'x', 10)),
+ | map('k', named_struct('y', 20, 'x', 10))
+ |""".stripMargin)
+ checkAnswer(
+ spark.table("t"),
+ Row(Row(20, 10), Seq(Row(20, 10)), Map("k" -> Row(20, 10))))
+ }
+ }
+
+ test("SPARK-58816: insert with column list resolves deeply nested mixed " +
+ "collections positionally") {
+ withTable("t") {
+ createTable(
+ "t",
+ Seq("nested_arr"),
+ Seq("ARRAY<STRUCT<nested: ARRAY<STRUCT<x: INT, y: INT>>>>"))
Review Comment:
**Non-blocking:**
This case never crosses from one collection kind into another: the schema is
only `ARRAY<STRUCT<ARRAY<STRUCT>>>`. Please exercise an Array-to-Map or
Map-to-Array shape here so the new mutual recursion between the `ArrayType` and
`MapType` branches has regression coverage.
--
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]