[ 
https://issues.apache.org/jira/browse/DRILL-7268?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16860063#comment-16860063
 ] 

ASF GitHub Bot commented on DRILL-7268:
---------------------------------------

vvysotskyi commented on pull request #1805: DRILL-7268: Read Hive array with 
parquet native reader
URL: https://github.com/apache/drill/pull/1805#discussion_r292030401
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/parquet2/DrillParquetGroupConverter.java
 ##########
 @@ -131,43 +132,79 @@ public DrillParquetGroupConverter(OutputMutator mutator, 
MapWriter mapWriter, Gr
         name = type.getName();
       }
 
-      if (!isPrimitive) {
-        Collection<SchemaPath> c = new ArrayList<>();
+      Converter converter = createFieldConverter(skipRepeated, type, name, 
colNextChild);
+      converters.add(converter);
+    }
+  }
 
-        while(colNextChild!=null) {
-          if(colNextChild.isNamed()) {
-            break;
-          }
-          colNextChild=colNextChild.getChild();
-        }
+  private Converter createFieldConverter(boolean skipRepeated, Type fieldType, 
String name, PathSegment colNextChild) {
+    Converter converter;
+    if (fieldType.isPrimitive()) {
+      converter = getConverterForType(name, fieldType.asPrimitiveType());
+    } else {
+      while (colNextChild != null && !colNextChild.isNamed()) {
+        colNextChild = colNextChild.getChild();
+      }
 
-        if(colNextChild!=null) {
-          SchemaPath s = new SchemaPath(colNextChild.getNameSegment());
-          c.add(s);
-        }
-        if (rep != Repetition.REPEATED) {
-          DrillParquetGroupConverter converter = new 
DrillParquetGroupConverter(
-              mutator, mapWriter.map(name), type.asGroupType(), c, options, 
containsCorruptedDates);
-          converters.add(converter);
+      Collection<SchemaPath> c = colNextChild == null
+          ? Collections.emptyList()
+          : Collections.singletonList(new 
SchemaPath(colNextChild.getNameSegment()));
+
+      BaseWriter writer;
+      GroupType fieldGroupType = fieldType.asGroupType();
+      if (isLogicalListType(fieldGroupType)) {
+        writer = getWriter(name, (m, s) -> m.list(s), l -> l.list());
+        converter = new DrillParquetGroupConverter(mutator, writer, 
fieldGroupType, c, options,
+            containsCorruptedDates, true, converterName);
+      } else if (fieldType.isRepetition(Repetition.REPEATED)) {
+        if (skipRepeated && fieldGroupType.getFieldCount() > 0) {
+          converter = new DrillIntermediateParquetGroupConverter(mutator, 
baseWriter, fieldGroupType, c, options,
+              containsCorruptedDates, false, converterName);
         } else {
-          DrillParquetGroupConverter converter = new 
DrillParquetGroupConverter(
-              mutator, mapWriter.list(name).map(), type.asGroupType(), c, 
options, containsCorruptedDates);
-          converters.add(converter);
+          writer = getWriter(name, (m, s) -> m.list(s).map(), l -> 
l.list().map());
+          converter = new DrillParquetGroupConverter(mutator, writer, 
fieldGroupType, c, options,
+              containsCorruptedDates, false, converterName);
         }
       } else {
-        PrimitiveConverter converter = getConverterForType(name, 
type.asPrimitiveType());
-        converters.add(converter);
+        writer = getWriter(name, (m, s) -> m.map(s), l -> l.map());
+        converter = new DrillParquetGroupConverter(mutator, writer, 
fieldGroupType, c, options,
+            containsCorruptedDates, false, converterName);
       }
+
     }
+    return converter;
   }
 
-  private PrimitiveConverter getConverterForType(String name, PrimitiveType 
type) {
+  /**
+   * Checks whether group field approximately matches pattern for Logical 
Lists:
+   * <list-repetition> group <name> (LIST) {
+   *   repeated group list {
+   *     <element-repetition> <element-type> element;
+   *   }
+   * }
+   * (See for more details: 
https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#lists)
+   *
+   * Note, that standard field names 'list' and 'element' aren't checked 
intentionally,
+   * because Hive lists have 'bag' and 'array_element' names instead.
+   *
+   * @param groupType type which may have LIST original type
+   * @return whether the type is LIST and nested field is repeated group
+   */
+  private boolean isLogicalListType(GroupType groupType) {
+    if (groupType.getOriginalType() == OriginalType.LIST && 
groupType.getFieldCount() == 1) {
+      Type nestedField = groupType.getFields().get(0);
+      return nestedField.isRepetition(Repetition.REPEATED)
+          && !nestedField.isPrimitive()
+          && nestedField.getOriginalType() == null;
 
 Review comment:
   Please also check `nestedField.asGroupType().getFieldCount() == 1` to ensure 
that nested field has single field, according to the `LogicalTypes.md` doc.
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Read Hive array with parquet native reader
> ------------------------------------------
>
>                 Key: DRILL-7268
>                 URL: https://issues.apache.org/jira/browse/DRILL-7268
>             Project: Apache Drill
>          Issue Type: Sub-task
>            Reporter: Igor Guzenko
>            Assignee: Igor Guzenko
>            Priority: Major
>             Fix For: 1.17.0
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to