Class TableConfig
- java.lang.Object
-
- org.apache.flink.table.api.TableConfig
-
- All Implemented Interfaces:
ReadableConfig
,WritableConfig
@PublicEvolving public final class TableConfig extends Object implements WritableConfig, ReadableConfig
Configuration for the currentTableEnvironment
session to adjust Table & SQL API programs.This class is a pure API class that abstracts configuration from various sources. Currently, configuration can be set in any of the following layers (in the given order):
config.yaml
,- CLI parameters,
StreamExecutionEnvironment
when bridging to DataStream API,EnvironmentSettings.Builder.withConfiguration(Configuration)
/TableEnvironment.create(Configuration)
,- and
set(ConfigOption, Object)
/set(String, String)
.
The latter two represent the application-specific part of the configuration. They initialize and directly modify
getConfiguration()
. Other layers represent the configuration of the execution context and are immutable.The getters
get(ConfigOption)
andgetOptional(ConfigOption)
give read-only access to the full configuration. However, application-specific configuration has precedence. Configuration of outer layers is used for defaults and fallbacks. The settersset(ConfigOption, Object)
andset(String, String)
will only affect application-specific configuration.For common or important configuration options, this class provides getters and setters methods with detailed inline documentation.
For more advanced configuration, users can directly access the underlying key-value map via
getConfiguration()
. Users can configure also underlying execution parameters via this object.For example:
tEnv.getConfig().addConfiguration( new Configuration() .set(CoreOptions.DEFAULT_PARALLELISM, 128) .set(PipelineOptions.AUTO_WATERMARK_INTERVAL, Duration.ofMillis(800)) .set(CheckpointingOptions.CHECKPOINTING_INTERVAL, Duration.ofSeconds(30)) );
Note: Because options are read at different point in time when performing operations, it is recommended to set configuration options early after instantiating a table environment.
-
-
Constructor Summary
Constructors Constructor Description TableConfig()
Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addConfiguration(Configuration configuration)
Adds the given key-value configuration to the underlying application-specific configuration.void
addJobParameter(String key, String value)
Sets a custom user parameter that can be accessed viaFunctionContext.getJobParameter(String, String)
.<T> T
get(ConfigOption<T> option)
Reads a value using the metadata included inConfigOption
.Configuration
getConfiguration()
Gives direct access to the underlying application-specific key-value map for advanced configuration.static TableConfig
getDefault()
Duration
getIdleStateRetention()
ZoneId
getLocalTimeZone()
Returns the current session time zone id.Integer
getMaxGeneratedCodeLength()
Returns the current threshold where generated code will be split into sub-function calls.long
getMaxIdleStateRetentionTime()
Deprecated.usegetIdleStateRetention()
instead.long
getMinIdleStateRetentionTime()
Deprecated.usegetIdleStateRetention()
instead.<T> Optional<T>
getOptional(ConfigOption<T> option)
Reads a value using the metadata included inConfigOption
.PlannerConfig
getPlannerConfig()
Returns the current configuration of Planner for Table API and SQL queries.ReadableConfig
getRootConfiguration()
Gives direct access to the underlying environment-specific key-value map for advanced configuration.SqlDialect
getSqlDialect()
Returns the current SQL dialect.TableConfig
set(String key, String value)
Sets an application-specific string-based value for the given string-based key.<T> TableConfig
set(ConfigOption<T> option, T value)
Sets an application-specific value for the givenConfigOption
.void
setIdleStateRetention(Duration duration)
Specifies a retention time interval for how long idle state, i.e., state which was not updated, will be retained.void
setIdleStateRetentionTime(Duration minTime, Duration maxTime)
Deprecated.usesetIdleStateRetention(Duration)
instead.void
setLocalTimeZone(ZoneId zoneId)
Sets the current session time zone id.void
setMaxGeneratedCodeLength(Integer maxGeneratedCodeLength)
Sets current threshold where generated code will be split into sub-function calls.void
setPlannerConfig(PlannerConfig plannerConfig)
Sets the configuration of Planner for Table API and SQL queries.void
setRootConfiguration(ReadableConfig rootConfiguration)
Sets the given configuration asrootConfiguration
, which contains any configuration set in the execution context.void
setSqlDialect(SqlDialect sqlDialect)
Sets the current SQL dialect to parse a SQL query.Map<String,String>
toMap()
Converts the configuration items into a map of string key-value pairs.
-
-
-
Constructor Detail
-
TableConfig
@Deprecated public TableConfig()
Deprecated.Please usegetDefault()
instead.
-
-
Method Detail
-
set
public <T> TableConfig set(ConfigOption<T> option, T value)
Sets an application-specific value for the givenConfigOption
.This method should be preferred over
set(String, String)
as it is type-safe, avoids unnecessary parsing of the value, and provides inline documentation.Note: Scala users might need to convert the value into a boxed type. E.g. by using
Int.box(1)
orBoolean.box(false)
.- Specified by:
set
in interfaceWritableConfig
- Type Parameters:
T
- type of the value to be stored- Parameters:
option
- metadata informationvalue
- value to be stored- Returns:
- instance of this configuration for fluent API
- See Also:
TableConfigOptions
,ExecutionConfigOptions
,OptimizerConfigOptions
-
set
public TableConfig set(String key, String value)
Sets an application-specific string-based value for the given string-based key.The value will be parsed by the framework on access.
This method exists for convenience when configuring a session with string-based properties. Use
set(ConfigOption, Object)
for more type-safety and inline documentation.
-
get
public <T> T get(ConfigOption<T> option)
Reads a value using the metadata included inConfigOption
. Returns theConfigOption.defaultValue()
if value key not present in the configuration.This method gives read-only access to the full configuration. However, application-specific configuration has precedence. Configuration of outer layers is used for defaults and fallbacks. See the docs of
TableConfig
for more information.- Specified by:
get
in interfaceReadableConfig
- Type Parameters:
T
- type of the value to read- Parameters:
option
- metadata of the option to read- Returns:
- read value or
ConfigOption.defaultValue()
if not found - See Also:
ReadableConfig.getOptional(ConfigOption)
-
getOptional
public <T> Optional<T> getOptional(ConfigOption<T> option)
Reads a value using the metadata included inConfigOption
. In contrast toReadableConfig.get(ConfigOption)
returnsOptional.empty()
if value not present.This method gives read-only access to the full configuration. However, application-specific configuration has precedence. Configuration of outer layers is used for defaults and fallbacks. See the docs of
TableConfig
for more information.- Specified by:
getOptional
in interfaceReadableConfig
- Type Parameters:
T
- type of the value to read- Parameters:
option
- metadata of the option to read- Returns:
- read value or
Optional.empty()
if not found - See Also:
ReadableConfig.get(ConfigOption)
-
toMap
@Internal public Map<String,String> toMap()
Description copied from interface:ReadableConfig
Converts the configuration items into a map of string key-value pairs.- Specified by:
toMap
in interfaceReadableConfig
- Returns:
- a map containing the configuration properties, where the keys are strings and the values are the corresponding configuration values in string format.
-
getConfiguration
public Configuration getConfiguration()
Gives direct access to the underlying application-specific key-value map for advanced configuration.
-
getRootConfiguration
@Internal public ReadableConfig getRootConfiguration()
Gives direct access to the underlying environment-specific key-value map for advanced configuration.
-
addConfiguration
public void addConfiguration(Configuration configuration)
Adds the given key-value configuration to the underlying application-specific configuration. It overwrites existing keys.- Parameters:
configuration
- key-value configuration to be added
-
getSqlDialect
public SqlDialect getSqlDialect()
Returns the current SQL dialect.
-
setSqlDialect
public void setSqlDialect(SqlDialect sqlDialect)
Sets the current SQL dialect to parse a SQL query. Flink's SQL behavior by default.
-
getLocalTimeZone
public ZoneId getLocalTimeZone()
Returns the current session time zone id. It is used when converting to/fromTIMESTAMP WITH LOCAL TIME ZONE
. SeesetLocalTimeZone(ZoneId)
for more details.- See Also:
LocalZonedTimestampType
-
setLocalTimeZone
public void setLocalTimeZone(ZoneId zoneId)
Sets the current session time zone id. It is used when converting to/fromDataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE()
. Internally, timestamps with local time zone are always represented in the UTC time zone. However, when converting to data types that don't include a time zone (e.g. TIMESTAMP, TIME, or simply STRING), the session time zone is used during conversion.Example:
TableConfig config = tEnv.getConfig(); config.setLocalTimeZone(ZoneOffset.ofHours(2)); tEnv.executeSql("CREATE TABLE testTable (id BIGINT, tmstmp TIMESTAMP WITH LOCAL TIME ZONE)"); tEnv.executeSql("INSERT INTO testTable VALUES ((1, '2000-01-01 2:00:00'), (2, TIMESTAMP '2000-01-01 2:00:00'))"); tEnv.executeSql("SELECT * FROM testTable"); // query with local time zone set to UTC+2
should produce:
============================= id | tmstmp ============================= 1 | 2000-01-01 2:00:00' 2 | 2000-01-01 2:00:00'
If we change the local time zone and query the same table:
config.setLocalTimeZone(ZoneOffset.ofHours(0)); tEnv.executeSql("SELECT * FROM testTable"); // query with local time zone set to UTC+0
we should get:
============================= id | tmstmp ============================= 1 | 2000-01-01 0:00:00' 2 | 2000-01-01 0:00:00'
- See Also:
LocalZonedTimestampType
-
getPlannerConfig
public PlannerConfig getPlannerConfig()
Returns the current configuration of Planner for Table API and SQL queries.
-
setPlannerConfig
public void setPlannerConfig(PlannerConfig plannerConfig)
Sets the configuration of Planner for Table API and SQL queries. Changing the configuration has no effect after the first query has been defined.
-
getMaxGeneratedCodeLength
public Integer getMaxGeneratedCodeLength()
Returns the current threshold where generated code will be split into sub-function calls. Java has a maximum method length of 64 KB. This setting allows for finer granularity if necessary.Default value is 4000 instead of 64KB as by default JIT refuses to work on methods with more than 8K byte code.
-
setMaxGeneratedCodeLength
public void setMaxGeneratedCodeLength(Integer maxGeneratedCodeLength)
Sets current threshold where generated code will be split into sub-function calls. Java has a maximum method length of 64 KB. This setting allows for finer granularity if necessary.Default value is 4000 instead of 64KB as by default JIT refuses to work on methods with more than 8K byte code.
-
setIdleStateRetentionTime
@Deprecated public void setIdleStateRetentionTime(Duration minTime, Duration maxTime)
Deprecated.usesetIdleStateRetention(Duration)
instead.Specifies a minimum and a maximum time interval for how long idle state, i.e., state which was not updated, will be retained. State will never be cleared until it was idle for less than the minimum time and will never be kept if it was idle for more than the maximum time.When new data arrives for previously cleaned-up state, the new data will be handled as if it was the first data. This can result in previous results being overwritten.
Set to 0 (zero) to never clean-up the state.
NOTE: Cleaning up state requires additional bookkeeping which becomes less expensive for larger differences of minTime and maxTime. The difference between minTime and maxTime must be at least 5 minutes.
NOTE: Currently maxTime will be ignored and it will automatically derived from minTime as 1.5 x minTime.
- Parameters:
minTime
- The minimum time interval for which idle state is retained. Set to 0 (zero) to never clean-up the state.maxTime
- The maximum time interval for which idle state is retained. Must be at least 5 minutes greater than minTime. Set to 0 (zero) to never clean-up the state.
-
setIdleStateRetention
public void setIdleStateRetention(Duration duration)
Specifies a retention time interval for how long idle state, i.e., state which was not updated, will be retained. State will never be cleared until it was idle for less than the retention time and will be cleared on a best effort basis after the retention time.When new data arrives for previously cleaned-up state, the new data will be handled as if it was the first data. This can result in previous results being overwritten.
Set to 0 (zero) to never clean-up the state.
- Parameters:
duration
- The retention time interval for which idle state is retained. Set to 0 (zero) to never clean-up the state.- See Also:
StateTtlConfig
-
getMinIdleStateRetentionTime
@Deprecated public long getMinIdleStateRetentionTime()
Deprecated.usegetIdleStateRetention()
instead.NOTE: Currently the concept of min/max idle state retention has been deprecated and only idle state retention time is supported. The min idle state retention is regarded as idle state retention and the max idle state retention is derived from idle state retention as 1.5 x idle state retention.- Returns:
- The minimum time until state which was not updated will be retained.
-
getMaxIdleStateRetentionTime
@Deprecated public long getMaxIdleStateRetentionTime()
Deprecated.usegetIdleStateRetention()
instead.NOTE: Currently the concept of min/max idle state retention has been deprecated and only idle state retention time is supported. The min idle state retention is regarded as idle state retention and the max idle state retention is derived from idle state retention as 1.5 x idle state retention.- Returns:
- The maximum time until state which was not updated will be retained.
-
getIdleStateRetention
public Duration getIdleStateRetention()
- Returns:
- The duration until state which was not updated will be retained.
-
addJobParameter
public void addJobParameter(String key, String value)
Sets a custom user parameter that can be accessed viaFunctionContext.getJobParameter(String, String)
.This will add an entry to the current value of
PipelineOptions.GLOBAL_JOB_PARAMETERS
.It is also possible to set multiple parameters at once, which will override any previously set parameters:
Map<String, String> params = ... TableConfig config = tEnv.getConfig(); config.set(PipelineOptions.GLOBAL_JOB_PARAMETERS, params);
-
setRootConfiguration
@Internal public void setRootConfiguration(ReadableConfig rootConfiguration)
Sets the given configuration asrootConfiguration
, which contains any configuration set in the execution context. See the docs ofTableConfig
for more information.- Parameters:
rootConfiguration
- root configuration to be set
-
getDefault
public static TableConfig getDefault()
-
-