Search in sources :

Example 1 with DataTypes

use of org.apache.flink.table.api.DataTypes in project flink by apache.

the class ValueDataTypeConverter method extractElementTypeFromValues.

private static Optional<DataType> extractElementTypeFromValues(Object[] array) {
    DataType elementType = null;
    for (Object element : array) {
        // null values are wildcard array elements
        if (element == null) {
            continue;
        }
        final Optional<DataType> possibleElementType = extractDataType(element);
        if (!possibleElementType.isPresent()) {
            return Optional.empty();
        }
        // for simplification, we assume that array elements can always be nullable
        // otherwise mismatches could occur when dealing with nested arrays
        final DataType extractedElementType = possibleElementType.get().nullable();
        // modification (i.e. adding spaces) which is not intended.
        if (elementType != null && !extractedElementType.equals(elementType)) {
            return Optional.empty();
        }
        elementType = extractedElementType;
    }
    return Optional.ofNullable(elementType).map(DataTypes::ARRAY);
}
Also used : DataType(org.apache.flink.table.types.DataType) AtomicDataType(org.apache.flink.table.types.AtomicDataType) DataTypes(org.apache.flink.table.api.DataTypes)

Example 2 with DataTypes

use of org.apache.flink.table.api.DataTypes 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)

Aggregations

IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Nullable (javax.annotation.Nullable)1 Internal (org.apache.flink.annotation.Internal)1 OutputFormat (org.apache.flink.api.common.io.OutputFormat)1 BulkWriter (org.apache.flink.api.common.serialization.BulkWriter)1 DeserializationSchema (org.apache.flink.api.common.serialization.DeserializationSchema)1 Encoder (org.apache.flink.api.common.serialization.Encoder)1 SerializationSchema (org.apache.flink.api.common.serialization.SerializationSchema)1 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)1 Configuration (org.apache.flink.configuration.Configuration)1