Search in sources :

Example 21 with SinkRuntimeProviderContext

use of org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext in project flink by apache.

the class DebeziumJsonFormatFactoryTest method testSchemaIncludeOption.

@Test
public void testSchemaIncludeOption() {
    Map<String, String> options = getAllOptions();
    options.put("debezium-json.schema-include", "true");
    final DebeziumJsonDeserializationSchema expectedDeser = new DebeziumJsonDeserializationSchema(PHYSICAL_DATA_TYPE, Collections.emptyList(), InternalTypeInfo.of(PHYSICAL_DATA_TYPE.getLogicalType()), true, true, TimestampFormat.ISO_8601);
    final DynamicTableSource actualSource = createTableSource(SCHEMA, options);
    TestDynamicTableFactory.DynamicTableSourceMock scanSourceMock = (TestDynamicTableFactory.DynamicTableSourceMock) actualSource;
    DeserializationSchema<RowData> actualDeser = scanSourceMock.valueFormat.createRuntimeDecoder(ScanRuntimeProviderContext.INSTANCE, PHYSICAL_DATA_TYPE);
    assertEquals(expectedDeser, actualDeser);
    try {
        final DynamicTableSink actualSink = createTableSink(SCHEMA, options);
        TestDynamicTableFactory.DynamicTableSinkMock sinkMock = (TestDynamicTableFactory.DynamicTableSinkMock) actualSink;
        // should fail
        sinkMock.valueFormat.createRuntimeEncoder(new SinkRuntimeProviderContext(false), PHYSICAL_DATA_TYPE);
        fail();
    } catch (Exception e) {
        assertEquals(e.getCause().getCause().getMessage(), "Debezium JSON serialization doesn't support " + "'debezium-json.schema-include' option been set to true.");
    }
}
Also used : SinkRuntimeProviderContext(org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) TestDynamicTableFactory(org.apache.flink.table.factories.TestDynamicTableFactory) ExpectedException(org.junit.rules.ExpectedException) ValidationException(org.apache.flink.table.api.ValidationException) RowData(org.apache.flink.table.data.RowData) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) Test(org.junit.Test)

Example 22 with SinkRuntimeProviderContext

use of org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext in project flink by apache.

the class CanalJsonFormatFactoryTest method createSerializationSchema.

private static SerializationSchema<RowData> createSerializationSchema(Map<String, String> options) {
    DynamicTableSink sink = createTableSink(SCHEMA, options);
    assert sink instanceof TestDynamicTableFactory.DynamicTableSinkMock;
    TestDynamicTableFactory.DynamicTableSinkMock sinkMock = (TestDynamicTableFactory.DynamicTableSinkMock) sink;
    return sinkMock.valueFormat.createRuntimeEncoder(new SinkRuntimeProviderContext(false), PHYSICAL_DATA_TYPE);
}
Also used : SinkRuntimeProviderContext(org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) TestDynamicTableFactory(org.apache.flink.table.factories.TestDynamicTableFactory)

Example 23 with SinkRuntimeProviderContext

use of org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext in project flink by apache.

the class MaxwellJsonFormatFactoryTest method testSeDeSchema.

@Test
public void testSeDeSchema() {
    final MaxwellJsonDeserializationSchema expectedDeser = new MaxwellJsonDeserializationSchema(PHYSICAL_DATA_TYPE, Collections.emptyList(), ROW_TYPE_INFO, true, TimestampFormat.ISO_8601);
    final MaxwellJsonSerializationSchema expectedSer = new MaxwellJsonSerializationSchema(PHYSICAL_TYPE, TimestampFormat.ISO_8601, JsonFormatOptions.MapNullKeyMode.LITERAL, "null", true);
    final Map<String, String> options = getAllOptions();
    final DynamicTableSource actualSource = createTableSource(SCHEMA, options);
    assert actualSource instanceof TestDynamicTableFactory.DynamicTableSourceMock;
    TestDynamicTableFactory.DynamicTableSourceMock scanSourceMock = (TestDynamicTableFactory.DynamicTableSourceMock) actualSource;
    DeserializationSchema<RowData> actualDeser = scanSourceMock.valueFormat.createRuntimeDecoder(ScanRuntimeProviderContext.INSTANCE, SCHEMA.toPhysicalRowDataType());
    assertEquals(expectedDeser, actualDeser);
    final DynamicTableSink actualSink = createTableSink(SCHEMA, options);
    assert actualSink instanceof TestDynamicTableFactory.DynamicTableSinkMock;
    TestDynamicTableFactory.DynamicTableSinkMock sinkMock = (TestDynamicTableFactory.DynamicTableSinkMock) actualSink;
    SerializationSchema<RowData> actualSer = sinkMock.valueFormat.createRuntimeEncoder(new SinkRuntimeProviderContext(false), SCHEMA.toPhysicalRowDataType());
    assertEquals(expectedSer, actualSer);
}
Also used : SinkRuntimeProviderContext(org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) TestDynamicTableFactory(org.apache.flink.table.factories.TestDynamicTableFactory) RowData(org.apache.flink.table.data.RowData) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) Test(org.junit.Test)

