diff --git a/mkdocs/docs/api.md b/mkdocs/docs/api.md index 57d80d66e2..bb97e55481 100644 --- a/mkdocs/docs/api.md +++ b/mkdocs/docs/api.md @@ -2278,6 +2278,40 @@ shape: (11, 4) └───────────┴─────────────┴────────────────────────────┴─────────────────────┘ ``` +## Incremental append scan + +`incremental_append_scan()` reads only the rows appended to a table between two snapshots: + +```python +tbl.incremental_append_scan( + from_snapshot_id_exclusive=from_snapshot_id, + to_snapshot_id_inclusive=to_snapshot_id, +).to_arrow() +``` + +Both bounds are optional. Without an end, the scan reads up to the current snapshot, and without a start, from the end snapshot's oldest ancestor. The start must be an earlier snapshot in the end snapshot's history, or a `ValueError` is raised. When polling for new rows, skip the scan if the current snapshot is still the last one read, because a start equal to the end raises. + +It takes the same `row_filter`, `selected_fields`, `case_sensitive` and `limit` arguments as [`scan()`](#query-the-data), and can be read with `to_arrow()`, `to_arrow_batch_reader()`, `to_pandas()`, `to_duckdb()`, `to_ray()` or `to_polars()`. It's always planned on the client, even when a REST catalog uses server-side planning for `scan()`. + +The scan can also be built by chaining methods, each of which returns a new scan. Besides `filter()` and `select()`, there are methods for the bounds, and `from_snapshot_id_inclusive()` includes the start snapshot: + +```python +( + tbl.incremental_append_scan() + .from_snapshot_id_inclusive(snapshot_id) + .filter("lat > 40.0") + .select("city") + .to_arrow() +) +``` + + + +!!! warning "Only appends are read" + Only `append` snapshots, such as those committed by `append()` and `add_files()`, are read. Other snapshots are skipped, including any rows they add. Deletes aren't reported, so a row that was deleted after it was appended is still returned, and after an `upsert()` an updated row can be returned with both its old and its new values. + + + ## Type mapping ### PyArrow diff --git a/pyiceberg/table/__init__.py b/pyiceberg/table/__init__.py index d4068b1c0c..646dfa8353 100644 --- a/pyiceberg/table/__init__.py +++ b/pyiceberg/table/__init__.py @@ -1591,6 +1591,7 @@ def incremental_append_scan( The incremental append scan returns the rows added by append snapshots in a snapshot range that match the provided row_filter, projected onto the table's current schema. + Non-append snapshots in the range are skipped, so this is not a changelog scan. Args: from_snapshot_id_exclusive: