读取表在较早快照时的状态

阅读约需 40分钟 分钟,7节中含3个示例。

版次 2026.11.10 示例于 2026年11月20日 通过 39个示例中有39个通过 变化内容

AI 翻译。由人工以英文核验。 我们如何制作图书

译自英文版图书,版次 2026.11.10。 阅读原文

本章教你读取表在较早一次提交之后的状态,涵盖三种格式:列出该表的提交,按各格式使用的编号读取其中一次提交,并在不同格式之间比较这些编号而不致混淆。

假设 wiki.pageviews_hourly 的仪表盘合计值(按小时对 views 求和)在第三个小时的数据写入后发生了变化,其负责人提出两个问题:该次提交之前的合计值是多少?变化的是表本身,还是仅仅是查询?要回答这两个问题,需要表的历史记录,以及读取表的旧状态的方法。这张表有五列:hour_utc、domain_code、page_title、views 和 response_bytes。本章的每个示例都会像第 1 章那样构建各自的表副本:创建表,并将 00、01 和 02 三个小时的数据作为三次提交追加进去。第 00 小时有 499 行,其余两个小时各有 500 行。

每次提交都是一个快照

最近一次修改见于版次 2026.11.10

第 1 章把这三个小时的数据写成了三次提交。每次提交都会留下一个快照,之后读取的正是这个快照。

一次提交通过一个原子步骤修改表的元数据,因此读取方看到的要么是提交之前的表,要么是提交之后的表,不会看到中间状态。在 Apache Iceberg 中,每次提交都会创建一个快照。Iceberg 规范将快照定义为“表在某一时刻的状态”,用于访问表中完整的数据文件集合,并把每一次变更描述为元数据文件的一次原子替换。快照有唯一的 ID、创建时间和摘要。快照摘要中有一个必填字段 operation,其取值为 append、replace、overwrite 或 delete 之一。append 表示添加了数据文件,没有删除任何文件。之后的提交会新增一个快照,并保持之前的快照不变,这使得仪表盘的负责人可以询问一个已不再是最新的状态。

在执行任何扫描之前,先读取历史记录:本示例按顺序列出三次提交,并给出每次提交的操作类型和新增行数,先是 Iceberg,然后是 Delta Lake。

snapshot-history.py Python 3.12.15 · deltalake 1.6.6 · duckdb 2.0.0 · pyarrow 26.0.1 · pyiceberg 0.12.0 通过
"""Commit three hours to an Iceberg table and a Delta Lake table, then list each commit with its operation and rows added.The prose's point that all three Iceberg commits are appends rests on the operation lines for the snapshots."""from deltalake import DeltaTable, write_deltalakefrom lib.lakehouse import ICEBERG_ID, PAGEVIEWS_SCHEMA, new_warehouse, read_cut_hour, snapshot_labelsdef main():    with new_warehouse() as wh:        table = wh.catalog.create_table(ICEBERG_ID, schema=PAGEVIEWS_SCHEMA)        delta_path = str(wh.root / "delta" / "pageviews_hourly")        for hour in range(3):                       # hours 00, 01 and 02: one commit to each table per hour            batch = read_cut_hour(hour)            table.append(batch)            write_deltalake(delta_path, batch, mode="append")        # sequence_number counts commits, so sorting by it puts the labels in commit order.        snapshots = sorted(table.snapshots(), key=lambda snapshot: snapshot.sequence_number)        labels = snapshot_labels([snapshot.snapshot_id for snapshot in snapshots])        for snapshot in snapshots:            label = labels[snapshot.snapshot_id]            operation = snapshot.summary.operation.value            print(f"{label} operation: {operation}")            # added-records counts only this commit's rows, not the table's running total.            print(f"{label} rows added: {snapshot.summary['added-records']}")        # Sorted by version, so the lines follow Delta's own numbering whatever order history returns.        history = sorted(DeltaTable(delta_path).history(), key=lambda entry: entry["version"])        for entry in history:            rows = entry["operationMetrics"]["num_added_rows"]      # Delta's count of the rows this WRITE added            print(f"version {entry['version']} operation: {entry['operation']}")            print(f"version {entry['version']} rows added: {rows}")if __name__ == "__main__":    main()
输出python snapshot-history.py
snapshot 1 operation: append
snapshot 1 rows added: 499
snapshot 2 operation: append
snapshot 2 rows added: 500
snapshot 3 operation: append
snapshot 3 rows added: 500
version 0 operation: WRITE
version 0 rows added: 499
version 1 operation: WRITE
version 1 rows added: 500
version 2 operation: WRITE
version 2 rows added: 500

