Skip to content

Commit e67327a

Browse files
committed
Update tests to match existing style; strengthen map test
1 parent 3fb3391 commit e67327a

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetIOSuite.scala

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@ class ParquetIOSuite extends QueryTest with ParquetTest with SharedSparkSession
8484
withParquetDataFrame(data)(r => checkAnswer(r, data.map(Row.fromTuple)))
8585
}
8686

87-
testStandardAndLegacyModes("array of struct") {
88-
val data = (1 to 4).map(i => (i, Seq(Tuple1(i), Tuple1(i + 1))))
89-
val expected = (1 to 4).map(i => Row(i, Seq(Row(i), Row(i + 1))))
90-
withParquetDataFrame(data)(r => checkAnswer(r, expected))
91-
}
92-
93-
9487
test("basic data types (without binary)") {
9588
val data = (1 to 4).map { i =>
9689
(i % 2 == 0, i, i.toLong, i.toFloat, i.toDouble)
@@ -211,6 +204,23 @@ class ParquetIOSuite extends QueryTest with ParquetTest with SharedSparkSession
211204
}
212205
}
213206

207+
testStandardAndLegacyModes("array of struct") {
208+
val data = (1 to 4).map { i =>
209+
Tuple1(
210+
Seq(
211+
Tuple1(s"1st_val_$i"),
212+
Tuple1(s"2nd_val_$i")
213+
)
214+
)
215+
}
216+
withParquetDataFrame(data) { df =>
217+
// Structs are converted to `Row`s
218+
checkAnswer(df, data.map { case Tuple1(array) =>
219+
Row(array.map(struct => Row(struct.productIterator.toSeq: _*)))
220+
})
221+
}
222+
}
223+
214224
testStandardAndLegacyModes("nested struct with array of array as field") {
215225
val data = (1 to 4).map(i => Tuple1((i, Seq(Seq(s"val_$i")))))
216226
withParquetDataFrame(data) { df =>
@@ -222,8 +232,16 @@ class ParquetIOSuite extends QueryTest with ParquetTest with SharedSparkSession
222232
}
223233

224234
testStandardAndLegacyModes("nested map with struct as value type") {
225-
val data = (1 to 4).map(i => Tuple1(Map(i -> ((i, s"val_$i")))))
235+
val data = (1 to 4).map { i =>
236+
Tuple1(
237+
Map(
238+
s"kA_$i" -> ((i, s"vA_$i")),
239+
s"kB_$i" -> ((i, s"vB_$i"))
240+
)
241+
)
242+
}
226243
withParquetDataFrame(data) { df =>
244+
// Structs are converted to `Row`s
227245
checkAnswer(df, data.map { case Tuple1(m) =>
228246
Row(m.mapValues(struct => Row(struct.productIterator.toSeq: _*)))
229247
})

0 commit comments

Comments
 (0)