Class FactoryUtil

java.lang.Object
org.apache.flink.table.factories.FactoryUtil

@PublicEvolving public final class FactoryUtil extends Object
Utility for working with Factorys.
  • Field Details

  • Method Details

    • createDynamicTableSource

      public static DynamicTableSource createDynamicTableSource(@Nullable org.apache.flink.table.factories.DynamicTableSourceFactory preferredFactory, ObjectIdentifier objectIdentifier, org.apache.flink.table.catalog.ResolvedCatalogTable catalogTable, Map<String,String> enrichmentOptions, ReadableConfig configuration, ClassLoader classLoader, boolean isTemporary)
      Creates a DynamicTableSource from a CatalogTable.

      If is passed, the table source is created from that factory. Otherwise, an attempt is made to discover a matching factory using Java SPI (see Factory for details).

    • createDynamicTableSink

      public static DynamicTableSink createDynamicTableSink(@Nullable org.apache.flink.table.factories.DynamicTableSinkFactory preferredFactory, ObjectIdentifier objectIdentifier, org.apache.flink.table.catalog.ResolvedCatalogTable catalogTable, Map<String,String> enrichmentOptions, ReadableConfig configuration, ClassLoader classLoader, boolean isTemporary)
      Creates a DynamicTableSink from a CatalogTable.

      If is passed, the table sink is created from that factory. Otherwise, an attempt is made to discover a matching factory using Java SPI (see Factory for details).

    • createModelProvider

      public static org.apache.flink.table.ml.ModelProvider createModelProvider(@Nullable org.apache.flink.table.factories.ModelProviderFactory preferredFactory, ObjectIdentifier objectIdentifier, org.apache.flink.table.catalog.ResolvedCatalogModel catalogModel, ReadableConfig configuration, ClassLoader classLoader, boolean isTemporary)
      Creates a ModelProvider from a ResolvedCatalogModel.

      If is passed, the model provider is created from that factory. Otherwise, an attempt is made to discover a matching factory using Java SPI (see Factory for details).

    • createCatalogFactoryHelper

      public static FactoryUtil.CatalogFactoryHelper createCatalogFactoryHelper(org.apache.flink.table.factories.CatalogFactory factory, org.apache.flink.table.factories.CatalogFactory.Context context)
      Creates a utility that helps validating options for a CatalogFactory.

      Note: This utility checks for left-over options in the final step.

    • createCatalogStoreFactoryHelper

      public static FactoryUtil.CatalogStoreFactoryHelper createCatalogStoreFactoryHelper(org.apache.flink.table.factories.CatalogStoreFactory factory, org.apache.flink.table.factories.CatalogStoreFactory.Context context)
      Creates a utility that helps validating options for a CatalogStoreFactory.

      Note: This utility checks for left-over options in the final step.

    • createModuleFactoryHelper

      public static FactoryUtil.ModuleFactoryHelper createModuleFactoryHelper(org.apache.flink.table.factories.ModuleFactory factory, org.apache.flink.table.factories.ModuleFactory.Context context)
      Creates a utility that helps validating options for a ModuleFactory.

      Note: This utility checks for left-over options in the final step.

    • createTableFactoryHelper

      public static FactoryUtil.TableFactoryHelper createTableFactoryHelper(org.apache.flink.table.factories.DynamicTableFactory factory, org.apache.flink.table.factories.DynamicTableFactory.Context context)
      Creates a utility that helps in discovering formats, merging options with DynamicTableFactory.Context.getEnrichmentOptions() and validating them all for a DynamicTableFactory.

      The following example sketches the usage:

      
       // in createDynamicTableSource()
       helper = FactoryUtil.createTableFactoryHelper(this, context);
      
       keyFormat = helper.discoverDecodingFormat(DeserializationFormatFactory.class, KEY_FORMAT);
       valueFormat = helper.discoverDecodingFormat(DeserializationFormatFactory.class, VALUE_FORMAT);
      
       helper.validate();
      
       ... // construct connector with discovered formats
       

      Note: The format option parameter of FactoryUtil.TableFactoryHelper.discoverEncodingFormat(Class, ConfigOption) and FactoryUtil.TableFactoryHelper.discoverDecodingFormat(Class, ConfigOption) must be FORMAT or end with FORMAT_SUFFIX. The discovery logic will replace 'format' with the factory identifier value as the format prefix. For example, assuming the identifier is 'json', if the format option key is 'format', then the format prefix is 'json.'. If the format option key is 'value.format', then the format prefix is 'value.json'. The format prefix is used to project the options for the format factory.

      Note: When created, this utility merges the options from DynamicTableFactory.Context.getEnrichmentOptions() using DynamicTableFactory.forwardOptions(). When invoking FactoryUtil.FactoryHelper.validate(), this utility checks for left-over options in the final step.

    • createModelProviderFactoryHelper

      public static FactoryUtil.ModelProviderFactoryHelper createModelProviderFactoryHelper(org.apache.flink.table.factories.ModelProviderFactory factory, org.apache.flink.table.factories.ModelProviderFactory.Context context)
      Creates a utility that helps validate options for a ModelProviderFactory.

      Note: This utility checks for left-over options in the final step.

    • createCatalog

      public static Catalog createCatalog(String catalogName, Map<String,String> options, ReadableConfig configuration, ClassLoader classLoader)
      Attempts to discover an appropriate catalog factory and creates an instance of the catalog.

      This first uses the legacy TableFactory stack to discover a matching CatalogFactory. If none is found, it falls back to the new stack using Factory instead.

    • createModule

      public static Module createModule(String moduleName, Map<String,String> options, ReadableConfig configuration, ClassLoader classLoader)
      Discovers a matching module factory and creates an instance of it.

      This first uses the legacy TableFactory stack to discover a matching ModuleFactory. If none is found, it falls back to the new stack using Factory instead.

    • discoverFactory

      public static <T extends org.apache.flink.table.factories.Factory> T discoverFactory(ClassLoader classLoader, Class<T> factoryClass, String factoryIdentifier)
    • validateFactoryOptions

      public static void validateFactoryOptions(org.apache.flink.table.factories.Factory factory, ReadableConfig options)
      Validates the required and optional ConfigOptions of a factory.

      Note: It does not check for left-over options.

    • validateFactoryOptions

      public static void validateFactoryOptions(Set<ConfigOption<?>> requiredOptions, Set<ConfigOption<?>> optionalOptions, ReadableConfig options)
      Validates the required options and optional options.

      Note: It does not check for left-over options.

    • validateUnconsumedKeys

      public static void validateUnconsumedKeys(String factoryIdentifier, Set<String> allOptionKeys, Set<String> consumedOptionKeys, Set<String> deprecatedOptionKeys)
      Validates unconsumed option keys.
    • validateUnconsumedKeys

      public static void validateUnconsumedKeys(String factoryIdentifier, Set<String> allOptionKeys, Set<String> consumedOptionKeys)
      Validates unconsumed option keys.
    • getFormatPrefix

      public static String getFormatPrefix(ConfigOption<String> formatOption, String formatIdentifier)
      Returns the required option prefix for options of the given format.
    • getDynamicTableFactory

      public static <T extends org.apache.flink.table.factories.DynamicTableFactory> Optional<T> getDynamicTableFactory(Class<T> factoryClass, @Nullable Catalog catalog)
      Returns the DynamicTableFactory via Catalog.
    • stringifyOption

      public static String stringifyOption(String key, String value)
    • validateWatermarkOptions

      public static void validateWatermarkOptions(String factoryIdentifier, ReadableConfig conf)
      Validate watermark options from table options.
      Parameters:
      factoryIdentifier - identifier of table
      conf - table options
    • checkWatermarkOptions

      public static Optional<String> checkWatermarkOptions(ReadableConfig conf)
      Check watermark-related options and return error messages.
      Parameters:
      conf - table options
      Returns:
      Optional of error messages