[
https://issues.apache.org/jira/browse/DRILL-8216?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17535137#comment-17535137
]
ASF GitHub Bot commented on DRILL-8216:
---------------------------------------
cgivre commented on code in PR #2539:
URL: https://github.com/apache/drill/pull/2539#discussion_r870823130
##########
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:
What would happen here if you have a nested map? IE something like this:
```
{
"field1": {
"nested_field1":"something",
"nested_field2": {
"really_nested":"something",
"real_nested2":"something_else"
}
}
}
```
Or are nested schemata not supported for `VALUES()` operator?
> Use EVF-based JSON reader for Values operator
> ---------------------------------------------
>
> Key: DRILL-8216
> URL: https://issues.apache.org/jira/browse/DRILL-8216
> Project: Apache Drill
> Issue Type: Sub-task
> Reporter: Vova Vysotskyi
> Assignee: Vova Vysotskyi
> Priority: Major
>
> The newer Calcite version simplifies and removes casts for literals. It
> causes wrong results for drillTypeOf and sqlTypeOf functions, since the
> Values operator uses an old JSON reader which reads integers with bigInt type.
--
This message was sent by Atlassian Jira
(v8.20.7#820007)