Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions mkdocs/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: it might be worth mentioning the builder methods too, especially from_snapshot_id_inclusive(), since the keyword arguments only offer an exclusive start:

tbl.incremental_append_scan().from_snapshot_id_inclusive(snapshot_id).to_arrow()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't usually seem to document the builder APIs in this file (though I'm not sure why) but I do agree and have added builder API docs below 👍


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()
)
```

<!-- prettier-ignore-start -->

!!! 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.

<!-- prettier-ignore-end -->

## Type mapping

### PyArrow
Expand Down
1 change: 1 addition & 0 deletions pyiceberg/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down