RewritePositionDeleteFiles
TheRewritePositionDeleteFiles action rewrites position delete files to optimize their size and layout within a table. This is commonly used for compacting small delete files and improving query performance.
Interface
Overview
Position delete files can accumulate and become fragmented over time, especially with frequent delete operations. Rewriting them helps by:- Combining small delete files into larger, more efficient ones
- Reducing metadata overhead for query planning
- Improving scan performance by reducing file count
- Optimizing storage layout
Configuration Options
Partial Progress
partial-progress.enabled (default: false)
Enable committing groups of files before the entire rewrite completes. This produces additional commits but allows progress even if some groups fail.
partial-progress.max-commits (default: 10)
Maximum number of Iceberg commits allowed when partial progress is enabled.
Concurrency
max-concurrent-file-group-rewrites (default: 5)
Maximum number of file groups to rewrite simultaneously. Each group is rewritten independently and asynchronously.
Job Ordering
rewrite-job-order (default: none)
Forces the rewrite job order based on the value:
bytes-asc- Rewrite smallest job groups firstbytes-desc- Rewrite largest job groups firstfiles-asc- Rewrite groups with least files firstfiles-desc- Rewrite groups with most files firstnone- No specific ordering (planned order)
Methods
filter
Filter which position delete files to rewrite based on partition values.expression- An Iceberg expression used to find deletes. The filter will be converted to a partition filter with inclusive projection.
this for method chaining
Example:
Any file that may contain rows matching this filter will be included in the rewrite. The filter uses inclusive projection for partition-level matching.
Result
TheResult interface provides statistics about the rewrite operation.
Methods
rewriteResults
Returns detailed results for each file group that was rewritten. Returns:List<FileGroupRewriteResult>
rewrittenDeleteFilesCount
Returns the total count of position delete files that have been rewritten. Returns:int - Number of rewritten files
addedDeleteFilesCount
Returns the total count of newly created position delete files. Returns:int - Number of new files
rewrittenBytesCount
Returns the total number of bytes of position delete files that have been rewritten. Returns:long - Bytes rewritten
addedBytesCount
Returns the total number of bytes of newly added position delete files. Returns:long - Bytes added
FileGroupRewriteResult
Detailed results for a particular position delete file group.FileGroupInfo
Description of a position delete file group.Usage Examples
Basic Rewrite
Rewrite Specific Partitions
With Custom Options
With Partial Progress
Analyze Rewrite Results
Calculate Compression Ratio
Filter Multiple Partitions
Complete Optimization Workflow
Best Practices
- Run after delete operations: Execute this action after batch delete operations to compact delete files
- Use partition filters: For large tables, rewrite delete files partition by partition
- Enable partial progress: For very large tables, enable partial progress to avoid losing work on failure
- Monitor compression: Track the compression ratio to understand optimization effectiveness
- Adjust concurrency: Set concurrency based on cluster capacity and table size
- Combine with other optimizations: Run alongside data file compaction for comprehensive optimization
Rewriting position delete files creates a new snapshot. Old files remain accessible through previous snapshots until they are expired.
Performance Considerations
- File reduction: Fewer files mean faster query planning and execution
- Size optimization: Larger, consolidated files are more efficient
- Resource usage: Adjust concurrency settings based on available resources
- Partial progress: Prevents losing work in case of failures during large rewrites
When to Run This Action
RunRewritePositionDeleteFiles when:
- Position delete files are numerous and small
- Query planning is slow due to delete file overhead
- After bulk delete operations
- As part of regular table maintenance
- Before computing table statistics
Related
- ConvertEqualityDeleteFiles - Convert equality to position deletes
- RemoveDanglingDeleteFiles - Remove obsolete delete files
- RewriteDataFiles - Optimize data file layout
- ExpireSnapshots - Clean up old snapshots