ppadma commented on a change in pull request #1429: DRILL-6676: Add Union, List 
and Repeated List types to Result Set Loader
URL: https://github.com/apache/drill/pull/1429#discussion_r211064266
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/physical/rowSet/impl/BuildFromSchema.java
 ##########
 @@ -96,4 +132,67 @@ private void expandMap(ObjectWriter colWriter, 
ColumnMetadata colSchema) {
       buildTuple(colWriter.tuple(), colSchema.mapSchema());
     }
   }
+
+  private void buildVariant(ParentShim parent, ColumnMetadata colSchema) {
+    final ObjectWriter colWriter = parent.add(colSchema.cloneEmpty());
+    expandVariant(colWriter, colSchema);
+  }
+
+  private void expandVariant(ObjectWriter colWriter, ColumnMetadata colSchema) 
{
+    if (colSchema.isArray()) {
+      buildUnion(colWriter.array().variant(), colSchema.variantSchema());
+    } else {
+      buildUnion(colWriter.variant(), colSchema.variantSchema());
+    }
+  }
+
+  public void buildUnion(VariantWriter writer, VariantMetadata schema) {
+    final UnionShim unionShim = new UnionShim(writer);
+    for (final ColumnMetadata member : schema.members()) {
+      buildColumn(unionShim, member);
+    }
+  }
+
+  private void buildSingleList(ParentShim parent, ColumnMetadata colSchema) {
+    final ColumnMetadata seed = colSchema.cloneEmpty();
+    final ColumnMetadata subtype = colSchema.variantSchema().listSubtype();
+    seed.variantSchema().addType(subtype.cloneEmpty());
+    seed.variantSchema().becomeSimple();
+    final ObjectWriter listWriter = parent.add(seed);
+    expandColumn(listWriter, subtype);
+  }
+
+  /**
+   * Expand a repeated list. The list may be multi-dimensional, meaning that
+   * it may have may layers of other repeated lists before we get to the 
element
+   * (inner-most) array.
+   *
+   * @param writer tuple writer for the tuple that holds the array
+   * @param colSchema schema definition of the array
+   */
+
+  private void buildRepeatedList(ParentShim parent, ColumnMetadata colSchema) {
+    final ColumnMetadata seed = colSchema.cloneEmpty();
+    final RepeatedListWriter listWriter = (RepeatedListWriter) 
parent.add(seed).array();
+    final ColumnMetadata elements = colSchema.childSchema();
+    if (elements != null) {
+      final RepeatedListShim listShim = new RepeatedListShim(listWriter);
+      buildColumn(listShim, elements);
+    }
+  }
+
+  private void expandColumn(ObjectWriter colWriter, ColumnMetadata colSchema) {
+
+    if (colSchema.structureType() == StructureType.MULTI_ARRAY) {
+      assert false;
+    } else if (colSchema.isMap()) {
+      expandMap(colWriter, colSchema);
+    } else if (isSingleList(colSchema)) {
+      assert false;
+    } else if (colSchema.isVariant()) {
+      expandVariant(colWriter, colSchema);
+    } else {
+      // Nothing to expand for primitives
 
 Review comment:
   no need for this else then ? you can leave the comment. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to