Updated on 2024-12-13 GMT+08:00

Enabling and Disabling TTL

Function

Enable or disable the TTL of the Hudi table.

Syntax

call ttl_configuration(table => "[table]", path => "[path]", enabled => "[enabled]", strategy => "[strategy]", value => "[value]", resolveConflictsBy => "[resolveConflictsBy]", runInline => "[runInline]")
  • If strategy is NUM_COMMITS, value indicates that TTL is triggered every [value] commits/deltacommits.
  • If strategy is TIME_ELAPSED, value indicates that TTL is triggered every [value] days.
  • The resolveConflictsBy attribute is used to handle TTL policy conflicts. For example, the dt=2023/05/01 partition is hit by the following two TTL policies:

    Policy A: call ttl_policy_save(table => 'hudi_table', spec => 'dt=2023/05/*', units => 'DAYS', value => '2', level => 'PARTITION');

    Policy B: call ttl_policy_save(table => 'hudi_table', spec => 'dt=2023/05/01', units => 'DAYS', value => '1', level => 'PARTITION');

  • If resolveConflictsBy is MAX_TTL and a partition is hit by multiple TTL policies, the policy with the longest retention period has the highest priority. Policy A takes effect on the dt=2023/05/01 partition, but policy B does not take effect.
  • If resolveConflictsBy is MIN_TTL and a partition is hit by multiple TTL policies, the policy with the shortest retention period has the highest priority. Policy B takes effect on the dt=2023/05/01 partition, but policy A does not take effect.
  • If runInline is true, TTL determines whether to check the TTLs of all partitions based on the values of strategy and value after each write operation is complete. If the TTL needs to be checked and aged partitions are detected, the aged partitions are logically deleted, and the logical deletion operation generates a repalcecommit. When the clean operation is performed, the aged partitions are automatically and physically deleted. If the check is not required, the next write operation is performed.
  • If runInline is false, you do not need to specify strategy or value. TTL checks whether all partitions meet aging conditions during each clean operation. If they do, aged partitions are physically deleted.

Description

Parameter

Description

Mandatory

table

Table name. Database name.Table name is also supported. The value is a string.

No. Specify either table or path.

path

Absolute path of the table. The value is a string.

No. Specify either table or path.

enabled

Whether to enable TTL. The value is a string.

No. The value can be false or true. The default value is false.

strategy

How TTL is defined. The value is a string.

No. The value can be NUM_COMMITS or TIME_ELAPSED. The default value is NUM_COMMITS.

value

TTL triggering interval. The value is a string.

No. The default value is 10.

resolveConflictsBy

Policy to handle TTL conflicts. The value is a string.

No. The value can be MAX_TTL or MIN_TTL. The default value is MAX_TTL.

runInline

Whether the TTL event is triggered when the write operation is complete. The value is a string.

No. The value can be false or true. The default value is false.

Examples

  • Enable TTL for a specified table. The TTL event is triggered every 10 replacecommits.
    call ttl_configuration(table => "hudi_table", enabled => "true", strategy => "NUM_COMMITS", value => "10", resolveConflictsBy => "MAX_TTL", runInline => "true")
  • Enable TTL for a specified path. The TTL event is triggered once every day.
    call ttl_configuration(path => "hdfs://hacluster/user/hive/warehouse/hudi_table/", enabled => "true", strategy => "TIME_ELAPSED", value => "1", resolveConflictsBy => "MIN_TTL", runInline => "true")
  • Enable TTL for a specified table. The TTL event is triggered each time clean is performed.
    call ttl_configuration(table => "hudi_table", enabled => "true", resolveConflictsBy => "MAX_TTL", runInline => "false")
  • Disable TTL.
    call ttl_configuration(table => "hudi_table", enabled => "false")