三次提交使用的都是 append,因此没有任何一次重写或删除文件。第 00 小时新增了 499 行,比其他两个小时少一行,原因是数据裁剪时丢弃了其中一行,数据说明文件对此有解释。第 01 小时和第 02 小时各新增了 500 行。负责人的问题从这里开始:这张表有三个状态可供选择,而历史记录给出了它们的名称。

pyiceberg 为每个快照分配一个长整型 ID。我们不打印这些 ID。取而代之的是,snapshot_labels 按提交顺序将它们映射为标签“snapshot 1”“snapshot 2”和“snapshot 3”,输出中只打印这些标签。

同样的三个小时的数据通过 write_deltalake 写入了一张 Delta Lake 表,每小时写入一次。Delta Lake 把每次提交称为一个版本,其历史记录列出每个版本的操作类型和写入的行数。Delta 的版本从 0 开始编号,因此第一次写入是版本 0。本书打印 Delta 自己的编号,所以示例按版本对历史记录排序,并打印“version 0”“version 1”和“version 2”。每次 Delta 写入都是一个 WRITE 操作,新增的行数与对应的 Iceberg 快照相同:版本 0 为 499 行,随后分别是 500 行和 500 行。

历史记录回答了负责人所问问题的前半部分:它说明了是哪次提交改变了表,以及该次提交新增了多少行。append 只会添加行,因此不可能改变表中已有小时的合计值。如果某个小时的合计值发生了变化,历史记录中必然会有 overwrite、delete 或 replace 被指为原因,随后你再读取它前后两侧的快照。历史记录不会说明某次查询做了什么,问题的这一部分需要借助下一节的读取操作来回答。

**工作准则:**在读取或修改一张表之前,先以你所使用的格式列出它的历史记录,并将这份列表作为提交编号的唯一来源。按提交顺序对列表排序,在打印之前用 snapshot_labels 为 Iceberg 快照加上标签,并按 Delta 自身的编号方式打印 Delta 版本。读取每次提交时一并读取其操作类型。append 只会添加文件,因此不可能删除了行,而 overwrite 或 delete 则可能删除行。

快照指向什么

最近一次修改见于版次 2026.11.10

快照本身不保存任何行,它指向保存这些行的文件。在格式版本 2 和 3 中,快照记录一个清单列表(manifest list),它的文件就是通过这个列表找到的。上一节中的定义使快照成为通向完整数据文件集合的入口,因此读取方从快照出发,沿着它找到各个文件。

这使快照成为一组指针,而这一结果关系到后面的每一节。只有快照所指名的文件仍然存在时,这个快照才能被读取。因此,时间旅行不是备份。它只读取表仍然保留的文件,而表只在某个快照指名一个文件时才保留该文件。第 7 章会删除旧快照以及只被这些快照指名的文件,这会终止对那些状态的时间旅行。

提交的操作类型表明了哪些共享是可能的。规范将 append 定义为"只添加了数据文件,没有删除任何文件"的操作。因此快照 3 再次指名小时 00 的文件,因为第三次提交没有重写这些文件。多个快照可以指名同一个文件,一次提交的代价只是它所写入的文件,加上指向这些文件的指针。

