Search in sources :

Example 16 with DeserializationSchema

use of org.apache.flink.api.common.serialization.DeserializationSchema in project flink by apache.

the class FileSystemTableSink method createCompactReaderFactory.

private Optional<CompactReader.Factory<RowData>> createCompactReaderFactory(Context context) {
    // Compute producedDataType (including partition fields) and physicalDataType (excluding
    // partition fields)
    final DataType producedDataType = physicalRowDataType;
    final DataType physicalDataType = DataType.getFields(producedDataType).stream().filter(field -> !partitionKeys.contains(field.getName())).collect(Collectors.collectingAndThen(Collectors.toList(), DataTypes::ROW));
    if (bulkReaderFormat != null) {
        final BulkFormat<RowData, FileSourceSplit> format = new FileInfoExtractorBulkFormat(bulkReaderFormat.createRuntimeDecoder(createSourceContext(context), physicalDataType), producedDataType, context.createTypeInformation(producedDataType), Collections.emptyMap(), partitionKeys, defaultPartName);
        return Optional.of(CompactBulkReader.factory(format));
    } else if (deserializationFormat != null) {
        final DeserializationSchema<RowData> decoder = deserializationFormat.createRuntimeDecoder(createSourceContext(context), physicalDataType);
        final BulkFormat<RowData, FileSourceSplit> format = new FileInfoExtractorBulkFormat(new DeserializationSchemaAdapter(decoder), producedDataType, context.createTypeInformation(producedDataType), Collections.emptyMap(), partitionKeys, defaultPartName);
        return Optional.of(CompactBulkReader.factory(format));
    }
    return Optional.empty();
}
Also used : DataType(org.apache.flink.table.types.DataType) CompactBulkReader(org.apache.flink.connector.file.table.stream.compact.CompactBulkReader) DecodingFormat(org.apache.flink.table.connector.format.DecodingFormat) PartitionCommitInfo(org.apache.flink.connector.file.table.stream.PartitionCommitInfo) SupportsPartitioning(org.apache.flink.table.connector.sink.abilities.SupportsPartitioning) FSDataOutputStream(org.apache.flink.core.fs.FSDataOutputStream) Path(org.apache.flink.core.fs.Path) Map(java.util.Map) SINK_ROLLING_POLICY_CHECK_INTERVAL(org.apache.flink.connector.file.table.FileSystemConnectorOptions.SINK_ROLLING_POLICY_CHECK_INTERVAL) StreamingFileSink(org.apache.flink.streaming.api.functions.sink.filesystem.StreamingFileSink) AUTO_COMPACTION(org.apache.flink.connector.file.table.FileSystemConnectorOptions.AUTO_COMPACTION) PartFileInfo(org.apache.flink.streaming.api.functions.sink.filesystem.PartFileInfo) CheckpointRollingPolicy(org.apache.flink.streaming.api.functions.sink.filesystem.rollingpolicies.CheckpointRollingPolicy) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation) PartitionPathUtils(org.apache.flink.table.utils.PartitionPathUtils) OutputFormat(org.apache.flink.api.common.io.OutputFormat) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) SINK_ROLLING_POLICY_ROLLOVER_INTERVAL(org.apache.flink.connector.file.table.FileSystemConnectorOptions.SINK_ROLLING_POLICY_ROLLOVER_INTERVAL) CompactOperator.convertToUncompacted(org.apache.flink.connector.file.table.stream.compact.CompactOperator.convertToUncompacted) UUID(java.util.UUID) Preconditions(org.apache.flink.util.Preconditions) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) FileSystem(org.apache.flink.core.fs.FileSystem) FactoryUtil(org.apache.flink.table.factories.FactoryUtil) LogicalType(org.apache.flink.table.types.logical.LogicalType) DataStreamSinkProvider(org.apache.flink.table.connector.sink.DataStreamSinkProvider) SimpleVersionedSerializer(org.apache.flink.core.io.SimpleVersionedSerializer) ValidationException(org.apache.flink.table.api.ValidationException) Optional(java.util.Optional) BulkFormat(org.apache.flink.connector.file.src.reader.BulkFormat) SerializationSchema(org.apache.flink.api.common.serialization.SerializationSchema) EncodingFormat(org.apache.flink.table.connector.format.EncodingFormat) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier) ChangelogMode(org.apache.flink.table.connector.ChangelogMode) BucketAssigner(org.apache.flink.streaming.api.functions.sink.filesystem.BucketAssigner) BucketsBuilder(org.apache.flink.streaming.api.functions.sink.filesystem.StreamingFileSink.BucketsBuilder) LinkedHashMap(java.util.LinkedHashMap) ReadableConfig(org.apache.flink.configuration.ReadableConfig) FileSourceSplit(org.apache.flink.connector.file.src.FileSourceSplit) COMPACTION_FILE_SIZE(org.apache.flink.connector.file.table.FileSystemConnectorOptions.COMPACTION_FILE_SIZE) SINK_ROLLING_POLICY_INACTIVITY_INTERVAL(org.apache.flink.connector.file.table.FileSystemConnectorOptions.SINK_ROLLING_POLICY_INACTIVITY_INTERVAL) SupportsOverwrite(org.apache.flink.table.connector.sink.abilities.SupportsOverwrite) Nullable(javax.annotation.Nullable) StreamingSink(org.apache.flink.connector.file.table.stream.StreamingSink) DataStreamSink(org.apache.flink.streaming.api.datastream.DataStreamSink) OutputStream(java.io.OutputStream) RollingPolicy(org.apache.flink.streaming.api.functions.sink.filesystem.RollingPolicy) RowData(org.apache.flink.table.data.RowData) ProviderContext(org.apache.flink.table.connector.ProviderContext) BulkWriter(org.apache.flink.api.common.serialization.BulkWriter) Configuration(org.apache.flink.configuration.Configuration) TableException(org.apache.flink.table.api.TableException) DataTypes(org.apache.flink.table.api.DataTypes) IOException(java.io.IOException) DeserializationSchema(org.apache.flink.api.common.serialization.DeserializationSchema) DataStream(org.apache.flink.streaming.api.datastream.DataStream) Encoder(org.apache.flink.api.common.serialization.Encoder) SimpleVersionedStringSerializer(org.apache.flink.streaming.api.functions.sink.filesystem.bucketassigners.SimpleVersionedStringSerializer) RowKind(org.apache.flink.types.RowKind) CompactReader(org.apache.flink.connector.file.table.stream.compact.CompactReader) OutputFileConfig(org.apache.flink.streaming.api.functions.sink.filesystem.OutputFileConfig) Internal(org.apache.flink.annotation.Internal) Collections(java.util.Collections) SINK_ROLLING_POLICY_FILE_SIZE(org.apache.flink.connector.file.table.FileSystemConnectorOptions.SINK_ROLLING_POLICY_FILE_SIZE) RowData(org.apache.flink.table.data.RowData) FileSourceSplit(org.apache.flink.connector.file.src.FileSourceSplit) DataType(org.apache.flink.table.types.DataType) DeserializationSchema(org.apache.flink.api.common.serialization.DeserializationSchema) BulkFormat(org.apache.flink.connector.file.src.reader.BulkFormat)

