Search in sources :

Example 6 with JdbcLookupOptions

use of org.apache.flink.connector.jdbc.internal.options.JdbcLookupOptions in project flink by apache.

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, SCHEMA.toPhysicalRowDataType());
    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 7 with JdbcLookupOptions

use of org.apache.flink.connector.jdbc.internal.options.JdbcLookupOptions in project flink by apache.

the class JdbcRowDataLookupFunctionTest method testEval.

@Test
public void testEval() throws Exception {
    JdbcLookupOptions lookupOptions = JdbcLookupOptions.builder().build();
    JdbcRowDataLookupFunction lookupFunction = buildRowDataLookupFunction(lookupOptions);
    ListOutputCollector collector = new ListOutputCollector();
    lookupFunction.setCollector(collector);
    lookupFunction.open(null);
    lookupFunction.eval(1, StringData.fromString("1"));
    // close connection
    lookupFunction.getDbConnection().close();
    lookupFunction.eval(2, StringData.fromString("3"));
    List<String> result = new ArrayList<>(collector.getOutputs()).stream().map(RowData::toString).sorted().collect(Collectors.toList());
    List<String> expected = new ArrayList<>();
    expected.add("+I(1,1,11-c1-v1,11-c2-v1)");
    expected.add("+I(1,1,11-c1-v2,11-c2-v2)");
    expected.add("+I(2,3,null,23-c2)");
    Collections.sort(expected);
    assertEquals(expected, result);
}
Also used : RowData(org.apache.flink.table.data.RowData) GenericRowData(org.apache.flink.table.data.GenericRowData) JdbcLookupOptions(org.apache.flink.connector.jdbc.internal.options.JdbcLookupOptions) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

JdbcLookupOptions (org.apache.flink.connector.jdbc.internal.options.JdbcLookupOptions)7 Test (org.junit.Test)7 JdbcConnectorOptions (org.apache.flink.connector.jdbc.internal.options.JdbcConnectorOptions)4 DynamicTableSource (org.apache.flink.table.connector.source.DynamicTableSource)4 ArrayList (java.util.ArrayList)3 GenericRowData (org.apache.flink.table.data.GenericRowData)3 RowData (org.apache.flink.table.data.RowData)3 List (java.util.List)2 JdbcExecutionOptions (org.apache.flink.connector.jdbc.JdbcExecutionOptions)1 JdbcDmlOptions (org.apache.flink.connector.jdbc.internal.options.JdbcDmlOptions)1 JdbcReadOptions (org.apache.flink.connector.jdbc.internal.options.JdbcReadOptions)1 DynamicTableSink (org.apache.flink.table.connector.sink.DynamicTableSink)1