pyiceberg 中的快照里的行数展示了指针的作用。快照 2 读回 999 行,即小时 00 的 499 行加上小时 01 的 500 行,小时 02 的数据一行也没有。快照 3 读到全部三个小时的数据。每个快照读到的是截至当时各次提交已使之可见的行,不多也不少。两个计数之差正是第三次提交添加的行,共 500 行,所以历史记录与读取结果是一致的。

工作准则: 只有旧快照的文件仍然存在时,才把它视为可读取的。在删除文件之前,先决定保留哪些快照,并先让其余快照过期。针对旧快照的查询若在清理之后失败,原因就是文件缺失。解决办法是从表的某个副本中找回那个文件,而不是改去读取另一个快照来代替它。

读取早期快照

读取早期快照,就是在扫描表时指明要读的那个快照。各种格式指明快照的方式不同。Iceberg 使用快照 ID。DuckLake 在 AT (VERSION => n) 中使用快照编号。Delta Lake 使用版本号。这三种编号计数的对象并不相同。

所有者的第一个问题是,第三个小时的数据写入之前,总量是多少。答案是第二次提交之后的状态,即快照 2。

pyiceberg 中的快照

最近一次修改见于版次 2026.11.7

在 pyiceberg 0.12.0 中,scan(snapshot_id=...) 会按该快照读取表,而不带快照 ID 的扫描则读取当前快照。按 ID 进行两次扫描,就能依据表自身的历史回答所有者的第一个问题;该示例还会读取当前表,并将其与快照 3 比较。

read-as-of-snapshot.py Python 3.12.15 · deltalake 1.6.6 · duckdb 2.0.0 · pyarrow 26.0.1 · pyiceberg 0.12.0 通过
"""Read an Iceberg table as of snapshot 2 and snapshot 3, by ID, then compare the current table with snapshot 3.The prose's answer to the owner's first question rests on the snapshot 2 views line, and the failed read on the last line."""from lib.lakehouse import (    ICEBERG_ID, PAGEVIEWS_SCHEMA, new_warehouse, read_cut_hour, safe_error, scan_arrow, snapshot_labels, sql_rows,)def main():    with new_warehouse() as wh:        table = wh.catalog.create_table(ICEBERG_ID, schema=PAGEVIEWS_SCHEMA)        for hour in range(3):            table.append(read_cut_hour(hour))        snapshots = sorted(table.snapshots(), key=lambda snapshot: snapshot.sequence_number)        ids = [snapshot.snapshot_id for snapshot in snapshots]        labels = snapshot_labels(ids)        # ids[1] is snapshot 2 and ids[2] is snapshot 3: the list is in commit order, counted from 0.        for snapshot_id in (ids[1], ids[2]):            arrow = scan_arrow(table, snapshot_id=snapshot_id)            # The scan is registered in DuckDB as t, so the SQL can count and sum its rows.            rows, views = sql_rows(wh.con, "SELECT count(*), sum(views) FROM t", t=arrow)[0]            print(f"{labels[snapshot_id]} rows: {rows}")            print(f"{labels[snapshot_id]} views: {views}")        current = scan_arrow(table)                  # no snapshot_id, so this reads the current snapshot        last = scan_arrow(table, snapshot_id=ids[2])        print(f"current rows: {current.num_rows}")        # equals compares every row and column, in order; scan_arrow sorts both tables by every column, so row order cannot differ.        assert current.equals(last)        try:            scan_arrow(table, snapshot_id=2)         # 2 is the label's number, not an ID, so this fails on purpose        except Exception as exc:            print(f"read by label: {safe_error(exc, wh)}")if __name__ == "__main__":    main()
输出python read-as-of-snapshot.py
snapshot 2 rows: 999
snapshot 2 views: 580963
snapshot 3 rows: 1499
snapshot 3 views: 899451
current rows: 1499
read by label: ValueError: Snapshot not found: 2

