手把手教你如何写一个FLink Connecter(二)
--lookup source connector篇
前言
lookup source相对于比较简单,其核心原理就是根据key再数据库中查询完数据之后,缓存起来。减少数据库的压力。
DynamicTableSinkFactory类
跟sink一样。lookupsource需要继承DynamicTableSourceFactory。
public DynamicTableSource createDynamicTableSource(Context context) {
FactoryUtil.TableFactoryHelper helper = createTableFactoryHelper(this, context);
helper.validate();
WTableOptions wTableOptions = getConfig(helper);
DecodingFormat<DeserializationSchema<RowData>> deserializationSchemaDecodingFormat =
helper.discoverDecodingFormat(DeserializationFormatFactory.class, VALUE_FORMAT);
ResolvedSchema resolvedSchema = context.getCatalogTable().getResolvedSchema();
Optional<UniqueConstraint> primaryKey = resolvedSchema.getPrimaryKey();
validatePrimaryKey(primaryKey);
String pk = primaryKey.get().getColumns().get(0);
List<String> columnNames = resolvedSchema.getColumnNames();
int pkIndex = columnNames.indexOf(pk);