Search in sources :

Example 21 with DynamicTableSink

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

the class KafkaDynamicTableFactoryTest method testTableSinkWithKeyValue.

@Test
public void testTableSinkWithKeyValue() {
    final Map<String, String> modifiedOptions = getModifiedOptions(getKeyValueOptions(), options -> {
        options.put("sink.delivery-guarantee", "exactly-once");
        options.put("sink.transactional-id-prefix", "kafka-sink");
    });
    final DynamicTableSink actualSink = createTableSink(SCHEMA, modifiedOptions);
    final KafkaDynamicSink actualKafkaSink = (KafkaDynamicSink) actualSink;
    // initialize stateful testing formats
    actualKafkaSink.getSinkRuntimeProvider(new SinkRuntimeProviderContext(false));
    final EncodingFormatMock keyEncodingFormat = new EncodingFormatMock("#");
    keyEncodingFormat.consumedDataType = DataTypes.ROW(DataTypes.FIELD(NAME, DataTypes.STRING().notNull())).notNull();
    final EncodingFormatMock valueEncodingFormat = new EncodingFormatMock("|");
    valueEncodingFormat.consumedDataType = DataTypes.ROW(DataTypes.FIELD(COUNT, DataTypes.DECIMAL(38, 18)), DataTypes.FIELD(TIME, DataTypes.TIMESTAMP(3))).notNull();
    final DynamicTableSink expectedSink = createExpectedSink(SCHEMA_DATA_TYPE, keyEncodingFormat, valueEncodingFormat, new int[] { 0 }, new int[] { 1, 2 }, null, TOPIC, KAFKA_FINAL_SINK_PROPERTIES, new FlinkFixedPartitioner<>(), DeliveryGuarantee.EXACTLY_ONCE, null, "kafka-sink");
    assertThat(actualSink).isEqualTo(expectedSink);
}
Also used : SinkRuntimeProviderContext(org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext) EncodingFormatMock(org.apache.flink.table.factories.TestFormatFactory.EncodingFormatMock) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with DynamicTableSink

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

the class KafkaDynamicTableFactoryTest method testTableSinkSemanticTranslation.

@Test
public void testTableSinkSemanticTranslation() {
    final List<String> semantics = ImmutableList.of("exactly-once", "at-least-once", "none");
    final EncodingFormat<SerializationSchema<RowData>> valueEncodingFormat = new EncodingFormatMock(",");
    for (final String semantic : semantics) {
        final Map<String, String> modifiedOptions = getModifiedOptions(getBasicSinkOptions(), options -> {
            options.put("sink.semantic", semantic);
            options.put("sink.transactional-id-prefix", "kafka-sink");
        });
        final DynamicTableSink actualSink = createTableSink(SCHEMA, modifiedOptions);
        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.valueOf(semantic.toUpperCase().replace("-", "_")), null, "kafka-sink");
        assertThat(actualSink).isEqualTo(expectedSink);
    }
}
Also used : 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) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with DynamicTableSink

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

the class JsonFormatFactoryTest method createTableSink.

private TestDynamicTableFactory.DynamicTableSinkMock createTableSink(Map<String, String> options) {
    final DynamicTableSink actualSink = FactoryMocks.createTableSink(SCHEMA, options);
    assertThat(actualSink).isInstanceOf(TestDynamicTableFactory.DynamicTableSinkMock.class);
    return (TestDynamicTableFactory.DynamicTableSinkMock) actualSink;
}
Also used : DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) TestDynamicTableFactory(org.apache.flink.table.factories.TestDynamicTableFactory)

Example 24 with DynamicTableSink

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

the class FactoryUtilTest method testAllOptions.

@Test
public void testAllOptions() {
    final Map<String, String> options = createAllOptions();
    final DynamicTableSource actualSource = createTableSource(SCHEMA, options);
    final DynamicTableSource expectedSource = new DynamicTableSourceMock("MyTarget", null, new DecodingFormatMock(",", false), new DecodingFormatMock("|", true));
    assertThat(actualSource).isEqualTo(expectedSource);
    final DynamicTableSink actualSink = createTableSink(SCHEMA, options);
    final DynamicTableSink expectedSink = new DynamicTableSinkMock("MyTarget", 1000L, new EncodingFormatMock(","), new EncodingFormatMock("|"));
    assertThat(actualSink).isEqualTo(expectedSink);
}
Also used : EncodingFormatMock(org.apache.flink.table.factories.TestFormatFactory.EncodingFormatMock) DecodingFormatMock(org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) DynamicTableSourceMock(org.apache.flink.table.factories.TestDynamicTableFactory.DynamicTableSourceMock) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) DynamicTableSinkMock(org.apache.flink.table.factories.TestDynamicTableFactory.DynamicTableSinkMock) Test(org.junit.jupiter.api.Test)

Example 25 with DynamicTableSink

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

the class RawFormatFactoryTest method createSerializationSchema.

private static SerializationSchema<RowData> createSerializationSchema(ResolvedSchema schema, Map<String, String> options) {
    final DynamicTableSink actualSink = createTableSink(schema, options);
    assertThat(actualSink, instanceOf(TestDynamicTableFactory.DynamicTableSinkMock.class));
    TestDynamicTableFactory.DynamicTableSinkMock sinkMock = (TestDynamicTableFactory.DynamicTableSinkMock) actualSink;
    return sinkMock.valueFormat.createRuntimeEncoder(new SinkRuntimeProviderContext(false), schema.toPhysicalRowDataType());
}
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)

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