快照 2 回答了所有者的第一个问题。在第三次提交之前,表中共有 580963 次浏览,而在其之后的快照 3 中有 899451 次。不带 ID 读取该表,得到的行与快照 3 相同,并且这项检查比较的是行本身,而不只是行数。

浏览量一列回答了所有者的第二个问题。快照 3 的浏览量比快照 2 多,差值就是 02 时新增的浏览量。总数发生变化,是因为第三次提交添加了行,而不是因为仪表板的查询改变了。对同一张表的两次读取,无需改动查询就能说明这一点。

如果读者心里想的是“快照 2”这个标签,可能会把数字 2 当作 ID 传入。这个调用会失败,而这样的失败是安全的结果:

ValueError: Snapshot not found: 2

错误信息指出了传入的那个数字,它并不是快照 ID,而且表中没有任何内容被改动。读者由此知道应当去查找 ID。该示例本身在 table.snapshots() 中查找每个 ID,从不根据计数来推算 ID。标签用于行文,ID 用于扫描。

工作准则: 从 table.snapshots() 获取快照 ID,并传入你查到的 ID,绝不要传入标签的编号。在打印任何内容之前,先按提交顺序把 ID 映射到标签。当问题是某次提交之后的状态时,先在历史中找到该次提交,再读取它所创建的快照。

按编号读取各格式中的提交

最近一次修改见于版次 2026.11.10

Delta Lake 用 DeltaTable(path, version=n) 读取较早的版本。版本是该提交在表历史中的位置,从 0 开始计数,因此版本 0 是第一次写入。辅助函数 read_delta 接收路径和可选的版本号,并以排序后的 Arrow 表返回数据行。在本书中,所有 Delta 读取都通过 deltalake 的 QueryBuilder 进行,辅助函数会替你调用它。原因见决策节。

DuckLake 对目录的每一次变更都保留一个快照,创建 schema 和创建表也算作变更。DuckLake 的快照编号同样从 0 开始,因此新目录中的第一次插入的编号并不是 1。DuckLake 时间旅行页面给出了读取快照的子句 SELECT * FROM tbl AT (VERSION => 3);,并说明要查询的快照可以按时间戳指定,或“显式使用快照标识符”。本书使用标识符。你应当从 ducklake_snapshots 读取编号,而不是根据自己对插入次数的计数来推算。

三版本示例让两种格式的编号出现分歧,而行数保持一致:它把相同的三个小时的数据写入一张 Delta 表和一张 DuckLake 表,每种格式每小时提交一次。示例按编号逐个读回每次提交,打印两种格式的行数,统计第一次插入之前的 DuckLake 快照数,并展示一种失败情形。