Example 17 with DeserializationSchema

use of org.apache.flink.api.common.serialization.DeserializationSchema in project flink by apache.

the class TestDynamicTableFactory method createDynamicTableSource.

@Override
public DynamicTableSource createDynamicTableSource(Context context) {
    final TableFactoryHelper helper = FactoryUtil.createTableFactoryHelper(this, context);
    final Optional<DecodingFormat<DeserializationSchema<RowData>>> keyFormat = helper.discoverOptionalDecodingFormat(DeserializationFormatFactory.class, KEY_FORMAT);
    final DecodingFormat<DeserializationSchema<RowData>> valueFormat = helper.discoverOptionalDecodingFormat(DeserializationFormatFactory.class, FORMAT).orElseGet(() -> helper.discoverDecodingFormat(DeserializationFormatFactory.class, VALUE_FORMAT));
    helper.validate();
    return new DynamicTableSourceMock(helper.getOptions().get(TARGET), helper.getOptions().getOptional(PASSWORD).orElse(null), keyFormat.orElse(null), valueFormat);
}
Also used : RowData(org.apache.flink.table.data.RowData) DecodingFormat(org.apache.flink.table.connector.format.DecodingFormat) TableFactoryHelper(org.apache.flink.table.factories.FactoryUtil.TableFactoryHelper) DeserializationSchema(org.apache.flink.api.common.serialization.DeserializationSchema)

Aggregations

DeserializationSchema (org.apache.flink.api.common.serialization.DeserializationSchema)17 RowData (org.apache.flink.table.data.RowData)9 DataType (org.apache.flink.table.types.DataType)9 DecodingFormat (org.apache.flink.table.connector.format.DecodingFormat)7 DynamicTableSource (org.apache.flink.table.connector.source.DynamicTableSource)7 Collections (java.util.Collections)6 List (java.util.List)6 Map (java.util.Map)6 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)6 LinkedHashMap (java.util.LinkedHashMap)5 Properties (java.util.Properties)5 Collectors (java.util.stream.Collectors)5 Stream (java.util.stream.Stream)5 ReadableConfig (org.apache.flink.configuration.ReadableConfig)5 DataTypes (org.apache.flink.table.api.DataTypes)5 ChangelogMode (org.apache.flink.table.connector.ChangelogMode)5 RowKind (org.apache.flink.types.RowKind)5 FactoryUtil (org.apache.flink.table.factories.FactoryUtil)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3