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_r212796946
##########
File path:
exec/java-exec/src/main/java/org/apache/drill/exec/physical/rowSet/impl/BuildFromSchema.java
##########
@@ -96,4 +164,89 @@ private void expandMap(ObjectWriter colWriter,
ColumnMetadata colSchema) {
buildTuple(colWriter.tuple(), colSchema.mapSchema());
}
}
+
+ /**
+ * Expand a variant column. We use the term "variant" to mean either
+ * a UNION, or a LIST of UNIONs. (A LIST of UNIONs is, conceptually,
+ * a repeated UNION, though it is far more complex.)
+ *
+ * @param parent shim object used to associate the UNION types with its
+ * parent column (which is a UNION or a LIST). Since UNION and LIST are
+ * far different types, the shim provides a facade that encapsulates
+ * the common behavior
+ * @param colSchema the schema of the variant (LIST or UNION) column
+ */
+
+ 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);
+ }
+ }
+
+ /**
+ * We've just built a writer for column. If the column is structured
+ * (AKA "complex", meaning a map or list or array), then we need to
+ * build writer for the components of the column. We do that recursively
+ * here.
+ *
+ * @param colWriter the writer for the (possibly structured) column
+ * @param colSchema the schema definition for the column
+ */
+
+ private void expandColumn(ObjectWriter colWriter, ColumnMetadata colSchema) {
+
+ if (colSchema.structureType() == StructureType.MULTI_ARRAY) {
Review comment:
use isMultiList method ?
----------------------------------------------------------------
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