Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14014#discussion_r70030569
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetRowConverter.scala
 ---
    @@ -482,13 +482,105 @@ private[parquet] class ParquetRowConverter(
          */
         // scalastyle:on
         private def isElementType(
    -        parquetRepeatedType: Type, catalystElementType: DataType, 
parentName: String): Boolean = {
    +        parquetRepeatedType: Type, catalystElementType: DataType, parent: 
GroupType): Boolean = {
           (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) {           <-- parent
    +          //      repeated int32 element;                 <-- repeatedType
    +          //    }
    +          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) {           <-- parent
    +          //      repeated group element {                <-- repeatedType
    +          //        required binary str (UTF8);
    +          //        required int32 num;
    +          //      };
    +          //    }
    +          true
    +
    +        case (t: GroupType, _) if t.getFieldCount == 1 && t.getName == 
"array" =>
    +          // For legacy 2-level list types generated by parquet-avro 
(Parquet version < 1.6.0),
    +          // e.g.:
    +          //
    +          //    // List<OneTuple<String>> (nullable list, non-null 
elements)
    +          //    optional group my_list (LIST) {           <-- parent
    +          //      repeated group array {                  <-- repeatedType
    +          //        required binary str (UTF8);
    +          //      };
    +          //    }
    +          true
    +
    +        case (t: GroupType, _) if t.getFieldCount == 1 && t.getName == 
parent.getName + "_tuple" =>
    +          // For Parquet data generated by parquet-thrift, e.g.:
    +          //
    +          //    // List<OneTuple<String>> (nullable list, non-null 
elements)
    +          //    optional group my_list (LIST) {           <-- parent
    +          //      repeated group my_list_tuple {          <-- repeatedType
    +          //        required binary str (UTF8);
    +          //      };
    +          //    }
    +          true
    +
    +        case (t: GroupType, _)
    +            if parent.getOriginalType == LIST &&
    +              t.getFieldCount == 1 &&
    +              t.getName == "list" &&
    +              t.getFieldName(0) == "element" =>
    +          // For standard 3-level list types, e.g.:
    +          //
    +          //    // List<String> (list nullable, elements non-null)
    +          //    optional group my_list (LIST) {           <-- parent
    +          //      repeated group list {                   <-- repeatedType
    +          //        required binary element (UTF8);
    +          //      }
    +          //    }
    +          //
    +          // This case branch must appear before the next one. See 
comments of the next case branch
    +          // for details.
    +          false
    +
    +        case (t: GroupType, StructType(fields)) =>
    --- End diff --
    
    Probably it is good to explain why we are explicitly matching `GroupType` 
with `StructType` (because we are trying to determine if `GroupType` represents 
a Struct or just a middle layer?).


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to