Search in sources :

Example 11 with EncodingFormat

use of org.apache.flink.table.connector.format.EncodingFormat in project flink by apache.

the class OrcFileFormatFactory method createEncodingFormat.

@Override
public EncodingFormat<BulkWriter.Factory<RowData>> createEncodingFormat(DynamicTableFactory.Context context, ReadableConfig formatOptions) {
    return new EncodingFormat<BulkWriter.Factory<RowData>>() {

        @Override
        public BulkWriter.Factory<RowData> createRuntimeEncoder(DynamicTableSink.Context sinkContext, DataType consumedDataType) {
            RowType formatRowType = (RowType) consumedDataType.getLogicalType();
            LogicalType[] orcTypes = formatRowType.getChildren().toArray(new LogicalType[0]);
            TypeDescription typeDescription = OrcSplitReaderUtil.logicalTypeToOrcType(formatRowType);
            return new OrcBulkWriterFactory<>(new RowDataVectorizer(typeDescription.toString(), orcTypes), getOrcProperties(formatOptions), new Configuration());
        }

        @Override
        public ChangelogMode getChangelogMode() {
            return ChangelogMode.insertOnly();
        }
    };
}
Also used : EncodingFormat(org.apache.flink.table.connector.format.EncodingFormat) OrcBulkWriterFactory(org.apache.flink.orc.writer.OrcBulkWriterFactory) RowData(org.apache.flink.table.data.RowData) RowDataVectorizer(org.apache.flink.orc.vector.RowDataVectorizer) Configuration(org.apache.hadoop.conf.Configuration) BulkWriter(org.apache.flink.api.common.serialization.BulkWriter) DataType(org.apache.flink.table.types.DataType) RowType(org.apache.flink.table.types.logical.RowType) LogicalType(org.apache.flink.table.types.logical.LogicalType) TypeDescription(org.apache.orc.TypeDescription)

Example 12 with EncodingFormat

use of org.apache.flink.table.connector.format.EncodingFormat in project flink by apache.

the class CanalJsonFormatFactory method createEncodingFormat.

@Override
public EncodingFormat<SerializationSchema<RowData>> createEncodingFormat(DynamicTableFactory.Context context, ReadableConfig formatOptions) {
    FactoryUtil.validateFactoryOptions(this, formatOptions);
    validateEncodingFormatOptions(formatOptions);
    TimestampFormat timestampFormat = JsonFormatOptionsUtil.getTimestampFormat(formatOptions);
    JsonFormatOptions.MapNullKeyMode mapNullKeyMode = JsonFormatOptionsUtil.getMapNullKeyMode(formatOptions);
    String mapNullKeyLiteral = formatOptions.get(JSON_MAP_NULL_KEY_LITERAL);
    final boolean encodeDecimalAsPlainNumber = formatOptions.get(ENCODE_DECIMAL_AS_PLAIN_NUMBER);
    return new EncodingFormat<SerializationSchema<RowData>>() {

        @Override
        public ChangelogMode getChangelogMode() {
            return ChangelogMode.newBuilder().addContainedKind(RowKind.INSERT).addContainedKind(RowKind.UPDATE_BEFORE).addContainedKind(RowKind.UPDATE_AFTER).addContainedKind(RowKind.DELETE).build();
        }

        @Override
        public SerializationSchema<RowData> createRuntimeEncoder(DynamicTableSink.Context context, DataType consumedDataType) {
            final RowType rowType = (RowType) consumedDataType.getLogicalType();
            return new CanalJsonSerializationSchema(rowType, timestampFormat, mapNullKeyMode, mapNullKeyLiteral, encodeDecimalAsPlainNumber);
        }
    };
}
Also used : EncodingFormat(org.apache.flink.table.connector.format.EncodingFormat) JsonFormatOptions(org.apache.flink.formats.json.JsonFormatOptions) RowData(org.apache.flink.table.data.RowData) DataType(org.apache.flink.table.types.DataType) RowType(org.apache.flink.table.types.logical.RowType) TimestampFormat(org.apache.flink.formats.common.TimestampFormat)

Example 13 with EncodingFormat

use of org.apache.flink.table.connector.format.EncodingFormat in project flink by apache.

the class TestDynamicTableFactory method createDynamicTableSink.

@Override
public DynamicTableSink createDynamicTableSink(Context context) {
    final TableFactoryHelper helper = FactoryUtil.createTableFactoryHelper(this, context);
    final Optional<EncodingFormat<SerializationSchema<RowData>>> keyFormat = helper.discoverOptionalEncodingFormat(SerializationFormatFactory.class, KEY_FORMAT);
    final EncodingFormat<SerializationSchema<RowData>> valueFormat = helper.discoverOptionalEncodingFormat(SerializationFormatFactory.class, FORMAT).orElseGet(() -> helper.discoverEncodingFormat(SerializationFormatFactory.class, VALUE_FORMAT));
    helper.validate();
    return new DynamicTableSinkMock(helper.getOptions().get(TARGET), helper.getOptions().get(BUFFER_SIZE), keyFormat.orElse(null), valueFormat);
}
Also used : EncodingFormat(org.apache.flink.table.connector.format.EncodingFormat) RowData(org.apache.flink.table.data.RowData) SerializationSchema(org.apache.flink.api.common.serialization.SerializationSchema) TableFactoryHelper(org.apache.flink.table.factories.FactoryUtil.TableFactoryHelper)

Aggregations

EncodingFormat (org.apache.flink.table.connector.format.EncodingFormat)13 RowData (org.apache.flink.table.data.RowData)13 DataType (org.apache.flink.table.types.DataType)12 RowType (org.apache.flink.table.types.logical.RowType)11 TimestampFormat (org.apache.flink.formats.common.TimestampFormat)5 JsonFormatOptions (org.apache.flink.formats.json.JsonFormatOptions)4 BulkWriter (org.apache.flink.api.common.serialization.BulkWriter)2 SerializationSchema (org.apache.flink.api.common.serialization.SerializationSchema)2 ReadableConfig (org.apache.flink.configuration.ReadableConfig)2 ValidationException (org.apache.flink.table.api.ValidationException)2 Collections (java.util.Collections)1 Set (java.util.Set)1 StringEscapeUtils (org.apache.commons.lang3.StringEscapeUtils)1 Internal (org.apache.flink.annotation.Internal)1 Factory (org.apache.flink.api.common.serialization.BulkWriter.Factory)1 ConfigOption (org.apache.flink.configuration.ConfigOption)1 DeliveryGuarantee (org.apache.flink.connector.base.DeliveryGuarantee)1 FileSourceSplit (org.apache.flink.connector.file.src.FileSourceSplit)1 StreamFormatAdapter (org.apache.flink.connector.file.src.impl.StreamFormatAdapter)1 BulkFormat (org.apache.flink.connector.file.src.reader.BulkFormat)1