Skip to main content
The OverwriteFiles interface provides an API for replacing existing files in an Iceberg table with new files.

Overview

OverwriteFiles accumulates file additions and deletions, producing a new snapshot that replaces deleted files with added files. This is used for:
  • Idempotent writes that replace partitions
  • Update/delete operations that eagerly overwrite files
  • Data compaction and optimization

Interface

Core Methods

overwriteByRowFilter()

Deletes files that match an expression on data rows.
Parameters:
  • expr - An expression on rows in the table
Returns: This for method chaining Throws: ValidationException if a file can contain both rows that match and rows that do not Description: A file is selected to be deleted if it could contain any rows that match the expression (using an inclusive projection). Files are deleted if all rows in the file must match the expression (using a strict projection). Example:

addFile()

Adds a data file to the table.
Parameters:
  • file - A data file to add
Returns: This for method chaining Example:

deleteFile()

Deletes a data file from the table.
Parameters:
  • file - A data file to delete
Returns: This for method chaining Example:

deleteFiles()

Deletes a set of data files along with their delete files.
Parameters:
  • dataFilesToDelete - The data files to be deleted
  • deleteFilesToDelete - The delete files corresponding to the data files
Returns: This for method chaining

Validation Methods

validateAddedFilesMatchOverwriteFilter()

Validates that each added file matches the overwrite expression.
Returns: This for method chaining Description: Ensures writes are idempotent by validating that added files match the overwrite filter. This prevents adding files that wouldn’t be removed if the operation ran again. Example:

validateFromSnapshot()

Sets the snapshot ID used in any reads for this operation.
Parameters:
  • snapshotId - A snapshot ID
Returns: This for method chaining Description: Validations will check changes after this snapshot ID. If not set, all ancestor snapshots through the table’s initial snapshot are validated.

conflictDetectionFilter()

Sets a conflict detection filter for validating concurrent changes.
Parameters:
  • conflictDetectionFilter - An expression on rows in the table
Returns: This for method chaining

validateNoConflictingData()

Enables validation that concurrently added data does not conflict.
Returns: This for method chaining Description: Required for non-idempotent overwrite operations. Validates that no new files matching the conflict detection filter have been added concurrently. Example:

validateNoConflictingDeletes()

Enables validation that concurrent deletes do not conflict.
Returns: This for method chaining Description: Required for non-idempotent overwrite operations. Validates that no concurrent deletes affect the files being overwritten.

caseSensitive()

Enables or disables case sensitive expression binding.
Parameters:
  • caseSensitive - Whether expression binding should be case sensitive
Returns: This for method chaining

Examples

Partition Overwrite (Idempotent)

File-Level Overwrite

Compaction with Overwrite

Dynamic Overwrite

Non-Idempotent Update with Validation

Multi-Partition Overwrite

Overwrite with Delete Files

Validation Modes

Idempotent Overwrite

For operations that can safely be retried:

Non-Idempotent Overwrite

For operations that must check for conflicts:

See Also