Search in sources :

Example 6 with JdbcConnectorOptions

use of org.apache.flink.connector.jdbc.internal.options.JdbcConnectorOptions in project flink-connector-jdbc-ext by lixz3321.

the class JdbcTableSourceSinkFactoryTest method testJdbcLookupProperties.

@Test
public void testJdbcLookupProperties() {
    Map<String, String> properties = getBasicProperties();
    properties.put("connector.lookup.cache.max-rows", "1000");
    properties.put("connector.lookup.cache.ttl", "10s");
    properties.put("connector.lookup.max-retries", "10");
    final StreamTableSource<?> actual = TableFactoryService.find(StreamTableSourceFactory.class, properties).createStreamTableSource(properties);
    final JdbcConnectorOptions options = JdbcConnectorOptions.builder().setDBUrl("jdbc:derby:memory:mydb").setTableName("mytable").build();
    final JdbcLookupOptions lookupOptions = JdbcLookupOptions.builder().setCacheMaxSize(1000).setCacheExpireMs(10_000).setMaxRetryTimes(10).build();
    final JdbcTableSource expected = JdbcTableSource.builder().setOptions(options).setLookupOptions(lookupOptions).setSchema(schema).build();
    assertEquals(expected, actual);
}
Also used : JdbcLookupOptions(org.apache.flink.connector.jdbc.internal.options.JdbcLookupOptions) JdbcConnectorOptions(org.apache.flink.connector.jdbc.internal.options.JdbcConnectorOptions) StreamTableSourceFactory(org.apache.flink.table.factories.StreamTableSourceFactory) Test(org.junit.Test)

Example 7 with JdbcConnectorOptions

use of org.apache.flink.connector.jdbc.internal.options.JdbcConnectorOptions in project flink-connector-jdbc-ext by lixz3321.

the class JdbcDynamicTableFactoryTest method testJdbcSinkProperties.

@Test
public void testJdbcSinkProperties() {
    Map<String, String> properties = getAllOptions();
    properties.put("sink.buffer-flush.max-rows", "1000");
    properties.put("sink.buffer-flush.interval", "2min");
    properties.put("sink.max-retries", "5");
    DynamicTableSink actual = createTableSink(SCHEMA, properties);
    JdbcConnectorOptions options = JdbcConnectorOptions.builder().setDBUrl("jdbc:derby:memory:mydb").setTableName("mytable").build();
    JdbcExecutionOptions executionOptions = JdbcExecutionOptions.builder().withBatchSize(1000).withBatchIntervalMs(120_000).withMaxRetries(5).build();
    JdbcDmlOptions dmlOptions = JdbcDmlOptions.builder().withTableName(options.getTableName()).withDialect(options.getDialect()).withFieldNames(SCHEMA.getColumnNames().toArray(new String[0])).withKeyFields("bbb", "aaa").build();
    JdbcDynamicTableSink expected = new JdbcDynamicTableSink(options, executionOptions, dmlOptions, TableSchema.fromResolvedSchema(SCHEMA));
    assertEquals(expected, actual);
}
Also used : JdbcExecutionOptions(org.apache.flink.connector.jdbc.JdbcExecutionOptions) 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) Test(org.junit.Test)

Example 8 with JdbcConnectorOptions

use of org.apache.flink.connector.jdbc.internal.options.JdbcConnectorOptions in project flink-connector-jdbc-ext by lixz3321.

the class JdbcDynamicTableFactoryTest method testJdbcReadProperties.

@Test
public void testJdbcReadProperties() {
    Map<String, String> properties = getAllOptions();
    properties.put("scan.partition.column", "aaa");
    properties.put("scan.partition.lower-bound", "-10");
    properties.put("scan.partition.upper-bound", "100");
    properties.put("scan.partition.num", "10");
    properties.put("scan.fetch-size", "20");
    properties.put("scan.auto-commit", "false");
    DynamicTableSource actual = createTableSource(SCHEMA, properties);
    JdbcConnectorOptions options = JdbcConnectorOptions.builder().setDBUrl("jdbc:derby:memory:mydb").setTableName("mytable").build();
    JdbcReadOptions readOptions = JdbcReadOptions.builder().setPartitionColumnName("aaa").setPartitionLowerBound(-10).setPartitionUpperBound(100).setNumPartitions(10).setFetchSize(20).setAutoCommit(false).build();
    JdbcLookupOptions lookupOptions = JdbcLookupOptions.builder().setCacheMaxSize(-1).setCacheExpireMs(10_000).setMaxRetryTimes(3).build();
    JdbcDynamicTableSource expected = new JdbcDynamicTableSource(options, readOptions, lookupOptions, TableSchema.fromResolvedSchema(SCHEMA));
    assertEquals(expected, actual);
}
Also used : JdbcLookupOptions(org.apache.flink.connector.jdbc.internal.options.JdbcLookupOptions) JdbcConnectorOptions(org.apache.flink.connector.jdbc.internal.options.JdbcConnectorOptions) JdbcReadOptions(org.apache.flink.connector.jdbc.internal.options.JdbcReadOptions) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) Test(org.junit.Test)

