JDBC connector的入口JdbcDynamicTableFactory,提供了source和sink的支持,详细内容参考官网。
Source
在Factory类中通过createDynamicTableSource来创建JdbcDynamicTableSource,并将需要的所有参数传递过去。
jdbc作为source有两种用途:1.数据源使用Scan 2.维表关联使用Lookup。
Scan
通过JdbcRowDataInputFormat来实现数据读取,同时支持了列裁剪,limit下推。
注意:scan source只支持batch。
public ScanRuntimeProvider getScanRuntimeProvider(ScanContext runtimeProviderContext) {
//构造JdbcRowDataInputFormat,传递基础属性
final JdbcRowDataInputFormat.Builder builder =
JdbcRowDataInputFormat.builder()
.setDrivername(options.getDriverName())
.setDBUrl(options.getDbURL())
.setUsername(options.getUsername().orElse(null))
.setPassword(options.getPassword().orElse(null))
.setAutoCommit(readOptions.getAutoCommit());
if (readOptions.getFetchSize() != 0) {
builder.setFetchSize(readOptions.getFetchSize());
}
final JdbcDialect dialect = options.getDialect();//jdbc方言,目前支持mysql、postgres、derby,是根据url来推断
String query =
dialect.getSelectFromStatement(
options.getTableName(), physicalSchema.getFieldNames(), new String[0]);//构造select语句
if (readOptions.getPartitionColumnName().isPresent()) {
//支持并发读取,提高读取速度
long lowerBound = readOptions.getPartitionLowerBound().get