Github user liancheng commented on a diff in the pull request:
https://github.com/apache/spark/pull/14013#discussion_r69283877
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/CatalystRowConverter.scala
---
@@ -481,13 +481,106 @@ private[parquet] class CatalystRowConverter(
*/
// scalastyle:on
private def isElementType(
- parquetRepeatedType: Type, catalystElementType: DataType,
parentName: String): Boolean = {
+ parquetRepeatedType: Type, catalystElementType: DataType, parent:
GroupType): Boolean = {
+
+ def isStandardListLayout(t: GroupType): Boolean =
+ Option(parent.getOriginalType) == Some(LIST) &&
+ t.getFieldCount == 1 &&
+ t.getName == "list" &&
+ t.getFieldName(0) == "element"
+
(parquetRepeatedType, catalystElementType) match {
- case (t: PrimitiveType, _) => true
- case (t: GroupType, _) if t.getFieldCount > 1 => true
- case (t: GroupType, _) if t.getFieldCount == 1 && t.getName ==
"array" => true
- case (t: GroupType, _) if t.getFieldCount == 1 && t.getName ==
parentName + "_tuple" => true
- case (t: GroupType, StructType(Array(f))) if f.name ==
t.getFieldName(0) => true
+ case (t: PrimitiveType, _) =>
+ // For legacy 2-level list types with primitive element type,
e.g.:
+ //
+ // // List<Integer> (nullable list, non-null elements)
+ // optional group my_list (LIST) {
+ // repeated int32 element;
+ // }
+ true
+
+ case (t: GroupType, _) if t.getFieldCount > 1 =>
+ // For legacy 2-level list types whose element type is a group
type with 2 or more fields,
+ // e.g.:
+ //
+ // // List<Tuple<String, Integer>> (nullable list, non-null
elements)
+ // optional group my_list (LIST) {
+ // repeated group element {
+ // required binary str (UTF8);
+ // required int32 num;
+ // };
+ // }
+ true
+
+ case (t: GroupType, _) if t.getFieldCount == 1 && t.getName ==
"array" =>
+ // For Parquet data generated by parquet-thrift, e.g.:
+ //
+ // // List<OneTuple<String>> (nullable list, non-null
elements)
+ // optional group my_list (LIST) {
+ // repeated group my_list_tuple {
+ // required binary str (UTF8);
+ // };
+ // }
+ true
+
+ case (t: GroupType, _) if t.getFieldCount == 1 && t.getName ==
parent + "_tuple" =>
+ // For Parquet data generated by parquet-thrift, e.g.:
+ //
+ // // List<OneTuple<String>> (nullable list, non-null
elements)
+ // optional group my_list (LIST) {
+ // repeated group my_list_tuple {
+ // required binary str (UTF8);
+ // };
+ // }
+ true
+
+ case (t: GroupType, _) if isStandardListLayout(t) =>
+ // For standard 3-level list types, e.g.:
+ //
+ // // List<String> (list nullable, elements non-null)
+ // optional group my_list (LIST) {
+ // repeated group list {
+ // required binary element (UTF8);
+ // }
+ // }
+ //
+ // This case branch must appear before the next one. See
comments of the next case branch
+ // for details.
+ false
--- End diff --
This case branch is essential for the bug fix. Basically, it matches the
standard 3-level layout first before trying to match the legacy 2-level layout,
so that the "element" syntactic group in Parquet LIST won't be mistaken for the
"element" field in the nested struct.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]