Class TableConfig

java.lang.Object
org.apache.flink.table.api.TableConfig
All Implemented Interfaces:
org.apache.flink.configuration.ReadableConfig, org.apache.flink.configuration.WritableConfig

@PublicEvolving public final class TableConfig extends Object implements org.apache.flink.configuration.WritableConfig, org.apache.flink.configuration.ReadableConfig
Configuration for the current TableEnvironment 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):

  1. config.yaml,
  2. CLI parameters,
  3. StreamExecutionEnvironment when bridging to DataStream API,
  4. EnvironmentSettings.Builder.withConfiguration(Configuration) / TableEnvironment.create(Configuration),
  5. 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) and getOptional(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 setters set(ConfigOption, Object) and set(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.

See Also:
  • Method Details

    • set

      public <T> TableConfig set(org.apache.flink.configuration.ConfigOption<T> option, T value)
      Sets an application-specific value for the given ConfigOption.

      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) or Boolean.box(false).

      Specified by:
      set in interface org.apache.flink.configuration.WritableConfig
      See Also:
    • 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.

      See Also:
    • get

      public <T> T get(org.apache.flink.configuration.ConfigOption<T> option)

      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 interface org.apache.flink.configuration.ReadableConfig
      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
    • getOptional

      public <T> Optional<T> getOptional(org.apache.flink.configuration.ConfigOption<T> option)

      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 interface org.apache.flink.configuration.ReadableConfig
      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
    • toMap

      @Internal public Map<String,String> toMap()
      Specified by:
      toMap in interface org.apache.flink.configuration.ReadableConfig
    • getConfiguration

      public org.apache.flink.configuration.Configuration getConfiguration()
      Gives direct access to the underlying application-specific key-value map for advanced configuration.
    • getRootConfiguration

      @Internal public org.apache.flink.configuration.ReadableConfig getRootConfiguration()
      Gives direct access to the underlying environment-specific key-value map for advanced configuration.
    • addConfiguration

      public void addConfiguration(org.apache.flink.configuration.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/from TIMESTAMP WITH LOCAL TIME ZONE. See setLocalTimeZone(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/from DataTypes.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.

    • 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
    • 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 via FunctionContext.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(org.apache.flink.configuration.ReadableConfig rootConfiguration)
      Sets the given configuration as rootConfiguration, which contains any configuration set in the execution context. See the docs of TableConfig for more information.
      Parameters:
      rootConfiguration - root configuration to be set
    • getDefault

      public static TableConfig getDefault()