use of org.apache.flink.formats.json.canal.CanalJsonDecodingFormat.ReadableMetadata in project flink by apache.
the class CanalJsonDeserializationSchema method createJsonRowType.
// --------------------------------------------------------------------------------------------
private static RowType createJsonRowType(DataType physicalDataType, List<ReadableMetadata> readableMetadata) {
// Canal JSON contains other information, e.g. "ts", "sql", but we don't need them
DataType root = DataTypes.ROW(DataTypes.FIELD("data", DataTypes.ARRAY(physicalDataType)), DataTypes.FIELD("old", DataTypes.ARRAY(physicalDataType)), DataTypes.FIELD("type", DataTypes.STRING()), ReadableMetadata.DATABASE.requiredJsonField, ReadableMetadata.TABLE.requiredJsonField);
// append fields that are required for reading metadata in the root
final List<DataTypes.Field> rootMetadataFields = readableMetadata.stream().filter(m -> m != ReadableMetadata.DATABASE && m != ReadableMetadata.TABLE).map(m -> m.requiredJsonField).distinct().collect(Collectors.toList());
return (RowType) DataTypeUtils.appendRowFields(root, rootMetadataFields).getLogicalType();
}
Aggregations