Search in sources :

Example 1 with Context

use of org.apache.flink.table.factories.DynamicTableFactory.Context in project flink by apache.

the class RawFormatFactory method createEncodingFormat.

@Override
public EncodingFormat<SerializationSchema<RowData>> createEncodingFormat(Context context, ReadableConfig formatOptions) {
    FactoryUtil.validateFactoryOptions(this, formatOptions);
    final String charsetName = validateAndGetCharsetName(formatOptions);
    final boolean isBigEndian = isBigEndian(formatOptions);
    return new EncodingFormat<SerializationSchema<RowData>>() {

        @Override
        public SerializationSchema<RowData> createRuntimeEncoder(DynamicTableSink.Context context, DataType consumedDataType) {
            final RowType physicalRowType = (RowType) consumedDataType.getLogicalType();
            final LogicalType fieldType = validateAndExtractSingleField(physicalRowType);
            return new RawFormatSerializationSchema(fieldType, charsetName, isBigEndian);
        }

        @Override
        public ChangelogMode getChangelogMode() {
            return ChangelogMode.insertOnly();
        }
    };
}
Also used : EncodingFormat(org.apache.flink.table.connector.format.EncodingFormat) Context(org.apache.flink.table.factories.DynamicTableFactory.Context) RowData(org.apache.flink.table.data.RowData) DataType(org.apache.flink.table.types.DataType) RowType(org.apache.flink.table.types.logical.RowType) LogicalType(org.apache.flink.table.types.logical.LogicalType)

Example 2 with Context

use of org.apache.flink.table.factories.DynamicTableFactory.Context in project flink by apache.

the class RawFormatFactory method createDecodingFormat.

@Override
public DecodingFormat<DeserializationSchema<RowData>> createDecodingFormat(Context context, ReadableConfig formatOptions) {
    FactoryUtil.validateFactoryOptions(this, formatOptions);
    final String charsetName = validateAndGetCharsetName(formatOptions);
    final boolean isBigEndian = isBigEndian(formatOptions);
    return new DecodingFormat<DeserializationSchema<RowData>>() {

        @Override
        public DeserializationSchema<RowData> createRuntimeDecoder(DynamicTableSource.Context context, DataType producedDataType) {
            final RowType physicalRowType = (RowType) producedDataType.getLogicalType();
            final LogicalType fieldType = validateAndExtractSingleField(physicalRowType);
            final TypeInformation<RowData> producedTypeInfo = context.createTypeInformation(producedDataType);
            return new RawFormatDeserializationSchema(fieldType, producedTypeInfo, charsetName, isBigEndian);
        }

        @Override
        public ChangelogMode getChangelogMode() {
            return ChangelogMode.insertOnly();
        }
    };
}
Also used : Context(org.apache.flink.table.factories.DynamicTableFactory.Context) RowData(org.apache.flink.table.data.RowData) DecodingFormat(org.apache.flink.table.connector.format.DecodingFormat) DataType(org.apache.flink.table.types.DataType) RowType(org.apache.flink.table.types.logical.RowType) LogicalType(org.apache.flink.table.types.logical.LogicalType)

Aggregations

RowData (org.apache.flink.table.data.RowData)2 Context (org.apache.flink.table.factories.DynamicTableFactory.Context)2 DataType (org.apache.flink.table.types.DataType)2 LogicalType (org.apache.flink.table.types.logical.LogicalType)2 RowType (org.apache.flink.table.types.logical.RowType)2 DecodingFormat (org.apache.flink.table.connector.format.DecodingFormat)1 EncodingFormat (org.apache.flink.table.connector.format.EncodingFormat)1