three-version-numbers.py Python 3.12.15 · deltalake 1.6.6 · duckdb 2.0.0 · pyarrow 26.0.1 · pyiceberg 0.12.0 通过
"""Commit the same three hours to Delta Lake and DuckLake, then read each commit back by its own number.The prose's point that each hour gives the same row count in both formats rests on the paired row-count lines."""from deltalake import DeltaTable, write_deltalakefrom lib.lakehouse import (DUCKLAKE_ALIAS, NAMESPACE, TABLE, attach_ducklake, connect_ducklake, new_warehouse,                           read_cut_hour, read_delta, safe_error, snapshot_labels, sql_rows)LAKE_TABLE = f"{DUCKLAKE_ALIAS}.{NAMESPACE}.{TABLE}"CATALOG_SNAPSHOTS = f"SELECT snapshot_id FROM ducklake_snapshots('{DUCKLAKE_ALIAS}')"# Fetches snapshot_time, which turns into Python values through pytz; the pins do not install pytz, so this fails on purpose.TIME_COLUMN = f"SELECT snapshot_time FROM ducklake_snapshots('{DUCKLAKE_ALIAS}')"def main():    with new_warehouse() as wh:        delta_path = str(wh.root / "delta" / TABLE)        connect_ducklake(wh.con)        attach_ducklake(wh.con, DUCKLAKE_ALIAS, wh.root)        wh.con.execute(f"CREATE SCHEMA {DUCKLAKE_ALIAS}.{NAMESPACE}")        # A zero-row slice of hour 00: it gives the table its columns and types, and no rows.        sql_rows(wh.con, f"CREATE TABLE {LAKE_TABLE} AS SELECT * FROM empty", empty=read_cut_hour(0).slice(0, 0))        for hour in range(3):                        # hours 00, 01 and 02, one commit to each table per hour            batch = read_cut_hour(hour)            write_deltalake(delta_path, batch, mode="append")            sql_rows(wh.con, f"INSERT INTO {LAKE_TABLE} SELECT * FROM batch", batch=batch)        # Keeps only the snapshots that inserted rows, so the schema and table creations are left out.        inserts = sorted(row[0] for row in sql_rows(wh.con, CATALOG_SNAPSHOTS + " WHERE map_contains(changes, 'tables_inserted_into')"))        # Snapshot IDs count up with each change, so these are the snapshots made before the first insert.        before = sql_rows(wh.con, CATALOG_SNAPSHOTS + f" WHERE snapshot_id < {inserts[0]}")        print(f"snapshots before the first insert: {len(before)}")        # Labels count every DuckLake snapshot from 1, setup snapshots included, not DuckLake's own numbers.        lake_labels = snapshot_labels(sorted(row[0] for row in sql_rows(wh.con, CATALOG_SNAPSHOTS)))        delta_versions = list(range(DeltaTable(delta_path).version() + 1))     # Delta versions run from 0 to the latest        # zip pairs each hour's Delta version with its DuckLake insert, in order; strict fails if the counts differ.        for hour, (delta_version, snapshot) in enumerate(zip(delta_versions, inserts, strict=True)):            # DuckLake reads by the snapshot ID from ducklake_snapshots, never by counting the inserts.            lake = sql_rows(wh.con, f"SELECT count(*) FROM {LAKE_TABLE} AT (VERSION => {snapshot})")[0][0]            rows = len(read_delta(delta_path, version=delta_version))     # read_delta goes through QueryBuilder, because to_pyarrow_table() aborted at exit in some test runs at these pins.            print(f"after hour {hour:02d}, Delta version {delta_version} rows: {rows}")            print(f"after hour {hour:02d}, DuckLake {lake_labels[snapshot]} rows: {lake}")        try:            wh.con.execute(TIME_COLUMN).fetchall()        except Exception as exc:            print(f"select time: {safe_error(exc, wh)}")if __name__ == "__main__":    main()
输出python three-version-numbers.py
snapshots before the first insert: 3
after hour 00, Delta version 0 rows: 499
after hour 00, DuckLake snapshot 4 rows: 499
after hour 01, Delta version 1 rows: 999
after hour 01, DuckLake snapshot 5 rows: 999
after hour 02, Delta version 2 rows: 1499
after hour 02, DuckLake snapshot 6 rows: 1499
select time: InvalidInputException: Invalid Input Error: Required module 'pytz' failed to import, due to the following Python exception:
ModuleNotFoundError: No module named 'pytz'

第一次插入是“快照 4”而不是“快照 1”,因为在它之前 DuckLake 目录中已经有 3 个快照:DuckLake 在挂载时创建的默认 schema、wiki schema 以及这张表。本书对 DuckLake 快照从 1 开始标注,并把初始化过程计算在内,所以“快照 4”就是 DuckLake 自己的 3 号加 1。从 1 开始数插入次数的读者会得到错误的标签。

每个小时过后,两种格式持有的行数相同,尽管它们对提交的编号方式不同。小时是把二者对齐的键,因为两种格式并不共用同一套编号。在第 02 小时之后,也就是完整的表,Delta 版本 2 有 1499 行,DuckLake 快照 6 有 1499 行,更早的各小时也以同样的方式一一对应。

