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
22 changes: 22 additions & 0 deletions mkdocs/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,28 @@ DataFrame()
+---+---+
```

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


Both bounds are optional. Without a start, the scan reads from the beginning of the table's history, and without an end, up to the current snapshot. The start must be an earlier snapshot in the end snapshot's history, or a `ValueError` is raised.

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.

A few things about this paragraph:

  • Without a start, the scan begins at the oldest ancestor of the end snapshot that hasn't been expired, not at the start of the table's whole history. These differ after expiry or a rollback, or when to_snapshot_id_inclusive isn't the current snapshot. Maybe "from the end snapshot's oldest ancestor"?
  • The common polling pattern is to save the last snapshot you read and pass it back as from_snapshot_id_exclusive. If nothing has been committed since, that start equals the current snapshot, and the scan raises:
    ValueError: Starting snapshot (exclusive) … is not a parent ancestor of end snapshot …
    
    "Earlier snapshot" technically covers this, but a note telling readers to compare against tbl.current_snapshot() first would save them a surprise.
  • On the other hand, the exclusive start doesn't need to exist in the metadata anymore. An expired snapshot works as long as it's the parent of a snapshot that's still there, which is worth mentioning for consumers resuming from a saved snapshot ID.


It takes the same filtering and projection arguments, and has the same output methods, as [`scan()`](#query-the-data).

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.

This isn't quite the same as scan():

  • count() lives on DataScan, so IncrementalAppendScan doesn't have it.
  • The "Query the data" section describes REST server-side scan planning (scan-planning-mode=server). The incremental scan always plans on the client, even when the catalog or table asks for server-side planning.

Could we narrow the sentence to the methods it supports (to_arrow, to_arrow_batch_reader, to_pandas, to_duckdb, to_ray, to_polars) and mention that it's always planned on the client? Adding server-side planning support could be a follow-up, since the REST plan request already accepts a start and end snapshot.


<!-- 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 @@ -1592,6 +1592,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