You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by GitBox <gi...@apache.org> on 2019/09/16 08:33:55 UTC

[GitHub] [drill] vvysotskyi commented on a change in pull request #1856: DRILL-7376: Drill ignores Hive schema for MaprDB tables when group scan has star column

vvysotskyi commented on a change in pull request #1856: DRILL-7376: Drill ignores Hive schema for MaprDB tables when group scan has star column
URL: https://github.com/apache/drill/pull/1856#discussion_r324553673
 
 

 ##########
 File path: exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReaderUtils.java
 ##########
 @@ -120,4 +95,100 @@ public static void ensureAtLeastOneField(BaseWriter.ComplexWriter writer,
       }
     }
   }
+
+  /**
+   * Creates writers which correspond to the specified schema for specified root writer.
+   *
+   * @param writer      parent writer for writers to create
+   * @param columns     collection of columns for which writers should be created
+   * @param schema      table schema
+   * @param allTextMode whether all primitive writes should be for varchar type
+   */
+  public static void writeColumnsFromSchema(BaseWriter.ComplexWriter writer,
+      Collection<SchemaPath> columns, TupleMetadata schema, boolean allTextMode) {
+    Preconditions.checkArgument(schema != null, "Schema was not provided");
+    BaseWriter.MapWriter mapWriter = writer.rootAsMap();
+    for (SchemaPath column : columns) {
+      if (column.isDynamicStar()) {
+        writeColumnsForSchema(mapWriter, schema, allTextMode);
+      } else {
+        ColumnMetadata columnMetadata = schema.metadata(column.getRootSegmentPath());
+        writeToMap(mapWriter, column.getRootSegment(), columnMetadata, allTextMode);
+      }
+    }
+  }
+
+  private static void writeToMap(BaseWriter.MapWriter writer,
+      PathSegment column, ColumnMetadata columnMetadata, boolean allTextMode) {
+    PathSegment child = column.getChild();
+    if (child != null && child.isNamed()) {
+      String name = column.getNameSegment().getPath();
+      ColumnMetadata childMetadata = columnMetadata.mapSchema().metadata(name);
+      writeToMap(writer.map(name), child, childMetadata, allTextMode);
+    } else {
+      writeWithArray(columnMetadata, writer, allTextMode);
+    }
+  }
+
+  private static void writeWithArray(ColumnMetadata columnMetadata,
+      BaseWriter.MapWriter writer, boolean allTextMode) {
+    if (columnMetadata.isArray()) {
+      writeColumn(columnMetadata, writer.list(columnMetadata.name()), allTextMode);
+    } else {
+      writeColumn(columnMetadata, writer, allTextMode);
+    }
+  }
+
+  private static void writeColumnsForSchema(BaseWriter.MapWriter fieldWriter,
+      TupleMetadata schema, boolean allTextMode) {
+    for (ColumnMetadata columnMetadata : schema) {
+      writeWithArray(columnMetadata, fieldWriter, allTextMode);
+    }
+  }
+
+  private static void writeColumn(ColumnMetadata columnMetadata,
+      BaseWriter.MapWriter fieldWriter, boolean allTextMode) {
+    switch (columnMetadata.structureType()) {
+      case TUPLE:
+        writeColumnsForSchema(
+            fieldWriter.map(columnMetadata.name()), columnMetadata.mapSchema(), allTextMode);
+        break;
+      case MULTI_ARRAY:
+        writeColumn(columnMetadata.childSchema(), fieldWriter.list(columnMetadata.name()), allTextMode);
+        break;
+      case PRIMITIVE:
+        if (allTextMode) {
+          fieldWriter.varChar(columnMetadata.name());
+        } else {
+          ComplexCopier.getMapWriterForType(
+              columnMetadata.majorType(), fieldWriter, columnMetadata.name());
+        }
+        break;
+      default:
+        throw new UnsupportedOperationException(
 
 Review comment:
   Thanks, added.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services