Skip to content

Commit bca8c07

Browse files
committed
[SPARK-10434] [SQL] Fixes Parquet schema of arrays that may contain null
To keep full compatibility of Parquet write path with Spark 1.4, we should rename the innermost field name of arrays that may contain null from "array_element" to "array". Please refer to [SPARK-10434] [1] for more details. [1]: https://issues.apache.org/jira/browse/SPARK-10434 Author: Cheng Lian <[email protected]> Closes #8586 from liancheng/spark-10434/fix-parquet-array-type.
1 parent 7a4f326 commit bca8c07

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/CatalystSchemaConverter.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,14 @@ private[parquet] class CatalystSchemaConverter(
426426
// ArrayType and MapType (for Spark versions <= 1.4.x)
427427
// ===================================================
428428

429-
// Spark 1.4.x and prior versions convert ArrayType with nullable elements into a 3-level
430-
// LIST structure. This behavior mimics parquet-hive (1.6.0rc3). Note that this case is
431-
// covered by the backwards-compatibility rules implemented in `isElementType()`.
429+
// Spark 1.4.x and prior versions convert `ArrayType` with nullable elements into a 3-level
430+
// `LIST` structure. This behavior is somewhat a hybrid of parquet-hive and parquet-avro
431+
// (1.6.0rc3): the 3-level structure is similar to parquet-hive while the 3rd level element
432+
// field name "array" is borrowed from parquet-avro.
432433
case ArrayType(elementType, nullable @ true) if !followParquetFormatSpec =>
433434
// <list-repetition> group <name> (LIST) {
434435
// optional group bag {
435-
// repeated <element-type> element;
436+
// repeated <element-type> array;
436437
// }
437438
// }
438439
ConversionPatterns.listType(
@@ -441,8 +442,8 @@ private[parquet] class CatalystSchemaConverter(
441442
Types
442443
.buildGroup(REPEATED)
443444
// "array_element" is the name chosen by parquet-hive (1.7.0 and prior version)
444-
.addField(convertField(StructField("array_element", elementType, nullable)))
445-
.named(CatalystConverter.ARRAY_CONTAINS_NULL_BAG_SCHEMA_NAME))
445+
.addField(convertField(StructField("array", elementType, nullable)))
446+
.named("bag"))
446447

447448
// Spark 1.4.x and prior versions convert ArrayType with non-nullable elements into a 2-level
448449
// LIST structure. This behavior mimics parquet-avro (1.6.0rc3). Note that this case is

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class ParquetSchemaInferenceSuite extends ParquetSchemaTest {
197197
|message root {
198198
| optional group _1 (LIST) {
199199
| repeated group bag {
200-
| optional int32 array_element;
200+
| optional int32 array;
201201
| }
202202
| }
203203
|}
@@ -266,7 +266,7 @@ class ParquetSchemaInferenceSuite extends ParquetSchemaTest {
266266
| optional binary _1 (UTF8);
267267
| optional group _2 (LIST) {
268268
| repeated group bag {
269-
| optional group array_element {
269+
| optional group array {
270270
| required int32 _1;
271271
| required double _2;
272272
| }
@@ -645,7 +645,7 @@ class ParquetSchemaSuite extends ParquetSchemaTest {
645645
"""message root {
646646
| optional group f1 (LIST) {
647647
| repeated group bag {
648-
| optional int32 array_element;
648+
| optional int32 array;
649649
| }
650650
| }
651651
|}

0 commit comments

Comments
 (0)