use of org.apache.flink.table.factories.Factory in project flink by apache.
the class FileSystemTableFactory method formatFactoryExists.
/**
* Returns true if the format factory can be found using the given factory base class and
* identifier.
*/
private boolean formatFactoryExists(Context context, Class<?> factoryClass) {
Configuration options = Configuration.fromMap(context.getCatalogTable().getOptions());
String identifier = options.get(FactoryUtil.FORMAT);
if (identifier == null) {
throw new ValidationException(String.format("Table options do not contain an option key '%s' for discovering a format.", FactoryUtil.FORMAT.key()));
}
final List<Factory> factories = new LinkedList<>();
ServiceLoader.load(Factory.class, context.getClassLoader()).iterator().forEachRemaining(factories::add);
final List<Factory> foundFactories = factories.stream().filter(f -> factoryClass.isAssignableFrom(f.getClass())).collect(Collectors.toList());
final List<Factory> matchingFactories = foundFactories.stream().filter(f -> f.factoryIdentifier().equals(identifier)).collect(Collectors.toList());
return !matchingFactories.isEmpty();
}
Aggregations