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 2022/05/12 02:51:28 UTC

[GitHub] [drill] vvysotskyi commented on a diff in pull request #2539: DRILL-8216: Use EVF-based JSON reader for Values operator

vvysotskyi commented on code in PR #2539:
URL: https://github.com/apache/drill/pull/2539#discussion_r870903809


##########
exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/scan/v3/schema/SchemaUtils.java:
##########
@@ -234,4 +241,80 @@ static void copyProperties(TupleMetadata source,
       dest.setProperty(ScanProjectionParser.PROJECTION_TYPE_PROP, value);
     }
   }
+
+  /**
+   * Converts specified {@code RelDataType relDataType} into {@link ColumnMetadata}.
+   * For the case when specified relDataType is struct, map with recursively converted children
+   * will be created.
+   *
+   * @param name        filed name
+   * @param relDataType filed type
+   * @return {@link ColumnMetadata} which corresponds to specified {@code RelDataType relDataType}
+   */
+  public static ColumnMetadata getColumnMetadata(String name, RelDataType relDataType) {
+    switch (relDataType.getSqlTypeName()) {
+      case ARRAY:
+        return getArrayMetadata(name, relDataType);
+      case MAP:
+      case OTHER:
+        throw new UnsupportedOperationException(String.format("Unsupported data type: %s", relDataType.getSqlTypeName()));
+      default:
+        if (relDataType.isStruct()) {
+          return getStructMetadata(name, relDataType);
+        } else {
+          return new PrimitiveColumnMetadata(
+            MaterializedField.create(name,
+              TypeInferenceUtils.getDrillMajorTypeFromCalciteType(relDataType)));
+        }
+    }
+  }
+
+  /**
+   * Returns {@link ColumnMetadata} instance which corresponds to specified array {@code RelDataType relDataType}.
+   *
+   * @param name        name of the filed
+   * @param relDataType the source of type information to construct the schema
+   * @return {@link ColumnMetadata} instance
+   */
+  private static ColumnMetadata getArrayMetadata(String name, RelDataType relDataType) {
+    RelDataType componentType = relDataType.getComponentType();
+    ColumnMetadata childColumnMetadata = getColumnMetadata(name, componentType);
+    switch (componentType.getSqlTypeName()) {
+      case ARRAY:
+        // for the case when nested type is array, it should be placed into repeated list
+        return MetadataUtils.newRepeatedList(name, childColumnMetadata);
+      case MAP:
+      case OTHER:
+        throw new UnsupportedOperationException(String.format("Unsupported data type: %s", relDataType.getSqlTypeName()));
+      default:
+        if (componentType.isStruct()) {
+          // for the case when nested type is struct, it should be placed into repeated map
+          return MetadataUtils.newMapArray(name, childColumnMetadata.tupleSchema());
+        } else {
+          // otherwise creates column metadata with repeated data mode
+          return new PrimitiveColumnMetadata(
+            MaterializedField.create(name,
+              Types.overrideMode(
+                TypeInferenceUtils.getDrillMajorTypeFromCalciteType(componentType),
+                TypeProtos.DataMode.REPEATED)));
+        }
+    }
+  }
+
+  /**
+   * Returns {@link MapColumnMetadata} column metadata created based on specified {@code RelDataType relDataType} with
+   * converted to {@link ColumnMetadata} {@code relDataType}'s children.
+   *
+   * @param name        name of the filed
+   * @param relDataType {@link RelDataType} the source of the children for resulting schema
+   * @return {@link MapColumnMetadata} column metadata
+   */
+  private static MapColumnMetadata getStructMetadata(String name, RelDataType relDataType) {
+    TupleMetadata mapSchema = new TupleSchema();
+    relDataType.getFieldList().stream()
+      .map(field -> getColumnMetadata(field.getName(), field.getType()))

Review Comment:
   In the code it is called struct. Real map types as they are aren't supported for values operator.



-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@drill.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org