Search in sources :

Example 11 with DynamicTableSink

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

the class HBaseDynamicTableFactoryTest method testBufferFlushOptions.

@Test
public void testBufferFlushOptions() {
    Map<String, String> options = getAllOptions();
    options.put("sink.buffer-flush.max-size", "10mb");
    options.put("sink.buffer-flush.max-rows", "100");
    options.put("sink.buffer-flush.interval", "10s");
    ResolvedSchema schema = ResolvedSchema.of(Column.physical(ROWKEY, STRING()));
    DynamicTableSink sink = createTableSink(schema, options);
    HBaseWriteOptions expected = HBaseWriteOptions.builder().setBufferFlushMaxRows(100).setBufferFlushIntervalMillis(10 * 1000).setBufferFlushMaxSizeInBytes(10 * 1024 * 1024).build();
    HBaseWriteOptions actual = ((HBaseDynamicTableSink) sink).getWriteOptions();
    assertEquals(expected, actual);
}
Also used : HBaseDynamicTableSink(org.apache.flink.connector.hbase1.sink.HBaseDynamicTableSink) HBaseDynamicTableSink(org.apache.flink.connector.hbase1.sink.HBaseDynamicTableSink) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) HBaseWriteOptions(org.apache.flink.connector.hbase.options.HBaseWriteOptions) Test(org.junit.Test)

Example 12 with DynamicTableSink

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

the class DebeziumAvroFormatFactoryTest method createSerializationSchema.

private static SerializationSchema<RowData> createSerializationSchema(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)

Example 13 with DynamicTableSink

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

the class ElasticsearchDynamicSinkFactoryBaseTest method testSinkParallelism.

@Test
public void testSinkParallelism() {
    ElasticsearchDynamicSinkFactoryBase sinkFactory = createSinkFactory();
    DynamicTableSink sink = sinkFactory.createDynamicTableSink(createPrefilledTestContext().withOption(SINK_PARALLELISM.key(), "2").build());
    assertThat(sink).isInstanceOf(ElasticsearchDynamicSink.class);
    ElasticsearchDynamicSink esSink = (ElasticsearchDynamicSink) sink;
    SinkV2Provider provider = (SinkV2Provider) esSink.getSinkRuntimeProvider(new ElasticsearchUtil.MockContext());
    assertThat(2).isEqualTo(provider.getParallelism().get());
}
Also used : SinkV2Provider(org.apache.flink.table.connector.sink.SinkV2Provider) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) Test(org.junit.jupiter.api.Test)

Example 14 with DynamicTableSink

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

the class HiveTableFactoryTest method testHiveTable.

@Test
public void testHiveTable() throws Exception {
    final ResolvedSchema schema = ResolvedSchema.of(Column.physical("name", DataTypes.STRING()), Column.physical("age", DataTypes.INT()));
    catalog.createDatabase("mydb", new CatalogDatabaseImpl(new HashMap<>(), ""), true);
    final Map<String, String> options = Collections.singletonMap(FactoryUtil.CONNECTOR.key(), SqlCreateHiveTable.IDENTIFIER);
    final CatalogTable table = new CatalogTableImpl(TableSchema.fromResolvedSchema(schema), options, "hive table");
    catalog.createTable(new ObjectPath("mydb", "mytable"), table, true);
    final DynamicTableSource tableSource = FactoryUtil.createDynamicTableSource((DynamicTableSourceFactory) catalog.getFactory().orElseThrow(IllegalStateException::new), ObjectIdentifier.of("mycatalog", "mydb", "mytable"), new ResolvedCatalogTable(table, schema), new Configuration(), Thread.currentThread().getContextClassLoader(), false);
    assertTrue(tableSource instanceof HiveTableSource);
    final DynamicTableSink tableSink = FactoryUtil.createDynamicTableSink((DynamicTableSinkFactory) catalog.getFactory().orElseThrow(IllegalStateException::new), ObjectIdentifier.of("mycatalog", "mydb", "mytable"), new ResolvedCatalogTable(table, schema), new Configuration(), Thread.currentThread().getContextClassLoader(), false);
    assertTrue(tableSink instanceof HiveTableSink);
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) Configuration(org.apache.flink.configuration.Configuration) HashMap(java.util.HashMap) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) CatalogTable(org.apache.flink.table.catalog.CatalogTable) ResolvedCatalogTable(org.apache.flink.table.catalog.ResolvedCatalogTable) CatalogDatabaseImpl(org.apache.flink.table.catalog.CatalogDatabaseImpl) ResolvedCatalogTable(org.apache.flink.table.catalog.ResolvedCatalogTable) CatalogTableImpl(org.apache.flink.table.catalog.CatalogTableImpl) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) Test(org.junit.Test)

Example 15 with DynamicTableSink

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

the class JdbcDynamicTableFactoryTest method testJdbcCommonProperties.

@Test
public void testJdbcCommonProperties() {
    Map<String, String> properties = getAllOptions();
    properties.put("driver", "org.apache.derby.jdbc.EmbeddedDriver");
    properties.put("username", "user");
    properties.put("password", "pass");
    properties.put("connection.max-retry-timeout", "120s");
    // validation for source
    DynamicTableSource actualSource = createTableSource(SCHEMA, properties);
    JdbcConnectorOptions options = JdbcConnectorOptions.builder().setDBUrl("jdbc:derby:memory:mydb").setTableName("mytable").setDriverName("org.apache.derby.jdbc.EmbeddedDriver").setUsername("user").setPassword("pass").setConnectionCheckTimeoutSeconds(120).build();
    JdbcLookupOptions lookupOptions = JdbcLookupOptions.builder().setCacheMaxSize(-1).setCacheExpireMs(10_000).setMaxRetryTimes(3).build();
    JdbcDynamicTableSource expectedSource = new JdbcDynamicTableSource(options, JdbcReadOptions.builder().build(), lookupOptions, SCHEMA.toPhysicalRowDataType());
    assertEquals(expectedSource, actualSource);
    // validation for sink
    DynamicTableSink actualSink = createTableSink(SCHEMA, properties);
    // default flush configurations
    JdbcExecutionOptions executionOptions = JdbcExecutionOptions.builder().withBatchSize(100).withBatchIntervalMs(1000).withMaxRetries(3).build();
    JdbcDmlOptions dmlOptions = JdbcDmlOptions.builder().withTableName(options.getTableName()).withDialect(options.getDialect()).withFieldNames(SCHEMA.getColumnNames().toArray(new String[0])).withKeyFields("bbb", "aaa").build();
    JdbcDynamicTableSink expectedSink = new JdbcDynamicTableSink(options, executionOptions, dmlOptions, SCHEMA.toPhysicalRowDataType());
    assertEquals(expectedSink, actualSink);
}
Also used : JdbcExecutionOptions(org.apache.flink.connector.jdbc.JdbcExecutionOptions) JdbcLookupOptions(org.apache.flink.connector.jdbc.internal.options.JdbcLookupOptions) JdbcConnectorOptions(org.apache.flink.connector.jdbc.internal.options.JdbcConnectorOptions) JdbcDmlOptions(org.apache.flink.connector.jdbc.internal.options.JdbcDmlOptions) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) 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