use of org.apache.flink.table.planner.plan.nodes.exec.serde.DataTypeJsonSerializer.FIELD_NAME_KEY_CLASS in project flink by apache.
the class DataTypeJsonDeserializer method deserializeClass.
private static DataType deserializeClass(LogicalType logicalType, @Nullable JsonNode parentNode, SerdeContext serdeContext) {
if (parentNode == null) {
return DataTypes.of(logicalType);
}
final DataType dataType;
switch(logicalType.getTypeRoot()) {
case ARRAY:
case MULTISET:
final DataType elementDataType = deserializeClass(logicalType.getChildren().get(0), parentNode.get(FIELD_NAME_ELEMENT_CLASS), serdeContext);
dataType = new CollectionDataType(logicalType, elementDataType);
break;
case MAP:
final MapType mapType = (MapType) logicalType;
final DataType keyDataType = deserializeClass(mapType.getKeyType(), parentNode.get(FIELD_NAME_KEY_CLASS), serdeContext);
final DataType valueDataType = deserializeClass(mapType.getValueType(), parentNode.get(FIELD_NAME_VALUE_CLASS), serdeContext);
dataType = new KeyValueDataType(mapType, keyDataType, valueDataType);
break;
case ROW:
case STRUCTURED_TYPE:
final List<String> fieldNames = LogicalTypeChecks.getFieldNames(logicalType);
final List<LogicalType> fieldTypes = LogicalTypeChecks.getFieldTypes(logicalType);
final ArrayNode fieldNodes = (ArrayNode) parentNode.get(FIELD_NAME_FIELDS);
final Map<String, JsonNode> fieldNodesByName = new HashMap<>();
if (fieldNodes != null) {
fieldNodes.forEach(fieldNode -> fieldNodesByName.put(fieldNode.get(FIELD_NAME_FIELD_NAME).asText(), fieldNode));
}
final List<DataType> fieldDataTypes = IntStream.range(0, fieldNames.size()).mapToObj(i -> {
final String fieldName = fieldNames.get(i);
final LogicalType fieldType = fieldTypes.get(i);
return deserializeClass(fieldType, fieldNodesByName.get(fieldName), serdeContext);
}).collect(Collectors.toList());
dataType = new FieldsDataType(logicalType, fieldDataTypes);
break;
case DISTINCT_TYPE:
final DistinctType distinctType = (DistinctType) logicalType;
dataType = deserializeClass(distinctType.getSourceType(), parentNode, serdeContext);
break;
default:
dataType = DataTypes.of(logicalType);
}
if (!parentNode.has(FIELD_NAME_CONVERSION_CLASS)) {
return dataType;
}
final Class<?> conversionClass = loadClass(parentNode.get(FIELD_NAME_CONVERSION_CLASS).asText(), serdeContext, String.format("conversion class of data type '%s'", dataType));
return dataType.bridgedTo(conversionClass);
}
Aggregations