Search in sources :

Example 1 with Factory

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();
}
Also used : DecodingFormatFactory(org.apache.flink.table.factories.DecodingFormatFactory) EncodingFormat(org.apache.flink.table.connector.format.EncodingFormat) Factory(org.apache.flink.table.factories.Factory) SerializationFormatFactory(org.apache.flink.table.factories.SerializationFormatFactory) SHORT_IDS(java.time.ZoneId.SHORT_IDS) BulkWriterFormatFactory(org.apache.flink.connector.file.table.factories.BulkWriterFormatFactory) DeserializationFormatFactory(org.apache.flink.table.factories.DeserializationFormatFactory) HashSet(java.util.HashSet) DecodingFormat(org.apache.flink.table.connector.format.DecodingFormat) DynamicTableSourceFactory(org.apache.flink.table.factories.DynamicTableSourceFactory) TableFactory(org.apache.flink.table.factories.TableFactory) ConfigOption(org.apache.flink.configuration.ConfigOption) LinkedList(java.util.LinkedList) EncodingFormatFactory(org.apache.flink.table.factories.EncodingFormatFactory) BulkReaderFormatFactory(org.apache.flink.connector.file.table.factories.BulkReaderFormatFactory) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) DynamicTableSinkFactory(org.apache.flink.table.factories.DynamicTableSinkFactory) Configuration(org.apache.flink.configuration.Configuration) Set(java.util.Set) ServiceLoader(java.util.ServiceLoader) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) FactoryUtil(org.apache.flink.table.factories.FactoryUtil) ValidationException(org.apache.flink.table.api.ValidationException) Internal(org.apache.flink.annotation.Internal) ValidationException(org.apache.flink.table.api.ValidationException) Configuration(org.apache.flink.configuration.Configuration) DecodingFormatFactory(org.apache.flink.table.factories.DecodingFormatFactory) Factory(org.apache.flink.table.factories.Factory) SerializationFormatFactory(org.apache.flink.table.factories.SerializationFormatFactory) BulkWriterFormatFactory(org.apache.flink.connector.file.table.factories.BulkWriterFormatFactory) DeserializationFormatFactory(org.apache.flink.table.factories.DeserializationFormatFactory) DynamicTableSourceFactory(org.apache.flink.table.factories.DynamicTableSourceFactory) TableFactory(org.apache.flink.table.factories.TableFactory) EncodingFormatFactory(org.apache.flink.table.factories.EncodingFormatFactory) BulkReaderFormatFactory(org.apache.flink.connector.file.table.factories.BulkReaderFormatFactory) DynamicTableSinkFactory(org.apache.flink.table.factories.DynamicTableSinkFactory) LinkedList(java.util.LinkedList)

Aggregations

SHORT_IDS (java.time.ZoneId.SHORT_IDS)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ServiceLoader (java.util.ServiceLoader)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Internal (org.apache.flink.annotation.Internal)1 ConfigOption (org.apache.flink.configuration.ConfigOption)1 Configuration (org.apache.flink.configuration.Configuration)1 BulkReaderFormatFactory (org.apache.flink.connector.file.table.factories.BulkReaderFormatFactory)1 BulkWriterFormatFactory (org.apache.flink.connector.file.table.factories.BulkWriterFormatFactory)1 ValidationException (org.apache.flink.table.api.ValidationException)1 DecodingFormat (org.apache.flink.table.connector.format.DecodingFormat)1 EncodingFormat (org.apache.flink.table.connector.format.EncodingFormat)1 DynamicTableSink (org.apache.flink.table.connector.sink.DynamicTableSink)1 DynamicTableSource (org.apache.flink.table.connector.source.DynamicTableSource)1 DecodingFormatFactory (org.apache.flink.table.factories.DecodingFormatFactory)1 DeserializationFormatFactory (org.apache.flink.table.factories.DeserializationFormatFactory)1