下表并列给出这三种编号。

格式 用来指称提交的编号 计入哪些变更 读取方式
Iceberg 快照 ID,长整数 对表的每次提交 scan(snapshot_id=...)
Delta Lake 版本,从 0 开始计数 对表的每次提交 DeltaTable(path, version=n)
DuckLake 快照编号,从 0 开始计数(本书的标签比它大 1) 对目录的每一次变更,包括 schema 和表的创建 AT (VERSION => n)

工作准则: 比较各格式时,按每次提交所加载的小时来比较,绝不按原始编号来比较。打印 Iceberg 和 DuckLake 的快照时带上它们的标签,打印 Delta 版本时使用 Delta 自己的编号,并把行数与这些编号绑定。读取 Delta 只通过 read_delta,读取 DuckLake 只使用来自 ducklake_snapshots 的编号。如果某一种格式的表收到了另一种格式没有的提交,标签就不再对齐,此时各格式自身的历史记录是唯一可靠的依据。

这部分尚未翻译,因此以英文显示。

What goes wrong in production

最近一次修改见于版次 2026.11.7

The failures in this chapter are the ones a reader is likely to meet first. The first two appear in this chapter's examples. The third and fourth are argued from the documentation and the book's rules, and the fifth and sixth lean on chapter 1 and chapter 7. The first is the number that is not an ID. A failed scan is a safe failure, because the error says what was wrong. Worse failures come from reading a number that is valid in one format and means something else in another, or from a query that runs and returns something unexpected. The read-as-of-snapshot example shows the first kind: the ID guess fails loudly, and the error text names the value that was passed.

Fetching a time column fails for a different reason, a missing module. The three-version example includes a select of snapshot_time from ducklake_snapshots, and the call fails:

InvalidInputException: Invalid Input Error: Required module 'pytz' failed to import, due to the following Python exception:

The message says the pytz module is missing. The pinned environment does not install it. DuckDB's Python client needs pytz to turn a TIMESTAMPTZ column such as snapshot_time into Python values. The three-version example avoids the problem by selecting only snapshot_id and filtering on changes, so it never fetches snapshot_time. To read the time anyway, cast it with snapshot_time::VARCHAR. Leave out the column or cast it; we would rather not add a package the book does not pin.

Reading by timestamp is the third trap. DuckLake accepts a timestamp in AT (TIMESTAMP => ...), and Iceberg snapshots have a creation time. A timestamp picks a state by the clock, and the clock is the time when each commit ran. In production that is a good way to ask for "the table as it was at nine in the morning". An example would have to take a clock time from the run, which changes on every run, so the book uses IDs and version numbers instead. Choose the timestamp form when you need a point in wall-clock time and you have a record of when each commit ran. Choose the number form when you need the same answer every time.

Numbers drift between formats. Two formats can hold the same table, and the same label can then name different states. The book's example commits the same hours in the same order, so the labels agree. A production table that receives a repair in one format and not the other will not agree. Even with identical histories, the raw numbers do not line up across formats, because DuckLake's snapshot numbers also count schema and table creation. A dashboard that reads "version 4" from both formats will show different totals, so compare commits by their labels. The check is to compare the row counts for the label in both formats before you trust either number. The three-version example does that.

A file count can also read low, because DuckLake may keep a small insert in the catalog instead of writing a Parquet file, under the default chapter 1 names. The example's first hourly batch alone holds 499 rows, far over that limit, so under that default each of its inserts is written as a file. A count of data files is only meaningful once you know the row limit.

The failure this chapter warns about most comes later, at a read after a cleanup. What a snapshot points to gives the reason: the error appears only when a reader asks for a snapshot whose files are gone. Nothing fails at the cleanup itself. Chapter 7 shows which files a cleanup removes.

