Search in sources :

Example 26 with DynamicTableSink

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

the class KafkaDynamicTableFactoryTest method testTableSink.

@Test
public void testTableSink() {
    final Map<String, String> modifiedOptions = getModifiedOptions(getBasicSinkOptions(), options -> {
        options.put("sink.delivery-guarantee", "exactly-once");
        options.put("sink.transactional-id-prefix", "kafka-sink");
    });
    final DynamicTableSink actualSink = createTableSink(SCHEMA, modifiedOptions);
    final EncodingFormat<SerializationSchema<RowData>> valueEncodingFormat = new EncodingFormatMock(",");
    final DynamicTableSink expectedSink = createExpectedSink(SCHEMA_DATA_TYPE, null, valueEncodingFormat, new int[0], new int[] { 0, 1, 2 }, null, TOPIC, KAFKA_SINK_PROPERTIES, new FlinkFixedPartitioner<>(), DeliveryGuarantee.EXACTLY_ONCE, null, "kafka-sink");
    assertThat(actualSink).isEqualTo(expectedSink);
    // Test kafka producer.
    final KafkaDynamicSink actualKafkaSink = (KafkaDynamicSink) actualSink;
    DynamicTableSink.SinkRuntimeProvider provider = actualKafkaSink.getSinkRuntimeProvider(new SinkRuntimeProviderContext(false));
    assertThat(provider).isInstanceOf(SinkV2Provider.class);
    final SinkV2Provider sinkProvider = (SinkV2Provider) provider;
    final Sink<RowData> sinkFunction = sinkProvider.createSink();
    assertThat(sinkFunction).isInstanceOf(KafkaSink.class);
}
Also used : SinkRuntimeProviderContext(org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext) EncodingFormatMock(org.apache.flink.table.factories.TestFormatFactory.EncodingFormatMock) ConfluentRegistryAvroSerializationSchema(org.apache.flink.formats.avro.registry.confluent.ConfluentRegistryAvroSerializationSchema) AvroRowDataSerializationSchema(org.apache.flink.formats.avro.AvroRowDataSerializationSchema) SerializationSchema(org.apache.flink.api.common.serialization.SerializationSchema) DebeziumAvroSerializationSchema(org.apache.flink.formats.avro.registry.confluent.debezium.DebeziumAvroSerializationSchema) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) RowData(org.apache.flink.table.data.RowData) SinkV2Provider(org.apache.flink.table.connector.sink.SinkV2Provider) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with DynamicTableSink

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

the class UpsertKafkaDynamicTableFactoryTest method testTableSink.

@Test
public void testTableSink() {
    // Construct table sink using options and table sink factory.
    final DynamicTableSink actualSink = createTableSink(SINK_SCHEMA, getFullSinkOptions());
    final DynamicTableSink expectedSink = createExpectedSink(SINK_SCHEMA.toPhysicalRowDataType(), keyEncodingFormat, valueEncodingFormat, SINK_KEY_FIELDS, SINK_VALUE_FIELDS, null, SINK_TOPIC, UPSERT_KAFKA_SINK_PROPERTIES, DeliveryGuarantee.AT_LEAST_ONCE, SinkBufferFlushMode.DISABLED, null);
    // Test sink format.
    final KafkaDynamicSink actualUpsertKafkaSink = (KafkaDynamicSink) actualSink;
    assertEquals(expectedSink, actualSink);
    // Test kafka producer.
    DynamicTableSink.SinkRuntimeProvider provider = actualUpsertKafkaSink.getSinkRuntimeProvider(new SinkRuntimeProviderContext(false));
    assertThat(provider, instanceOf(SinkV2Provider.class));
    final SinkV2Provider sinkFunctionProvider = (SinkV2Provider) provider;
    final Sink<RowData> sink = sinkFunctionProvider.createSink();
    assertThat(sink, instanceOf(KafkaSink.class));
}
Also used : SinkRuntimeProviderContext(org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext) RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) KafkaSink(org.apache.flink.connector.kafka.sink.KafkaSink) SinkV2Provider(org.apache.flink.table.connector.sink.SinkV2Provider) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) Test(org.junit.Test)

Example 28 with DynamicTableSink

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

the class AvroFormatFactoryTest method testSeDeSchema.

