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);
}
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);
}
Aggregations