Working rule: Read the error text before you change the query. It names the value, the module or the version that failed, and that is the fastest route to the fix. Compare each count in one format with the same label in the other format before you trust either one. Keep the snapshot your question needs readable until the question is answered, and expire only the snapshots that no question still needs. Record the label and the format's name with every number you report, so that a reader of the report can reproduce it.

本章做出的决定

最近一次修改见于版次 2026.11.7
  • 用标签,不用 ID。 输出的各行带有“snapshot 2”这类标签,用于 Iceberg 和 DuckLake,从 1 开始,对格式记录的每个快照依次计数。对 DuckLake 而言,这包括三个初始化快照,因此 DuckLake 自身的编号要小 1。Iceberg 的 ID 和 DuckLake 的快照编号从不出现在输出中。Delta 打印自己的版本号,从 0 开始计数,读者传给 DeltaTable 的正是这些编号。读者可以重新运行示例,并逐行比对文本,差异只会反映数据或库的变化,而不会反映随机 ID 的变化。标签按提交顺序建立映射,因此即使某个库以另一种顺序返回历史,标签的含义也不会改变。
  • 用 ID 和版本号,不用时间戳。 按时间戳读取取决于时钟,也取决于每次提交的运行时间。我们按 ID 或编号读取,这样无论示例何时运行,读者都能从同一次提交得到相同的行。需要墙上时钟时间的生产环境读者应使用时间戳形式,并记录每次提交的运行时间。
  • Delta 只通过 read_delta 读取。 辅助函数通过 deltalake 的 QueryBuilder 读取。在这些固定版本下,to_pyarrow_table() 路径在某些运行中会于退出时中止,如第 8 章所测。我们修正读取路径,而不是绕开这一中止,因此没有任何示例调用 os._exit 或隐藏退出状态。
  • DuckLake 只通过辅助函数使用。 每次 DuckLake 运行都用 connect_ducklake 加载 DuckLake,并用 attach_ducklake 挂载它。我们从不设置 allow_unsigned_extensions。本书的运行加载 DuckDB 官方签名的 DuckLake 扩展,该扩展来自仓库中的内置文件,辅助函数会先对照 SOURCE.toml 检查两个哈希,因此离线运行无需下载。只有在读者自己的机器上,当该内置文件不存在时,connect_ducklake 才会运行 INSTALL ducklake。
  • 对目录的查询要窄。 对 ducklake_snapshots 的查询会写明所需的列,并省去 snapshot_time,因为该列需要一个固定版本不会安装的模块。我们宁可写明所需的列,也不添加固定版本中没有记录的依赖。
  • Delta 保留自己的编号。 Delta 打印其真实版本,从 0 开始计数。每个标签只说明它在自己的表中是哪一次提交,绝不表示两种格式持有相同的状态。检查这一点的办法,是比较各标签对应的行数。
  • 失败只打印,不抛出。 有两个示例以一次故意失败的调用结束,每个示例都会捕获错误并将其打印出来。展示失败,是因为读者会遇到它,而完整打印错误文本,是为了让读者能将其与自己的输出对照。
  • 先读历史,再读状态。 代码先列出每种格式的提交,然后才按编号读取某次提交。读者在任何扫描之前,先得到每次提交的操作和行数,因此看起来不对的计数可以对照产生它的提交来检查。

本章,在本版次中

版次 2026.11.10示例于 2026年11月20日 通过本章 3个示例 个示例中有 3 个通过

译自英文版图书,版次 2026.11.10。

引用本节

格式

每种格式均引用英文原书,本译本以其为准。

每种格式都会注明该版次。其链接会打开当前版次,节标题处会说明该节文本最后一次修改的时间。访问日期和检索日期即为您打开此页的当天。

本页内容

第 2 章,共 10 章: 读取表在较早快照时的状态

  1. 每次提交都是一个快照
  2. 快照指向什么
  3. 读取早期快照
  4. pyiceberg 中的快照
  5. 按编号读取各格式中的提交
  6. What goes wrong in production
  7. 本章做出的决定

返回顶部全部章节