Example 24 with SinkRuntimeProviderContext

use of org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext in project flink by apache.

the class OggJsonFormatFactoryTest method testSeDeSchema.

@Test
public void testSeDeSchema() {
    final Map<String, String> options = getAllOptions();
    final OggJsonSerializationSchema expectedSer = new OggJsonSerializationSchema((RowType) PHYSICAL_DATA_TYPE.getLogicalType(), TimestampFormat.ISO_8601, JsonFormatOptions.MapNullKeyMode.LITERAL, "null", true);
    final DynamicTableSink actualSink = createTableSink(SCHEMA, options);
    assert actualSink instanceof TestDynamicTableFactory.DynamicTableSinkMock;
    TestDynamicTableFactory.DynamicTableSinkMock sinkMock = (TestDynamicTableFactory.DynamicTableSinkMock) actualSink;
    SerializationSchema<RowData> actualSer = sinkMock.valueFormat.createRuntimeEncoder(new SinkRuntimeProviderContext(false), PHYSICAL_DATA_TYPE);
    assertEquals(expectedSer, actualSer);
}
Also used : SinkRuntimeProviderContext(org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext) RowData(org.apache.flink.table.data.RowData) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) TestDynamicTableFactory(org.apache.flink.table.factories.TestDynamicTableFactory) Test(org.junit.Test)

Example 25 with SinkRuntimeProviderContext

use of org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext in project flink by apache.

the class OracleTableSinkITCase method testFlushBufferWhenCheckpoint.

@Test
public void testFlushBufferWhenCheckpoint() throws Exception {
    Map<String, String> options = new HashMap<>();
    options.put("connector", "jdbc");
    options.put("url", containerUrl);
    options.put("table-name", OUTPUT_TABLE5);
    options.put("sink.buffer-flush.interval", "0");
    ResolvedSchema schema = ResolvedSchema.of(Column.physical("id", DataTypes.BIGINT().notNull()));
    DynamicTableSink tableSink = createTableSink(schema, options);
    SinkRuntimeProviderContext context = new SinkRuntimeProviderContext(false);
    SinkFunctionProvider sinkProvider = (SinkFunctionProvider) tableSink.getSinkRuntimeProvider(context);
    GenericJdbcSinkFunction<RowData> sinkFunction = (GenericJdbcSinkFunction<RowData>) sinkProvider.createSinkFunction();
    sinkFunction.setRuntimeContext(new MockStreamingRuntimeContext(true, 1, 0));
    sinkFunction.open(new Configuration());
    sinkFunction.invoke(GenericRowData.of(1L), SinkContextUtil.forTimestamp(1));
    sinkFunction.invoke(GenericRowData.of(2L), SinkContextUtil.forTimestamp(1));
    check(new Row[] {}, containerUrl, OUTPUT_TABLE5, new String[] { "id" });
    sinkFunction.snapshotState(new StateSnapshotContextSynchronousImpl(1, 1));
    check(new Row[] { Row.of(1L), Row.of(2L) }, containerUrl, OUTPUT_TABLE5, new String[] { "id" });
    sinkFunction.close();
}
Also used : SinkRuntimeProviderContext(org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext) MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) Configuration(org.apache.flink.configuration.Configuration) HashMap(java.util.HashMap) StateSnapshotContextSynchronousImpl(org.apache.flink.runtime.state.StateSnapshotContextSynchronousImpl) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) SinkFunctionProvider(org.apache.flink.table.connector.sink.SinkFunctionProvider) GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) GenericJdbcSinkFunction(org.apache.flink.connector.jdbc.internal.GenericJdbcSinkFunction) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) Test(org.junit.Test)

Aggregations

SinkRuntimeProviderContext (org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext)27 DynamicTableSink (org.apache.flink.table.connector.sink.DynamicTableSink)23 RowData (org.apache.flink.table.data.RowData)19 Test (org.junit.Test)17 ResolvedSchema (org.apache.flink.table.catalog.ResolvedSchema)12 SinkV2Provider (org.apache.flink.table.connector.sink.SinkV2Provider)11 TestDynamicTableFactory (org.apache.flink.table.factories.TestDynamicTableFactory)7 HashMap (java.util.HashMap)5 RowType (org.apache.flink.table.types.logical.RowType)5 SinkFunctionProvider (org.apache.flink.table.connector.sink.SinkFunctionProvider)4 SerializationSchema (org.apache.flink.api.common.serialization.SerializationSchema)3 AvroRowDataSerializationSchema (org.apache.flink.formats.avro.AvroRowDataSerializationSchema)3 ConfluentRegistryAvroSerializationSchema (org.apache.flink.formats.avro.registry.confluent.ConfluentRegistryAvroSerializationSchema)3 DynamicTableSource (org.apache.flink.table.connector.source.DynamicTableSource)3 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)3 EncodingFormatMock (org.apache.flink.table.factories.TestFormatFactory.EncodingFormatMock)3 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Transformation (org.apache.flink.api.dag.Transformation)2 Configuration (org.apache.flink.configuration.Configuration)2