Example 9 with JdbcConnectorOptions

use of org.apache.flink.connector.jdbc.internal.options.JdbcConnectorOptions in project flink-connector-jdbc-ext by lixz3321.

the class JdbcDynamicTableFactoryTest method testJDBCSinkWithParallelism.

@Test
public void testJDBCSinkWithParallelism() {
    Map<String, String> properties = getAllOptions();
    properties.put("sink.parallelism", "2");
    DynamicTableSink actual = createTableSink(SCHEMA, properties);
    JdbcConnectorOptions options = JdbcConnectorOptions.builder().setDBUrl("jdbc:derby:memory:mydb").setTableName("mytable").setParallelism(2).build();
    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 expected = new JdbcDynamicTableSink(options, executionOptions, dmlOptions, TableSchema.fromResolvedSchema(SCHEMA));
    assertEquals(expected, actual);
}
Also used : JdbcExecutionOptions(org.apache.flink.connector.jdbc.JdbcExecutionOptions) 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) Test(org.junit.Test)

Example 10 with JdbcConnectorOptions

use of org.apache.flink.connector.jdbc.internal.options.JdbcConnectorOptions in project flink-connector-jdbc-ext by lixz3321.

the class JdbcDynamicTableFactory method createDynamicTableSink.

@Override
public DynamicTableSink createDynamicTableSink(Context context) {
    final FactoryUtil.TableFactoryHelper helper = FactoryUtil.createTableFactoryHelper(this, context);
    final ReadableConfig config = helper.getOptions();
    helper.validate();
    validateConfigOptions(config);
    JdbcConnectorOptions jdbcOptions = getJdbcOptions(config);
    TableSchema physicalSchema = TableSchemaUtils.getPhysicalSchema(context.getCatalogTable().getSchema());
    return new JdbcDynamicTableSink(jdbcOptions, getJdbcExecutionOptions(config), getJdbcDmlOptions(jdbcOptions, physicalSchema), physicalSchema);
}
Also used : ReadableConfig(org.apache.flink.configuration.ReadableConfig) JdbcConnectorOptions(org.apache.flink.connector.jdbc.internal.options.JdbcConnectorOptions) TableSchema(org.apache.flink.table.api.TableSchema) FactoryUtil(org.apache.flink.table.factories.FactoryUtil)

Aggregations

JdbcConnectorOptions (org.apache.flink.connector.jdbc.internal.options.JdbcConnectorOptions)81 Test (org.junit.Test)71 JdbcDmlOptions (org.apache.flink.connector.jdbc.internal.options.JdbcDmlOptions)57 JdbcExecutionOptions (org.apache.flink.connector.jdbc.JdbcExecutionOptions)21 IOException (java.io.IOException)20 SQLException (java.sql.SQLException)20 TestEntry (org.apache.flink.connector.jdbc.JdbcTestFixture.TestEntry)20 JdbcLookupOptions (org.apache.flink.connector.jdbc.internal.options.JdbcLookupOptions)18 Connection (java.sql.Connection)16 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)16 DynamicTableSource (org.apache.flink.table.connector.source.DynamicTableSource)15 DynamicTableSink (org.apache.flink.table.connector.sink.DynamicTableSink)12 RowData (org.apache.flink.table.data.RowData)12 SimpleJdbcConnectionProvider (org.apache.flink.connector.jdbc.internal.connection.SimpleJdbcConnectionProvider)8 ReadableConfig (org.apache.flink.configuration.ReadableConfig)5 JdbcReadOptions (org.apache.flink.connector.jdbc.internal.options.JdbcReadOptions)5 FactoryUtil (org.apache.flink.table.factories.FactoryUtil)5 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)4 RuntimeContext (org.apache.flink.api.common.functions.RuntimeContext)4