arina-ielchiieva 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_r324581423
##########
File path:
exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReaderUtils.java
##########
@@ -120,4 +94,141 @@ 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 writeColumnsUsingSchema(BaseWriter.ComplexWriter writer,
+ Collection<SchemaPath> columns, TupleMetadata schema, boolean
allTextMode) {
+ BaseWriter.MapWriter mapWriter = writer.rootAsMap();
+ for (SchemaPath column : columns) {
+ if (column.isDynamicStar()) {
+ writeSchemaColumns(schema, mapWriter, allTextMode);
+ } else {
+ ColumnMetadata columnMetadata =
schema.metadata(column.getRootSegmentPath());
+ writeColumnToMapWriter(mapWriter, column.getRootSegment(),
columnMetadata, allTextMode);
+ }
+ }
+ }
+
+ /**
+ * Creates writer for column which corresponds to specified {@code
PathSegment column} with type taken from
+ * the specified {@code ColumnMetadata columnMetadata}.
+ * For the case when specified {@code PathSegment column} is map, writers
only for its child segments will be created.
+ * For thee case when specified {@code PathSegment column} is array segment,
all child writers will be created.
+ *
+ * @param writer parent writer for writers to create
+ * @param column column for which writers should be created
+ * @param columnMetadata column metadata
+ * @param allTextMode whether all primitive writes should be for varchar
type
+ */
+ private static void writeColumnToMapWriter(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);
+ writeColumnToMapWriter(writer.map(name), child, childMetadata,
allTextMode);
+ } else {
+ writeSingleOrArrayColumn(columnMetadata, writer, allTextMode);
+ }
+ }
+
+ /**
+ * Creates writers for specified {@code ColumnMetadata columnMetadata}.
+ * For the case when is array, creates list writer before target is created.
+ *
+ * @param columnMetadata column metadata
+ * @param writer parent writer for writers to create
+ * @param allTextMode whether all primitive writes should be for varchar
type
Review comment:
```suggestion
* @param allTextMode whether all primitive writers should be of
varchar type
```
----------------------------------------------------------------
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