@Test
public void testSeDeSchema() {
    final AvroRowDataDeserializationSchema expectedDeser = new AvroRowDataDeserializationSchema(ROW_TYPE, InternalTypeInfo.of(ROW_TYPE));
    final Map<String, String> options = getAllOptions();
    final DynamicTableSource actualSource = FactoryMocks.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 AvroRowDataSerializationSchema expectedSer = new AvroRowDataSerializationSchema(ROW_TYPE);
    final DynamicTableSink actualSink = FactoryMocks.createTableSink(SCHEMA, options);
    assert actualSink instanceof TestDynamicTableFactory.DynamicTableSinkMock;
    TestDynamicTableFactory.DynamicTableSinkMock sinkMock = (TestDynamicTableFactory.DynamicTableSinkMock) actualSink;
    SerializationSchema<RowData> actualSer = sinkMock.valueFormat.createRuntimeEncoder(null, SCHEMA.toPhysicalRowDataType());
    assertEquals(expectedSer, actualSer);
}
Also used : 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 29 with DynamicTableSink

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

the class RegistryAvroFormatFactoryTest method testSerializationSchemaWithOptionalProperties.

@Test
public void testSerializationSchemaWithOptionalProperties() {
    final AvroRowDataSerializationSchema expectedSer = new AvroRowDataSerializationSchema(ROW_TYPE, ConfluentRegistryAvroSerializationSchema.forGeneric(SUBJECT, AvroSchemaConverter.convertToSchema(ROW_TYPE), REGISTRY_URL, EXPECTED_OPTIONAL_PROPERTIES), RowDataToAvroConverters.createConverter(ROW_TYPE));
    final DynamicTableSink actualSink = createTableSink(SCHEMA, getOptionalProperties());
    assertThat(actualSink, instanceOf(TestDynamicTableFactory.DynamicTableSinkMock.class));
    TestDynamicTableFactory.DynamicTableSinkMock sinkMock = (TestDynamicTableFactory.DynamicTableSinkMock) actualSink;
    SerializationSchema<RowData> actualSer = sinkMock.valueFormat.createRuntimeEncoder(null, SCHEMA.toPhysicalRowDataType());
    assertEquals(expectedSer, actualSer);
}
Also used : AvroRowDataSerializationSchema(org.apache.flink.formats.avro.AvroRowDataSerializationSchema) 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 30 with DynamicTableSink

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

the class RegistryAvroFormatFactoryTest method testSerializationSchema.

@Test
public void testSerializationSchema() {
    final AvroRowDataSerializationSchema expectedSer = new AvroRowDataSerializationSchema(ROW_TYPE, ConfluentRegistryAvroSerializationSchema.forGeneric(SUBJECT, AvroSchemaConverter.convertToSchema(ROW_TYPE), REGISTRY_URL), RowDataToAvroConverters.createConverter(ROW_TYPE));
    final DynamicTableSink actualSink = createTableSink(SCHEMA, getDefaultOptions());
    assertThat(actualSink, instanceOf(TestDynamicTableFactory.DynamicTableSinkMock.class));
    TestDynamicTableFactory.DynamicTableSinkMock sinkMock = (TestDynamicTableFactory.DynamicTableSinkMock) actualSink;
    SerializationSchema<RowData> actualSer = sinkMock.valueFormat.createRuntimeEncoder(null, SCHEMA.toPhysicalRowDataType());
    assertEquals(expectedSer, actualSer);
}
Also used : AvroRowDataSerializationSchema(org.apache.flink.formats.avro.AvroRowDataSerializationSchema) 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)

Aggregations

DynamicTableSink (org.apache.flink.table.connector.sink.DynamicTableSink)54 Test (org.junit.Test)34 SinkRuntimeProviderContext (org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext)23 RowData (org.apache.flink.table.data.RowData)21 ResolvedSchema (org.apache.flink.table.catalog.ResolvedSchema)19 DynamicTableSource (org.apache.flink.table.connector.source.DynamicTableSource)14 SinkV2Provider (org.apache.flink.table.connector.sink.SinkV2Provider)12 TestDynamicTableFactory (org.apache.flink.table.factories.TestDynamicTableFactory)12 Test (org.junit.jupiter.api.Test)10 EncodingFormatMock (org.apache.flink.table.factories.TestFormatFactory.EncodingFormatMock)8 HashMap (java.util.HashMap)7 HBaseWriteOptions (org.apache.flink.connector.hbase.options.HBaseWriteOptions)6 AvroRowDataSerializationSchema (org.apache.flink.formats.avro.AvroRowDataSerializationSchema)6 SinkFunctionProvider (org.apache.flink.table.connector.sink.SinkFunctionProvider)5 Collections (java.util.Collections)4 HBaseDynamicTableSink (org.apache.flink.connector.hbase2.sink.HBaseDynamicTableSink)4 SupportsPartitioning (org.apache.flink.table.connector.sink.abilities.SupportsPartitioning)4 DataType (org.apache.flink.table.types.DataType)4 RowType (org.apache.flink.table.types.logical.RowType)4 ArrayList (java.util.ArrayList)3