Iceberg Table Service Functions
iceberg_expire_snapshots
Description: Each commit in Iceberg generates a new snapshot while retaining old data and metadata for snapshot isolation and time travel. Expire snapshots can be used to clean up old snapshots that are no longer needed and data files only included in unnecessary snapshots to improve query and cost efficiency.
Notes:
- Clearly define the cleaning and retention policy for old snapshots. After executing the cleanup of old snapshots, the deleted old snapshot data will no longer be accessible through regular queries. If a running query relies on the soon-to-expire snapshot data, it may lead to query failure or inaccurate results.
- When executing expire_snapshots, conflicts may arise between conditions such as retain_last, older_than, and snapshot_ids. Iceberg does not strictly adhere to the specified conditions but instead aims to retain as many snapshots as possible.
Syntax:
1 2 | iceberg_expire_snapshots('schema.table','older_than', 'clean_expired_metadata') iceberg_expire_snapshots('schema.table','older_than', retain_last, 'snapshot_ids', 'clean_expired_metadata') |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | String | None | Yes | Table where operations are to be performed |
| older_than | timestamp | 5 days ago | Yes | Snapshots exceeding this time limit will be deleted. Note: You need to input the specific time zone to avoid misunderstandings. It can be specified at input or through set timezone=xxx. |
| retain_last | int | 1 | No | How many snapshots to retain. |
| snapshot_ids | String | None | No | Multiple snapshot IDs can be provided, separated by semicolons (;). |
| clean_expired_metadata | boolean | None | No | If this parameter is set to true, schemas and partition specifications that are no longer referenced will be additionally cleaned up. |
Return values:
| Parameter | Description |
|---|---|
| deleted_data_files_count | Number of deleted data files. |
| deleted_position_delete_files_count | Number of deleted position delete files. |
| deleted_equality_delete_files_count | Number of deleted equality delete files. |
| deleted_manifest_files_count | Number of deleted manifest files. |
| deleted_manifest_lists_count | Number of deleted snapshot files. |
| deleted_statistics_files_count | Number of deleted statistics files. |
iceberg_rewrite_manifests
Description: The Iceberg table tracks each data file. The more data files, the more metadata stored in the snapshot file. rewrite manifests can re-write the table's manifest to optimize scan planning.
Notes: This operation generates a new manifest file, potentially affecting ongoing queries and write operations, leading to metadata conflicts. Avoid concurrent execution with other operations.
Syntax:
1 2 | iceberg_rewrite_manifests(table) iceberg_rewrite_manifests(table, options) |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | String | None | Yes | Table where operations are to be performed |
| options | array | None | No | Operational options. Example: '{spec_id=2}' |
The options parameter supports the following option:
| Parameter | Type | Description |
|---|---|---|
| spec_id | int32 | Rewrites only the manifest file associated with the specified spec_id. Valid values can be queried from iceberg_partition_specs. |
Return values:
| Parameter | Description |
|---|---|
| rewritten_manifests_count | Number of rewritten manifest files. |
| added_manifests_count | Number of new manifest files. |
iceberg_remove_orphanfiles
Description: Files not referenced by any Iceberg metadata file are termed orphaned files. Such files might result from failed transactions, unsuccessful concurrent commits, failures in old snapshot cleanup, or metadata cleanup errors, and can generally be deleted.
Notes: Ensure no concurrent write operations exist. During deletion, if there is a running write task, it might mistakenly delete files being generated (uncommitted temporary files).
Syntax:
1 2 | iceberg_remove_orphanfiles('schema.table') iceberg_remove_orphanfiles('schema.table', 'older_than', 'location') |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | String | None | Yes | Table where operations are to be performed |
| older_than | timestamp | Three days ago | No | Orphan files older than this timestamp will be removed. |
| location | String | Table root directory | No | Only orphan files under this location will be removed. |
Return values:
| Parameter | Description |
|---|---|
| orphan_file_location | Path of the file identified as an orphaned file. |
iceberg_add_files
Description: Add all files under the target folder to the Iceberg table.
This syntax recursively scans all files under the target folder and adds them to the Iceberg table.
All files must satisfy:
- Must be in Parquet format.
- Column names, types, and counts (including partition columns) in the Parquet file must match those in the target table.
- All data within a single Parquet file must belong to the same partition.
Syntax:
1 | iceberg_add_files(table,foldername,iscopy) |
Input parameters:
- table: table name, which is of the regclass type.
- foldername: folder path list, which is of the text type. Multiple paths are supported and are separated by commas (,).
- iscopy: whether to copy, which is of the Boolean type.
Return value: whether the execution is successful, which is of the Boolean type.
iceberg_show_snapshots
Definition: Queries snapshot information for a specified Iceberg table.
Syntax:
1 | iceberg_show_snapshots(table) |
Input parameters: table: table name, which is of the regclass type.
Return values:
- sequence_number: snapshot sequence number, which is of the int64 type.
- snapshot_id: snapshot ID, which is of the int64 type.
- create_time: snapshot creation time, which is of the timestamptz type.
- parent_id: snapshot parent node, which is of the int64 type. If the value is 0, no parent node exists.
- operation: snapshot operation type, which is of the text type.
- manifestlist: path to the manifest list associated with the snapshot, which is of the text type.
- summary: snapshot statistics, which is of the text type.
iceberg_manifests
Description: Queries all manifest files for a specified Iceberg table.
Syntax:
1 | iceberg_manifests(table) |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | String | None | Yes | Name of the table to query. |
Return values:
| Parameter | Description |
|---|---|
| content | An int32 value indicating the file type in the manifest: 0 for data files (DATA), 1 for delete files (DELETES). |
| path | A text value indicating the full path of the manifest file in the storage system. |
| length | An int64 value indicating the size of the manifest file in bytes. |
| partition_spec_id | An int32 value indicating the partition specification ID used by this manifest. |
| added_snapshot_id | An int64 value indicating the snapshot ID that created this manifest. |
| added_data_files_count | An int32 value indicating the number of new data files added in this manifest. |
| existing_data_files_count | An int32 value indicating the number of existing data files in this manifest. |
| deleted_data_files_count | An int32 value indicating the number of data files marked as deleted in this manifest. |
| added_delete_files_count | An int32 value indicating the number of new delete files added in this manifest. |
| existing_delete_files_count | An int32 value indicating the number of existing delete files in this manifest. |
| deleted_delete_files_count | An int32 value indicating the number of delete files marked as deleted in this manifest. |
| partition_summaries | A text value containing a JSON array of partition summaries. Each element corresponds to a partition field and includes details such as contains_null, contains_nan (for floating-point types only), lower_bound, and upper_bound. These represent the range of values for the partition field within this manifest. |
iceberg_manifest_entries
Description: Queries all manifest entry information for a specified Iceberg table. Each entry reflects the status of a data file in a specific snapshot.
Syntax:
1 | iceberg_manifest_entries(table) |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | String | None | Yes | Name of the table to query. |
Return values:
| Parameter | Description |
|---|---|
| status | An int32 value indicating the file status: 0 for existing (EXISTING), 1 for added (ADDED), or 2 for deleted (DELETED). |
| snapshot_id | An int64 value indicating the snapshot ID associated with this entry. |
| sequence_number | An int64 value indicating the sequence number of the file, used to determine write order. |
| file_sequence_number | An int64 value indicating the order in which the file was added within a single snapshot. |
| data_file | A text value containing complete metadata about the data file (e.g., path, format, partitions, size, record count, and column-level statistics). |
| readable_metrics | A text value presenting readable extended column-level statistics extracted from data_file (e.g., minimum, maximum, null counts) for easier inspection and debugging. |
iceberg_partitions
Description: Queries partition statistics for a specified Iceberg table, aggregating metrics for all data files in each partition.
Syntax:
1 | iceberg_partitions(table, small_file_threshold) |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | String | None | Yes | Name of the table to query. |
| small_file_threshold | int32 | 128 (MB) | No | Threshold to classify files as "small." |
Return values:
| Parameter | Description |
|---|---|
| partition | A text value indicating the specific value of the partition column (matching the table's partition schema). |
| spec_id | An int32 value indicating the ID of the partitioning specification used for this partition. |
| record_count | An int64 value indicating the total number of records across all active data files within the partition. |
| file_count | An int32 value indicating the total number of active data files in the partition. |
| total_data_file_size_in_bytes | An int64 value indicating the combined size (in bytes) of all active data files in the partition. |
| position_delete_record_count | An int64 value indicating the total number of records marked as deleted by positional delete files in the partition. |
| position_delete_file_count | An int32 value indicating the number of positional delete files in the partition. |
| equality_delete_record_count | An int64 value indicating the total number of records marked as deleted by equality delete files in the partition. |
| equality_delete_file_count | An int32 value indicating the number of equality delete files in the partition. |
| last_updated_at | A timestamptz value indicating the most recent update time for the partition (corresponding to the snapshot creation time). |
| updated_snapshot_id | An int64 value indicating the snapshot ID associated with the latest update to the partition. |
| small_file_count | An int64 value indicating the number of small files in the partition. |
iceberg_partition_specs
Description: Queries the set of partition key definitions for all historical versions of a specified Iceberg table.
Syntax:
1 | iceberg_partition_specs(table) |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | String | None | Yes | Name of the table to query. |
Return values:
| Parameter | Description |
|---|---|
| spec_id | An int32 value indicating the version ID of the partition key definition. |
| field_id | An int32 value indicating the ID of the partition key. |
| name | A text value indicating the name of the partition key. |
| transform | A text description of the expression used for the partition key. |
| source_id | An int32 value referencing the column ID from which the partition key is derived. This corresponds to the field_id in iceberg_schemas. |
iceberg_schemas
Description: Queries the set of table definitions for all historical versions of a specified Iceberg table.
Syntax:
1 | iceberg_schemas(table) |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | String | None | Yes | Name of the table to query. |
Return values:
| Parameter | Description |
|---|---|
| schema_id | An int32 value indicating the schema version ID. |
| field_id | An int32 value indicating the column ID. |
| name | A text value indicating the column name. |
| type | A text value indicating the column type. |
iceberg_history
Description: Queries historical version information for a specified Iceberg table.
Syntax:
1 | iceberg_history(table) |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | String | None | Yes | Name of the table to query. |
Return values:
| Parameter | Description |
|---|---|
| made_current_at | A timestamptz value indicating when the snapshot was created. |
| snapshot_id | An int64 value indicating the snapshot ID. |
| parent_id | An int64 value indicating the parent snapshot ID. |
| is_current_ancestor | A Boolean value indicating whether this snapshot is an ancestor of the current latest snapshot. |
iceberg_metadata_log_entries
Definition: Queries metadata file information for a specified Iceberg table.
Syntax:
1 | iceberg_metadata_log_entries(table) |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | String | None | Yes | Name of the table to query. |
Return values:
| Parameter | Description |
|---|---|
| timestamp | A timestamptz value indicating when the metadata.json file was generated. |
| file | A string value indicating the path to the metadata.json file. |
| latest_snapshot_id | An int64 value indicating the latest snapshot ID at the time of the metadata.json creation. |
| latest_schema_id | An int64 value indicating the most recent schema (table structure) ID at the time of the metadata.json creation. |
| latest_sequence_number | An int64 value indicating the latest sequence number for the table when the metadata.json file was created. |
iceberg_files
Description: Queries information about all data files and delete files for a specified Iceberg table.
Syntax:
1 | iceberg_files(table) |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | String | None | Yes | Name of the table to query. |
Return values:
| Parameter | Description |
|---|---|
| content | An int32 value indicating the file type. |
| file_path | A string value indicating the file path. |
| file_format | A string value indicating the file storage format. |
| spec_id | An int64 value indicating the specification ID (spec_id) linked to the file. |
| record_count | An int64 value indicating the number of rows within the file. |
| file_size_in_bytes | An int64 value indicating the file size. |
| column_sizes | A string value indicating the storage sizes of each column. |
| value_counts | A string value indicating the number of non-null values for each column. |
| null_value_counts | A string value indicating the number of null values for each column. |
| nan_value_counts | A string value indicating the number of not-a-number (NaN) values for each column. |
| lower_bounds | A string value defining the lower bounds of values for each column. |
| upper_bounds | A string value defining the upper bounds of values for each column. |
iceberg_position_delete_files
Description: Queries position delete file information for a specified Iceberg table.
Syntax:
1 | iceberg_position_delete_files(table) |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | String | None | Yes | Name of the table to query. |
Return values:
| Parameter | Description |
|---|---|
| file_path | A string value indicating the path to the data files associated with the delete files. |
| pos | An int64 value indicating the row number referenced in the delete file. |
| partition | A string value indicating the partition name. |
| spec_id | An int64 value indicating the specification ID of the partition. |
| delete_file_path | A string value indicating the path to the delete files. |
iceberg_refs
Description: Queries all branches/tags for a specified Iceberg table.
Syntax:
1 | iceberg_refs(table) |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | String | None | Yes | Name of the table to query. |
Return values:
| Parameter | Description |
|---|---|
| name | A string value indicating the name. |
| type | A string value indicating whether it is a branch or tag. |
| snapshot_id | An int64 value corresponding to the snapshot ID. |
| max_reference_age_in_ms | An int64 value indicating the retention time in milliseconds. |
| min_snapshots_to_keep | An int64 value defining the minimum number of snapshots to retain. |
| max_snapshot_age_in_ms | An int64 value setting the maximum duration for retaining snapshots, in milliseconds. |
iceberg_register_table
Description: Registers an existing metadata.json file with the current catalog.
Syntax:
1 | select * from iceberg_register_table(table, file_path) |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | String | None | Yes | Registered table name |
| file_path | String | None | Yes | Path of the metadata.json file |
Return values:
| Parameter | Description |
|---|---|
| snapshot_id | Snapshot ID of the newly registered table. The value type is int64. |
| record_count | Total number of rows in the newly registered table. The value type is int64. |
| total_data_files_count | Number of data files in the newly registered table. The value type is int64. |
iceberg_rollback_to_snapshot
Description: Rolls back the main branch of a table to a specified snapshot.
Syntax:
1 | select * from iceberg_rollback_to_snapshot(table, snapshot_id) |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | String | None | Yes | Table name |
| snapshot_id | int64 | None | Yes | ID of the target snapshot |
Return values:
| Parameter | Description |
|---|---|
| previous_snapshot_id | Snapshot ID of the table before the rollback. The value type is int64. |
| current_snapshot_id | Snapshot ID of the table after the rollback. The value type is int64. |
iceberg_rollback_to_timestamp
Description: Rolls back the main branch of a table to a specified timestamp.
Syntax:
1 | select * from iceberg_rollback_to_timestamp(table, timestamp) |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | String | None | Yes | Table name |
| timestamp | timestamptz | None | Yes | Target timestamp |
Return values:
| Parameter | Description |
|---|---|
| previous_snapshot_id | Snapshot ID of the table before the rollback. The value type is int64. |
| current_snapshot_id | Snapshot ID of the table after the rollback. The value type is int64. |
iceberg_set_current_snapshot
Description: Sets the current snapshot of the main branch.
Syntax:
1 | select * from iceberg_set_current_snapshot(table, snapshot_id) |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | String | None | Yes | Table name |
| snapshot_id | int64 | None | Yes | ID of the target snapshot |
Return values:
| Parameter | Description |
|---|---|
| previous_snapshot_id | Snapshot ID of the table before the snapshot is set. The value type is int64. |
| current_snapshot_id | Snapshot ID of the table after the snapshot is set. The value type is int64. |
iceberg_cherrypick_snapshot
Description: Extracts a snapshot to the main branch and creates another snapshot. The extracted snapshot cannot be an ancestor node of the main branch.
Syntax:
1 | select * from iceberg_cherrypick_snapshot(table, snapshot_id) |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | String | None | Yes | Table name |
| snapshot_id | int64 | None | Yes | ID of the snapshot to be extracted |
Return values:
| Parameter | Description |
|---|---|
| previous_snapshot_id | Snapshot ID of the table before the snapshot extraction. The value type is int64. |
| current_snapshot_id | Snapshot ID of the table after the snapshot extraction. The value type is int64. |
iceberg_fast_forward
Description: Fast-forwards the current snapshot of a branch to the latest snapshot of another branch.
Syntax:
1 | select * from iceberg_fast_forward(table, from_branch, to_branch) |
Input parameters:
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| table | string | None | Yes | Table name |
| from_branch | String | None | Yes | Current branch |
| to_branch | String | None | Yes | Target branch |
Return values:
| Parameter | Description |
|---|---|
| branch_updated | Name of the updated branch. The value is a string. |
| previous_ref | Snapshot ID of the table before the snapshot forwarding. The value type is int64. |
| updated_ref | Snapshot ID of the table after the snapshot forwarding. The value type is int64. |
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot