Search in sources :

Example 1 with ReadableMetadata

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();
}
Also used : DataType(org.apache.flink.table.types.DataType) RowData(org.apache.flink.table.data.RowData) DataTypes(org.apache.flink.table.api.DataTypes) IOException(java.io.IOException) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) TimestampFormat(org.apache.flink.formats.common.TimestampFormat) RowType(org.apache.flink.table.types.logical.RowType) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Serializable(java.io.Serializable) DeserializationSchema(org.apache.flink.api.common.serialization.DeserializationSchema) Objects(java.util.Objects) ArrayData(org.apache.flink.table.data.ArrayData) List(java.util.List) GenericRowData(org.apache.flink.table.data.GenericRowData) RowKind(org.apache.flink.types.RowKind) Collector(org.apache.flink.util.Collector) JsonRowDataDeserializationSchema(org.apache.flink.formats.json.JsonRowDataDeserializationSchema) Internal(org.apache.flink.annotation.Internal) ReadableMetadata(org.apache.flink.formats.json.canal.CanalJsonDecodingFormat.ReadableMetadata) Pattern(java.util.regex.Pattern) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation) Nullable(javax.annotation.Nullable) DataTypeUtils(org.apache.flink.table.types.utils.DataTypeUtils) DataType(org.apache.flink.table.types.DataType) RowType(org.apache.flink.table.types.logical.RowType)

Aggregations

IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 String.format (java.lang.String.format)1 List (java.util.List)1 Objects (java.util.Objects)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 Internal (org.apache.flink.annotation.Internal)1 DeserializationSchema (org.apache.flink.api.common.serialization.DeserializationSchema)1 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)1 TimestampFormat (org.apache.flink.formats.common.TimestampFormat)1 JsonRowDataDeserializationSchema (org.apache.flink.formats.json.JsonRowDataDeserializationSchema)1 ReadableMetadata (org.apache.flink.formats.json.canal.CanalJsonDecodingFormat.ReadableMetadata)1 JsonNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode)1 DataTypes (org.apache.flink.table.api.DataTypes)1 ArrayData (org.apache.flink.table.data.ArrayData)1 GenericRowData (org.apache.flink.table.data.GenericRowData)1 RowData (org.apache.flink.table.data.RowData)1 DataType (org.apache.flink.table.types.DataType)1