Class FactoryUtil
- java.lang.Object
-
- org.apache.flink.table.factories.FactoryUtil
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFactoryUtil.CatalogFactoryHelperHelper utility for validating all options for aCatalogFactory.static classFactoryUtil.CatalogStoreFactoryHelperHelper utility for validating all options for aCatalogStoreFactory.static classFactoryUtil.DefaultCatalogContextDefault implementation ofCatalogFactory.Context.static classFactoryUtil.DefaultCatalogStoreContextDefault implementation ofCatalogStoreFactory.Context.static classFactoryUtil.DefaultDynamicTableContextDefault implementation ofDynamicTableFactory.Context.static classFactoryUtil.DefaultModelProviderContextDefault implementation ofModelProviderFactory.Context.static classFactoryUtil.DefaultModuleContextDefault implementation ofModuleFactory.Context.static classFactoryUtil.FactoryHelper<F extends Factory>Base helper utility for validating all options for aFactory.static classFactoryUtil.ModelProviderFactoryHelperHelper utility for validating all options for aModelProviderFactory.static classFactoryUtil.ModuleFactoryHelperHelper utility for validating all options for aModuleFactory.static classFactoryUtil.TableFactoryHelperHelper utility for discovering formats and validating all options for aDynamicTableFactory.
-
Field Summary
Fields Modifier and Type Field Description static org.apache.flink.configuration.ConfigOption<String>CONNECTORstatic org.apache.flink.configuration.ConfigOption<String>FORMATstatic StringFORMAT_SUFFIXSuffix for keys ofConfigOptionin case a connector requires multiple formats (e.g.static StringPLACEHOLDER_SYMBOLThe placeholder symbol to be used for keys of options which can be templated.static org.apache.flink.configuration.ConfigOption<Integer>PROPERTY_VERSIONDescribes the property version.static org.apache.flink.configuration.ConfigOption<String>PROVIDERstatic org.apache.flink.configuration.ConfigOption<Integer>SINK_PARALLELISMstatic org.apache.flink.configuration.ConfigOption<Duration>SOURCE_IDLE_TIMEOUTstatic org.apache.flink.configuration.ConfigOption<Integer>SOURCE_PARALLELISMstatic org.apache.flink.configuration.ConfigOption<List<String>>SQL_GATEWAY_ENDPOINT_TYPEstatic org.apache.flink.configuration.ConfigOption<String>WATERMARK_ALIGNMENT_GROUPstatic org.apache.flink.configuration.ConfigOption<Duration>WATERMARK_ALIGNMENT_MAX_DRIFTstatic org.apache.flink.configuration.ConfigOption<Duration>WATERMARK_ALIGNMENT_UPDATE_INTERVALstatic org.apache.flink.configuration.ConfigOption<WatermarkEmitStrategy>WATERMARK_EMIT_STRATEGYstatic org.apache.flink.configuration.ConfigOption<String>WORKFLOW_SCHEDULER_TYPE
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Optional<String>checkWatermarkOptions(org.apache.flink.configuration.ReadableConfig conf)Check watermark-related options and return error messages.static CatalogcreateCatalog(String catalogName, Map<String,String> options, org.apache.flink.configuration.ReadableConfig configuration, ClassLoader classLoader)Attempts to discover an appropriate catalog factory and creates an instance of the catalog.static FactoryUtil.CatalogFactoryHelpercreateCatalogFactoryHelper(CatalogFactory factory, CatalogFactory.Context context)Creates a utility that helps validating options for aCatalogFactory.static FactoryUtil.CatalogStoreFactoryHelpercreateCatalogStoreFactoryHelper(CatalogStoreFactory factory, CatalogStoreFactory.Context context)Creates a utility that helps validating options for aCatalogStoreFactory.static DynamicTableSinkcreateDynamicTableSink(DynamicTableSinkFactory preferredFactory, ObjectIdentifier objectIdentifier, ResolvedCatalogTable catalogTable, Map<String,String> enrichmentOptions, org.apache.flink.configuration.ReadableConfig configuration, ClassLoader classLoader, boolean isTemporary)Creates aDynamicTableSinkfrom aCatalogTable.static DynamicTableSourcecreateDynamicTableSource(DynamicTableSourceFactory preferredFactory, ObjectIdentifier objectIdentifier, ResolvedCatalogTable catalogTable, Map<String,String> enrichmentOptions, org.apache.flink.configuration.ReadableConfig configuration, ClassLoader classLoader, boolean isTemporary)Creates aDynamicTableSourcefrom aCatalogTable.static ModelProvidercreateModelProvider(ModelProviderFactory preferredFactory, ObjectIdentifier objectIdentifier, ResolvedCatalogModel catalogModel, org.apache.flink.configuration.ReadableConfig configuration, ClassLoader classLoader, boolean isTemporary)Creates aModelProviderfrom aResolvedCatalogModel.static FactoryUtil.ModelProviderFactoryHelpercreateModelProviderFactoryHelper(ModelProviderFactory factory, ModelProviderFactory.Context context)Creates a utility that helps validate options for aModelProviderFactory.static ModulecreateModule(String moduleName, Map<String,String> options, org.apache.flink.configuration.ReadableConfig configuration, ClassLoader classLoader)Discovers a matching module factory and creates an instance of it.static FactoryUtil.ModuleFactoryHelpercreateModuleFactoryHelper(ModuleFactory factory, ModuleFactory.Context context)Creates a utility that helps validating options for aModuleFactory.static FactoryUtil.TableFactoryHelpercreateTableFactoryHelper(DynamicTableFactory factory, DynamicTableFactory.Context context)Creates a utility that helps in discovering formats, merging options withDynamicTableFactory.Context.getEnrichmentOptions()and validating them all for aDynamicTableFactory.static <T extends Factory>
TdiscoverFactory(ClassLoader classLoader, Class<T> factoryClass, String factoryIdentifier)Discovers a factory using the given factory base class and identifier.static <T extends DynamicTableFactory>
Optional<T>getDynamicTableFactory(Class<T> factoryClass, Catalog catalog)Returns theDynamicTableFactoryviaCatalog.static StringgetFormatPrefix(org.apache.flink.configuration.ConfigOption<String> formatOption, String formatIdentifier)Returns the required option prefix for options of the given format.static StringstringifyOption(String key, String value)static voidvalidateFactoryOptions(Set<org.apache.flink.configuration.ConfigOption<?>> requiredOptions, Set<org.apache.flink.configuration.ConfigOption<?>> optionalOptions, org.apache.flink.configuration.ReadableConfig options)Validates the required options and optional options.static voidvalidateFactoryOptions(Factory factory, org.apache.flink.configuration.ReadableConfig options)Validates the required and optionalConfigOptions of a factory.static voidvalidateUnconsumedKeys(String factoryIdentifier, Set<String> allOptionKeys, Set<String> consumedOptionKeys)Validates unconsumed option keys.static voidvalidateUnconsumedKeys(String factoryIdentifier, Set<String> allOptionKeys, Set<String> consumedOptionKeys, Set<String> deprecatedOptionKeys)Validates unconsumed option keys.static voidvalidateWatermarkOptions(String factoryIdentifier, org.apache.flink.configuration.ReadableConfig conf)Validate watermark options from table options.
-
-
-
Field Detail
-
PROPERTY_VERSION
public static final org.apache.flink.configuration.ConfigOption<Integer> PROPERTY_VERSION
Describes the property version. This can be used for backwards compatibility in case the property format changes.
-
CONNECTOR
public static final org.apache.flink.configuration.ConfigOption<String> CONNECTOR
-
PROVIDER
public static final org.apache.flink.configuration.ConfigOption<String> PROVIDER
-
FORMAT
public static final org.apache.flink.configuration.ConfigOption<String> FORMAT
-
SINK_PARALLELISM
public static final org.apache.flink.configuration.ConfigOption<Integer> SINK_PARALLELISM
-
SQL_GATEWAY_ENDPOINT_TYPE
public static final org.apache.flink.configuration.ConfigOption<List<String>> SQL_GATEWAY_ENDPOINT_TYPE
-
SOURCE_PARALLELISM
public static final org.apache.flink.configuration.ConfigOption<Integer> SOURCE_PARALLELISM
-
WATERMARK_EMIT_STRATEGY
public static final org.apache.flink.configuration.ConfigOption<WatermarkEmitStrategy> WATERMARK_EMIT_STRATEGY
-
WATERMARK_ALIGNMENT_GROUP
public static final org.apache.flink.configuration.ConfigOption<String> WATERMARK_ALIGNMENT_GROUP
-
WATERMARK_ALIGNMENT_MAX_DRIFT
public static final org.apache.flink.configuration.ConfigOption<Duration> WATERMARK_ALIGNMENT_MAX_DRIFT
-
WATERMARK_ALIGNMENT_UPDATE_INTERVAL
public static final org.apache.flink.configuration.ConfigOption<Duration> WATERMARK_ALIGNMENT_UPDATE_INTERVAL
-
SOURCE_IDLE_TIMEOUT
public static final org.apache.flink.configuration.ConfigOption<Duration> SOURCE_IDLE_TIMEOUT
-
WORKFLOW_SCHEDULER_TYPE
public static final org.apache.flink.configuration.ConfigOption<String> WORKFLOW_SCHEDULER_TYPE
-
FORMAT_SUFFIX
public static final String FORMAT_SUFFIX
Suffix for keys ofConfigOptionin case a connector requires multiple formats (e.g. for both key and value).See
createTableFactoryHelper(DynamicTableFactory, DynamicTableFactory.Context)for more information.- See Also:
- Constant Field Values
-
PLACEHOLDER_SYMBOL
public static final String PLACEHOLDER_SYMBOL
The placeholder symbol to be used for keys of options which can be templated. SeeFactoryfor details.- See Also:
- Constant Field Values
-
-
Method Detail
-
createDynamicTableSource
public static DynamicTableSource createDynamicTableSource(@Nullable DynamicTableSourceFactory preferredFactory, ObjectIdentifier objectIdentifier, ResolvedCatalogTable catalogTable, Map<String,String> enrichmentOptions, org.apache.flink.configuration.ReadableConfig configuration, ClassLoader classLoader, boolean isTemporary)
Creates aDynamicTableSourcefrom aCatalogTable.If {@param preferredFactory} is passed, the table source is created from that factory. Otherwise, an attempt is made to discover a matching factory using Java SPI (see
Factoryfor details).
-
createDynamicTableSink
public static DynamicTableSink createDynamicTableSink(@Nullable DynamicTableSinkFactory preferredFactory, ObjectIdentifier objectIdentifier, ResolvedCatalogTable catalogTable, Map<String,String> enrichmentOptions, org.apache.flink.configuration.ReadableConfig configuration, ClassLoader classLoader, boolean isTemporary)
Creates aDynamicTableSinkfrom aCatalogTable.If {@param preferredFactory} is passed, the table sink is created from that factory. Otherwise, an attempt is made to discover a matching factory using Java SPI (see
Factoryfor details).
-
createModelProvider
public static ModelProvider createModelProvider(@Nullable ModelProviderFactory preferredFactory, ObjectIdentifier objectIdentifier, ResolvedCatalogModel catalogModel, org.apache.flink.configuration.ReadableConfig configuration, ClassLoader classLoader, boolean isTemporary)
Creates aModelProviderfrom aResolvedCatalogModel.If {@param preferredFactory} is passed, the model provider is created from that factory. Otherwise, an attempt is made to discover a matching factory using Java SPI (see
Factoryfor details).
-
createCatalogFactoryHelper
public static FactoryUtil.CatalogFactoryHelper createCatalogFactoryHelper(CatalogFactory factory, CatalogFactory.Context context)
Creates a utility that helps validating options for aCatalogFactory.Note: This utility checks for left-over options in the final step.
-
createCatalogStoreFactoryHelper
public static FactoryUtil.CatalogStoreFactoryHelper createCatalogStoreFactoryHelper(CatalogStoreFactory factory, CatalogStoreFactory.Context context)
Creates a utility that helps validating options for aCatalogStoreFactory.Note: This utility checks for left-over options in the final step.
-
createModuleFactoryHelper
public static FactoryUtil.ModuleFactoryHelper createModuleFactoryHelper(ModuleFactory factory, ModuleFactory.Context context)
Creates a utility that helps validating options for aModuleFactory.Note: This utility checks for left-over options in the final step.
-
createTableFactoryHelper
public static FactoryUtil.TableFactoryHelper createTableFactoryHelper(DynamicTableFactory factory, DynamicTableFactory.Context context)
Creates a utility that helps in discovering formats, merging options withDynamicTableFactory.Context.getEnrichmentOptions()and validating them all for aDynamicTableFactory.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 formatsNote: The format option parameter of
FactoryUtil.TableFactoryHelper.discoverEncodingFormat(Class, ConfigOption)andFactoryUtil.TableFactoryHelper.discoverDecodingFormat(Class, ConfigOption)must beFORMATor end withFORMAT_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()usingDynamicTableFactory.forwardOptions(). When invokingFactoryUtil.FactoryHelper.validate(), this utility checks for left-over options in the final step.
-
createModelProviderFactoryHelper
public static FactoryUtil.ModelProviderFactoryHelper createModelProviderFactoryHelper(ModelProviderFactory factory, ModelProviderFactory.Context context)
Creates a utility that helps validate options for aModelProviderFactory.Note: This utility checks for left-over options in the final step.
-
createCatalog
public static Catalog createCatalog(String catalogName, Map<String,String> options, org.apache.flink.configuration.ReadableConfig configuration, ClassLoader classLoader)
Attempts to discover an appropriate catalog factory and creates an instance of the catalog.This first uses the legacy
TableFactorystack to discover a matchingCatalogFactory. If none is found, it falls back to the new stack usingFactoryinstead.
-
createModule
public static Module createModule(String moduleName, Map<String,String> options, org.apache.flink.configuration.ReadableConfig configuration, ClassLoader classLoader)
Discovers a matching module factory and creates an instance of it.This first uses the legacy
TableFactorystack to discover a matchingModuleFactory. If none is found, it falls back to the new stack usingFactoryinstead.
-
discoverFactory
public static <T extends Factory> T discoverFactory(ClassLoader classLoader, Class<T> factoryClass, String factoryIdentifier)
Discovers a factory using the given factory base class and identifier.This method is meant for cases where
createTableFactoryHelper(DynamicTableFactory, DynamicTableFactory.Context)createDynamicTableSource(DynamicTableSourceFactory, ObjectIdentifier, ResolvedCatalogTable, Map, ReadableConfig, ClassLoader, boolean), andcreateDynamicTableSink(DynamicTableSinkFactory, ObjectIdentifier, ResolvedCatalogTable, Map, ReadableConfig, ClassLoader, boolean)are not applicable.
-
validateFactoryOptions
public static void validateFactoryOptions(Factory factory, org.apache.flink.configuration.ReadableConfig options)
Validates the required and optionalConfigOptions of a factory.Note: It does not check for left-over options.
-
validateFactoryOptions
public static void validateFactoryOptions(Set<org.apache.flink.configuration.ConfigOption<?>> requiredOptions, Set<org.apache.flink.configuration.ConfigOption<?>> optionalOptions, org.apache.flink.configuration.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(org.apache.flink.configuration.ConfigOption<String> formatOption, String formatIdentifier)
Returns the required option prefix for options of the given format.
-
getDynamicTableFactory
public static <T extends DynamicTableFactory> Optional<T> getDynamicTableFactory(Class<T> factoryClass, @Nullable Catalog catalog)
Returns theDynamicTableFactoryviaCatalog.
-
validateWatermarkOptions
public static void validateWatermarkOptions(String factoryIdentifier, org.apache.flink.configuration.ReadableConfig conf)
Validate watermark options from table options.- Parameters:
factoryIdentifier- identifier of tableconf- table options
-
-