arina-ielchiieva commented on a change in pull request #1819: DRILL-7313: Use 
Hive schema for MaprDB native reader when field was empty
URL: https://github.com/apache/drill/pull/1819#discussion_r299881301
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReaderUtils.java
 ##########
 @@ -33,25 +38,48 @@ public static void 
ensureAtLeastOneField(BaseWriter.ComplexWriter writer,
                                     boolean allTextMode,
                                     List<BaseWriter.ListWriter> 
emptyArrayWriters) {
 
-    List<BaseWriter.MapWriter> writerList = Lists.newArrayList();
-    List<PathSegment> fieldPathList = Lists.newArrayList();
+    ensureAtLeastOneField(writer, columns, null /* schema */, allTextMode, 
emptyArrayWriters);
+  }
+
+  public static void ensureAtLeastOneField(BaseWriter.ComplexWriter writer,
+                                           Collection<SchemaPath> columns,
+                                           TupleMetadata schema,
+                                           boolean allTextMode,
+                                           List<BaseWriter.ListWriter> 
emptyArrayWriters) {
+
+    List<BaseWriter.MapWriter> writerList = new ArrayList<>();
+    List<PathSegment> fieldPathList = new ArrayList<>();
+    List<TypeProtos.MajorType> types = new ArrayList<>();
     BitSet emptyStatus = new BitSet(columns.size());
-    int i = 0;
+    int fieldIndex = 0;
 
     // first pass: collect which fields are empty
-    for (SchemaPath sp : columns) {
-      PathSegment fieldPath = sp.getRootSegment();
+    for (SchemaPath schemaPath : columns) {
+      PathSegment fieldPath = schemaPath.getRootSegment();
       BaseWriter.MapWriter fieldWriter = writer.rootAsMap();
+      TupleMetadata columnMetadata = schema;
       while (fieldPath.getChild() != null && !fieldPath.getChild().isArray()) {
-        fieldWriter = fieldWriter.map(fieldPath.getNameSegment().getPath());
+        String name = fieldPath.getNameSegment().getPath();
+        if (columnMetadata != null) {
+          ColumnMetadata metadata = columnMetadata.metadata(name);
+          columnMetadata = metadata != null ? metadata.mapSchema() : null;
+        }
+        fieldWriter = fieldWriter.map(name);
         fieldPath = fieldPath.getChild();
       }
       writerList.add(fieldWriter);
       fieldPathList.add(fieldPath);
+      // for the case when field is absent in the schema, use INT type
+      TypeProtos.MajorType majorType = 
Types.optional(TypeProtos.MinorType.INT);
 
 Review comment:
   Maybe we add support for all text mode for MaprDB option in the scope of 
this Jira as well?

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to