Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Feature: Add metadata-only replace API to Table for REPLACE snapshot operations

Aperta
#3,130 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
28/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
databases

Direzione di ricerca

Inizia da pyiceberg/table/update/snapshot.py e dalle API di snapshot esistenti di Table e Transaction, quindi confronta il comportamento proposto con l’interfaccia RewriteFiles di Java. Esamina tests/table/test_snapshots.py, in particolare test_invalid_operation(), e aggiungi una copertura mirata per gli scambi di file, i numeri di sequenza e operation=REPLACE. Il lavoro è completo quando la sostituzione basata solo sui metadati funziona atomicamente con input Iterable[DataFile] ed evita la serializzazione Parquet.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Feature Request / Improvement

Description

This issue proposes implementing a metadata-only replace API in PyIceberg, enabling orchestrators to submit a set of DataFiles to delete and a set of DataFiles to append in a single atomic transaction.

This functionality is critical for maintenance operations such as data compaction (the "small files" problem), ensuring the logical state of the table remains unaltered while physical data layout is optimized.

Background

In a current PR (#3124, part of #1092), PyIceberg's replace semantics are tightly coupled with PyArrow dataframes (def replace(self, df: pa.Table)). This approach introduces several architectural flaws:

  1. Coupling Physical Serialization with Metadata: It forces a .parquet write serialization hook directly into the snapshot commit transaction, increasing the risk of schema degradation and blocking network topologies.
  2. Missing Operation.REPLACE: The current system uses primitives that log as APPEND or OVERWRITE, muddying the table history and complicating snapshot expiry/maintenance.
  3. Java Inconsistency: This severely drifts from Java Iceberg's native org.apache.iceberg.RewriteFiles specification, which strictly isolates the builder into accepting purely DataFile pointers.
Proposed Solution

To fix this and achieve logical equivalence, we must implement an exact port of Java's RewriteFiles builder API into PyIceberg's native _SnapshotProducer engine.

  1. Introduce _RewriteFiles Snapshot Producer:
    Add a new _RewriteFiles class that specifically targets replacing existing files. This class will implement:

    • _deleted_entries(): To find the existing target files and re-emit them as DELETED entries, defensively keeping their ancestral sequence_numbers completely intact for time travel compatibility.
    • _existing_manifests(): To scavenge unchanged manifests natively, skipping deep rewrites and only mutating manifests impacted by the deleted files.
  2. Builder Hook Implementation:
    Implement UpdateSnapshot().replace() which configures the transaction with Operation.REPLACE.

  3. Expose Shorthands on Table & Transaction:
    Add replace APIs on both Table and Transaction taking Iterable[DataFile] arguments to elegantly wrap the snapshot mutation:

    def replace(
        self,
        files_to_delete: Iterable[DataFile],
        files_to_add: Iterable[DataFile],
        snapshot_properties: dict[str, str] = EMPTY_DICT,
        branch: str | None = MAIN_BRANCH,
    ) -> None:
        ...
    
Notable canges
  • replace() API implemented on both Table and Transaction using Iterable[DataFile].
  • PyArrow .parquet write logic decoupled from the metadata transaction.
  • _RewriteFiles correctly copies ancestral sequence_number pointers for DELETED and EXISTING manifest entries.
  • Snapshots committed via the replace() hook possess a Summary containing operation=Operation.REPLACE.
  • Unit tests pass simulating data file swaps and summary verifications.
Related Java API

Inspired heavily by Java's builder interface: https://github.com/apache/iceberg/blob/main/api/src/main/java/org/apache/iceberg/RewriteFiles.java

AI Disclosure

AI was used to help understand the code base and draft code changes. All code changes have been thoroughly reviewed, ensuring that the code changes are in line with a broader understanding of the codebase.

  • Worth deeper review after AI-assistance:
  • The test_invalid_operation() in tests/table/test_snapshots.py previously used Operation.REPLACE as a value to test invalid operations, but with this change Operation.REPLACE becomes valid. In place I just put a dummy Operation.
  • The _RewriteFiles in pyiceberg/table/update/snapshot.py overrides the _deleted_entries and _existing_manifests functions. I sought to test this thoroughly that it was done correctly. I am thinking it's possible to improve the test suite to make this more rigorous. I am open to suggestions on how that could be done.
Lingua principale
Python
Stelle
1.1k
Fork
589
Merge medio
2g 2h
PR unite (30g)
70

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/iceberg-python

Tutte le issue di apache/iceberg-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.