Help Center/ AI DataLake/ devg/ Paimon Development Guide/ Paimon on Spark/ Paimon Table Procedure Management
Updated on 2026-11-06 GMT+08:00

Paimon Table Procedure Management

Paimon provides a rich set of procedures for table management, which can be invoked using the CALL statement.

compact

  • Function: Compacts data files to optimize storage.
  • Parameters:
    • table (mandatory): Target table identifier.
    • partitions: Partition filter. Commas (,) indicate AND, and semicolons (;) indicate OR.
    • where: Partition predicate (cannot be used together with partitions).
    • order_strategy: Sorting strategy (order/zorder/hilbert/none)
    • order_by: Columns to sort by.
    • options: Dynamic options.
    • partition_idle_time: Partition idle time.
    • compact_strategy: Compaction strategy (full/minor)
  • Example:
    -- Basic compaction
    CALL sys.compact(table => 'T')  
    -- Compaction with specific partitions
    CALL sys.compact(table => 'T', partitions => 'p=0;p=1')  
    -- Compaction with sorting
    CALL sys.compact(table => 'T', order_strategy => 'zorder', order_by => 'a,b')  
    -- Compaction with WHERE condition
    CALL sys.compact(table => 'T', where => 'p>0 and p<3', order_strategy => 'zorder', order_by => 'a,b')  
    -- Minor compaction
    CALL sys.compact(table => 'T', compact_strategy => 'minor')

compact_manifest

  • Function: Compacts manifest files to optimize metadata storage.
  • Parameters:
    • table (mandatory): Target table identifier.
    • options: Dynamic options.
  • Example:
    CALL sys.compact_manifest(table => 'paimon.db.table');

purge_files

  • Function: Clears all data files of a table.
  • Parameters:
    • table (mandatory): Target table identifier.
  • Example:
    -- Risky operation: All data will be deleted.
    CALL sys.purge_files(table => 'paimon.db.table');

expire_snapshots

  • Function: Clears expired snapshots.
  • Parameters:
    • table (mandatory): Target table identifier.
    • retain_max: Maximum number of snapshots to retain.
    • retain_min: Minimum number of snapshots to retain.
    • older_than: Deletes snapshots created before the timestamp.
    • max_deletes: Maximum number of snapshots that can be deleted at a time.
    • options: Dynamic options.
  • Example:
    CALL sys.expire_snapshots(table => 'default.T', retain_max => 10)

rollback

  • Description: Rolls back to a specified snapshot or tag.
  • Parameters:
    • table (mandatory): Target table identifier.
    • version: Snapshot ID or tag name (discarded).
    • snapshot: Snapshot ID.
    • tag: Tag name.
  • Example:
    -- Roll back to a tag.
    CALL sys.rollback(table => 'default.T', tag => 'tag1')  
    -- Roll back to a snapshot.
    CALL sys.rollback(table => 'default.T', snapshot => 2)  
    -- Use the version parameter.
    CALL sys.rollback(table => 'default.T', version => 'my_tag') 
    CALL sys.rollback(table => 'default.T', version => 10)

rollback_to_watermark

  • Function: Rolls back to the snapshot corresponding to a specified watermark.
  • Parameters:
    • table (mandatory): Target table identifier.
    • watermark: Watermark.
  • Example:
    CALL sys.rollback_to_watermark(table => 'default.T', watermark => 1730292023000)

create_tag

  • Function: Creates a tag based on a snapshot.
  • Parameters:
    • table (mandatory): Target table identifier.
    • tag (mandatory): Tag name.
    • snapshot: Snapshot ID.
    • time_retained: Tag retention period.
  • Example:
    -- Create a tag based on snapshot 10.
    CALL sys.create_tag(table => 'default.T', tag => 'my_tag', snapshot => 10, time_retained => '1 d')  
    -- Create a tag based on the latest snapshot.
    CALL sys.create_tag(table => 'default.T', tag => 'my_tag')

create_tag_from_timestamp

  • Function: Creates a tag based on a specified timestamp.
  • Parameters:
    • table (mandatory): Target table identifier.
    • tag (mandatory): Tag name.
    • timestamp (mandatory): Timestamp.
    • time_retained: Tag retention period.
  • Example:
    CALL sys.create_tag_from_timestamp(table => 'default.T', tag => 'my_tag', timestamp => 1724404318750, time_retained => '1 d')

delete_tag

  • Function: Deletes a tag.
  • Parameters:
    • table (mandatory): Target table identifier.
    • tag (mandatory): Tag name. Use commas (,) to separate multiple tag names.
  • Example:
    CALL sys.delete_tag(table => 'default.T', tag => 'my_tag')

rename_tag

  • Function: Renames a tag.
  • Parameters:
    • table (mandatory): Target table identifier.
    • tag (mandatory): Original tag name.
    • target_tag (mandatory): New tag name.
  • Example:
    CALL sys.rename_tag(table => 'default.T', tag => 'tag1', target_tag => 'tag2')

