Interface DecodingFormat<I>
-
- Type Parameters:
I- runtime interface needed by the table source
- All Superinterfaces:
Format
- All Known Subinterfaces:
ProjectableDecodingFormat<I>
@PublicEvolving public interface DecodingFormat<I> extends Format
AFormatfor aDynamicTableSourcefor reading rows.Implementing a
DecodingFormatcreateRuntimeDecoder(DynamicTableSource.Context, DataType)takes aphysicalDataType. ThisDataTypehas usually been derived from a table'sResolvedSchemaand excludes partition, metadata, and other auxiliary columns. ThephysicalDataTypeshould describe exactly the full serialized record. In other words: for every field in the serialized record there is a corresponding field at the same position in thephysicalDataType. Some implementations may decide to be more lenient and allow users to omit fields but this depends on the format characteristics. For example, a CSV format implementation might allow the user to define the schema only for the first 5 of the 10 total columns available in each row.If the format supports projections, that is it can exclude certain fields from being parsed independently of the fields defined in the schema and can reorder fields in the produced
RowData, then it should implementProjectableDecodingFormat.ProjectableDecodingFormat.createRuntimeDecoder(DynamicTableSource.Context, DataType, int[][])provides thephysicalDataTypeas described above and providesprojectionsto compute the type to produce usingProjection.of(projections).project(physicalDataType). For example, a JSON format implementation may match the fields based on the JSON object keys, hence it can easily produceRowDataexcluding unused object values and set values inside theRowDatausing the index provided by theprojectionsarray.Whenever possible, it's highly recommended implementing
ProjectableDecodingFormat, as it might help to reduce the data volume when users are reading large records but are using only a small subset of fields.Using a
DecodingFormatDynamicTableSourcethat doesn't implementSupportsProjectionPushDownshould invokecreateRuntimeDecoder(DynamicTableSource.Context, DataType). Usually,DynamicTableFactory.Context.getPhysicalRowDataType()can provide thephysicalDataType(stripped of any fields not available in the serialized record).DynamicTableSourceimplementingSupportsProjectionPushDownshould check whether theDecodingFormatis an instance ofProjectableDecodingFormat:- If yes, then the connector can invoke
ProjectableDecodingFormat.createRuntimeDecoder(DynamicTableSource.Context, DataType, int[][])providing a non nullprojectionsarray excluding auxiliary fields. The built runtime implementation will take care of projections, producing records of typeProjection.of(projections).project(physicalDataType). - If no, then the connector must take care of performing the projection, for example using
ProjectedRowDatato project physicalRowDataemitted from the decoder runtime implementation.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidapplyReadableMetadata(List<String> metadataKeys)Provides a list of metadata keys that the produced row must contain as appended metadata columns.IcreateRuntimeDecoder(DynamicTableSource.Context context, DataType physicalDataType)Creates runtime decoder implementation that is configured to produce data of the given data type.default Map<String,DataType>listReadableMetadata()Returns the map of metadata keys and their corresponding data types that can be produced by this format for reading.-
Methods inherited from interface org.apache.flink.table.connector.format.Format
getChangelogMode
-
-
-
-
Method Detail
-
createRuntimeDecoder
I createRuntimeDecoder(DynamicTableSource.Context context, DataType physicalDataType)
Creates runtime decoder implementation that is configured to produce data of the given data type.- Parameters:
context- the context provides several utilities required to instantiate the runtime decoder implementation of the formatphysicalDataType- For more details check the documentation ofDecodingFormat.
-
listReadableMetadata
default Map<String,DataType> listReadableMetadata()
Returns the map of metadata keys and their corresponding data types that can be produced by this format for reading. By default, this method returns an empty map.Metadata columns add additional columns to the table's schema. A decoding format is responsible to add requested metadata columns at the end of produced rows.
See
SupportsReadingMetadatafor more information.Note: This method is only used if the outer
DynamicTableSourceimplementsSupportsReadingMetadataand calls this method inSupportsReadingMetadata.listReadableMetadata().
-
applyReadableMetadata
default void applyReadableMetadata(List<String> metadataKeys)
Provides a list of metadata keys that the produced row must contain as appended metadata columns. By default, this method throws an exception if metadata keys are defined.See
SupportsReadingMetadatafor more information.Note: This method is only used if the outer
DynamicTableSourceimplementsSupportsReadingMetadataand calls this method inSupportsReadingMetadata.applyReadableMetadata(List, DataType).
-
-