replace_tag

  • Function: Replaces the information of an existing tag.
  • Parameters:
    • table (mandatory): Target table identifier.
    • tag (mandatory): Tag name.
    • snapshot: Snapshot ID.
    • time_retained: Retention period.
  • Example:
    CALL sys.replace_tag(table => 'default.T', tag => 'tag1', snapshot => 10, time_retained => '1 d')

expire_tags

  • Function: Expires tags older than a specified time.
  • Parameters:
    • table (mandatory): Target table identifier.
    • older_than (mandatory): Expiration time threshold.
  • Example:
    CALL sys.expire_tags(table => 'default.T', older_than => '2024-09-06 11:00:00')

create_branch

  • Function: Creates a branch.
  • Parameters:
    • table (mandatory): Target table identifier.
    • branch (mandatory): Branch name.
    • tag: Tag name.
  • Example:
    CALL sys.create_branch(table => 'test_db.T', branch => 'test_branch') 
    CALL sys.create_branch(table => 'test_db.T', branch => 'test_branch', tag => 'my_tag')

delete_branch

  • Function: Deletes a branch.
  • Parameters:
    • table (mandatory): Target table identifier.
    • branch (mandatory): Branch name. Use commas (,) to separate multiple branch names.
  • Example:
    CALL sys.delete_branch(table => 'test_db.T', branch => 'test_branch')

fast_forward

  • Function: Fast-forwards a branch to the main branch.
  • Parameters:
    • table (mandatory): Target table identifier.
    • branch (mandatory): Branch name.
  • Example:
    CALL sys.fast_forward(table => 'test_db.T', branch => 'test_branch')

expire_partitions

  • Function: Clears expired partitions.
  • Parameters:
    • table (mandatory): Target table identifier.
    • expiration_time: Expiration time.
    • timestamp_formatter: Timestamp formatter.
    • timestamp_pattern: Timestamp pattern.
    • expire_strategy: Expiration strategy (values-time/update-time).
    • max_expires: Maximum number of expired records.
    • options: Dynamic options.
  • Example:
    CALL sys.expire_partitions(table => 'default.T', expiration_time => '1 d', timestamp_formatter => 'yyyy-MM-dd', timestamp_pattern => '$dt', expire_strategy => 'values-time')

mark_partition_done

  • Description: Marks a partition as done.
  • Parameters:
    • table (mandatory): Target table identifier.
    • partitions (mandatory): Partitions (separated by semicolons).
  • Example:
    -- Mark a single partition as done.
    CALL sys.mark_partition_done(table => 'default.T', partitions => 'day=2024-07-01')  
    -- Mark multiple partitions as done.
    CALL sys.mark_partition_done(table => 'default.T', partitions => 'day=2024-07-01;day=2024-07-02')

remove_orphan_files

  • Function: Deletes orphan files.
  • Parameters:
    • table (mandatory): Target table identifier (wildcard pattern db.* is supported)
    • older_than: Deletes orphan files generated before the timestamp.
    • dry_run: Only views orphan files and does not delete them.
    • parallelism: Degree of parallelism.
    • mode: Execution mode (local/distributed).
  • Example:
    CALL sys.remove_orphan_files(table => 'default.T', older_than => '2023-10-31 12:00:00') 
    CALL sys.remove_orphan_files(table => 'default.*', older_than => '2023-10-31 12:00:00') 
    CALL sys.remove_orphan_files(table => 'default.T', older_than => '2023-10-31 12:00:00', dry_run => true)

remove_unexisting_files

  • Function: Deletes files that are referenced in the manifest but do not exist.
  • Parameters:
    • table (mandatory): Target table identifier.
    • dry_run: Only views the files and does not delete them.
    • parallelism: Degree of parallelism.
  • Example:
    CALL sys.remove_unexisting_files(table => 'mydb.myt') 
    CALL sys.remove_unexisting_files(table => 'mydb.myt', dry_run => true)

reset_consumer

  • Function: Resets or deletes a consumer.
  • Parameters:
    • table (mandatory): Target table identifier.
    • consumerId (mandatory): Consumer ID.
    • nextSnapshotId: ID of the next snapshot.
  • Example:
    -- Reset the consumer snapshot ID.
    CALL sys.reset_consumer(table => 'default.T', consumerId => 'myid', nextSnapshotId => 10)  
    -- Delete a consumer.
    CALL sys.reset_consumer(table => 'default.T', consumerId => 'myid')

clear_consumers

  • Function: Clears consumers.
  • Parameters:
    • table (mandatory): Target table identifier.
    • includingConsumers: Consumers to be included (regular expressions are supported).
    • excludingConsumers: Consumers to be excluded (regular expressions are supported).
  • Example:
    -- Clear all consumers.
    CALL sys.clear_consumers(table => 'default.T')  
    -- Clear specified consumers.
    CALL sys.clear_consumers(table => 'default.T', includingConsumers => 'myid.*')  
    -- Exclude specified consumers.
    CALL sys.clear_consumers(table => 'default.T', includingConsumers => '', excludingConsumers => 'myid1.*')

refresh_object_table

  • Function: Refreshes an object table.
  • Parameters:
    • table (mandatory): Target table identifier.
  • Example:
    CALL sys.refresh_object_table('default.T')