构建第一张表:从头到尾

阅读约需 39分钟 分钟,10节中含3个示例。

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

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

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

读完本章,你可以把成批的行提交到一张表中,在 DuckDB 中读回这张表,并核对总数。本书面向会写 SQL 和 Python 的数据工程师与分析工程师,他们需要决定湖仓表如何存储、变更、清理、共享,以及如何在不同格式之间迁移。本书最终构建一个成果:pageviews 表。你会存储它、变更它、按较早的快照读取它、清理它、在目录中注册它,并在不同格式之间迁移它。

放在文件夹里的六小时 Wikimedia 页面浏览量还不是一张表。文件夹不会说明其中哪些文件属于这张表,而加载到一半中断时,留下的文件看起来与其他文件毫无区别。本书构建的表按小时记录:每一行表示某一篇公开的 Wikipedia 文章在某一个小时内、在某一个语言版次中被浏览了多少次。我们称它为 pageviews 表。

本章构建这张表的一个粗略版本。它用三种格式(Apache Iceberg、Delta Lake 和 DuckLake)写出这张表,并把每一种都读回 DuckDB,以便你比较总数。后续每一章会把其中一步做扎实:

  • 第 2 章按较早的快照读取这张表。
  • 第 3 章在不重写文件的情况下添加列并重命名列。
  • 第 4 章在不重写旧文件的情况下更改分区。
  • 第 5 章通过删除、更新和合并来更正行。
  • 第 6 章压缩按小时追加所留下的小文件。
  • 第 7 章使快照过期,并移除没有任何快照可达的文件。
  • 第 8 章在目录中注册表,并从 DuckDB 查询它们。
  • 第 9 章在格式之间迁移一张表,并检查副本。
  • 第 10 章根据你的工具所支持的内容选择格式。

你已经了解 SQL、Python 和 Parquet,也知道分区是什么。本章不对它们作解释。

pageviews 表的行覆盖 2024 年 6 月 3 日的六个小时,从 00:00 到 05:59 UTC。这些行来自 Wikimedia 页面浏览量转储,Wikimedia 项目以 CC0 发布这些数据。本书保留英语、德语、法语和日语版次中每小时浏览量最高的 500 个标题,并已去除特殊页面。这一天是固定的,且已成过去,因此它的转储不会再变化,仓库中的数据也不会过时。数据文件夹的 README 给出了来源、许可和确切的截取方式。

这些数据有意保持杂乱。标题带有下划线和非拉丁文字,计数也呈偏态:第 00 小时中排名第一的标题,其浏览量远高于排名第 500 的标题。截取结果中的每一行,response_bytes 的值都是 0,数据文件夹的 README 对此有记录。本书按截取结果原样保留这一列,因此它全部为 0。这些值留在数据中,因为表格式必须按原样存储它们。

表格式为文件增加了什么

最近一次修改见于版次 2026.11.10

任何读取该文件夹的程序,都会看到其中的每一个文件,而无从分辨哪些属于表的哪个状态。表格式用元数据来解决这一问题。表的元数据记录了表的模式(schema),以及表在其历史上每个时间点由哪些数据文件构成。对表的一次更改就是一次提交(commit),它一步写入新的元数据。这一步就是把表从一个状态推进到下一个状态的那个唯一的更改。

每种表格式都有自己的元数据,也有自己表述这些概念的用语。Iceberg 把提交之后的状态称为快照(snapshot)。Delta Lake 为其版本编号。DuckLake 把它的快照记录在一个目录文件(catalog file)中。本章把这三种格式都写一遍,这样你就能在每种格式中看到同样的行。

元数据存放的位置也各不相同。Iceberg 表保存一个元数据文件,其中指明当前快照。在 pyiceberg 所写入的格式版本 2 中,每个快照指向一个清单列表(manifest list),清单列表指明若干清单(manifest),每个清单指明数据文件及其统计信息。Iceberg 规范定义了其中的每一层。如 Delta Lake 协议所述,Delta Lake 表在其数据旁的 _delta_log 文件夹中保存一份有序的提交文件日志。DuckLake 表把元数据保存在你所挂载的目录文件中,并把数据文件写入该文件旁的一个文件夹。

六个小时的数据逐小时写入,每小时都写入全部三种格式,然后读回每张表并比较其总数。

rough-lakehouse.py Python 3.12.15 · deltalake 1.6.6 · duckdb 2.0.0 · pyarrow 26.0.1 · pyiceberg 0.12.0 通过
"""Load six hours into Iceberg, Delta Lake and DuckLake, then read each table back.The rows and views lines print each format's totals, and the assert after them checks that the three agree.The titles at the end come from the Iceberg table alone."""from lib.lakehouse import (    format_report,    load_three_formats,    new_warehouse,    print_rows,    safe_error,    sql_rows,    scan_arrow,)# page_title breaks ties in views, so titles with equal views always print in the same order.TOP_THREE = """    SELECT sum(views) AS views, page_title FROM pageviews    GROUP BY page_title ORDER BY views DESC, page_title LIMIT 3"""def main():    try:        with new_warehouse() as wh:            # range(6) is hours 0 to 5, the six hours of the cut, one commit per hour in each format.            iceberg, delta_path, lake = load_three_formats(wh, range(6))            report = format_report(wh, iceberg, delta_path, lake)            for name, (rows, views, files) in report.items():                print(f"{name} rows: {rows}")                print(f"{name} views: {views}")                print(f"{name} data files: {files}")            # A set of (rows, views) pairs has one entry only when all three formats agree.            totals = {(rows, views) for rows, views, _ in report.values()}            assert len(totals) == 1, "the three formats disagree on rows or views"            print("top three page titles over six hours (views, page_title):")            # pageviews names the Arrow table for the SQL; keep_order prints the rows in the SQL's order, not re-sorted.            print_rows(sql_rows(wh.con, TOP_THREE, keep_order=True, pageviews=scan_arrow(iceberg)), keep_order=True)    except Exception as exc:        print(safe_error(exc))        raise SystemExit(1)if __name__ == "__main__":    main()
输出python rough-lakehouse.py
iceberg rows: 2999
iceberg views: 1807299
iceberg data files: 6
delta rows: 2999
delta views: 1807299
delta data files: 6
ducklake rows: 2999
ducklake views: 1807299
ducklake data files: 6
top three page titles over six hours (views, page_title):
399885	Main_Page
102089	メインページ
54796	Wikipedia:Hauptseite

三种格式报告的行数相同,视图总数也相同,并且每种格式都为每个小时写了一个数据文件:

  • Iceberg:2999 行,1807299 次视图,6 个数据文件。
  • Delta Lake:2999 行,1807299 次视图,6 个数据文件。
  • DuckLake:2999 行,1807299 次视图,6 个数据文件。

如果三种格式的行数或视图总数出现任何差异,断言(assert)就会终止运行。随后输出列出这六个小时内浏览量最高的三个标题,仅从 Iceberg 表中读取:Main_Page、メインページ 和 Wikipedia:Hauptseite,分别是英文版、日文版和德文版的首页。

输出中不含快照 ID、版本号或文件名,因为这些内容每次运行都会变化;逐小时追加一节说明了快照改用什么方式来标记。

在你自己的机器上,DuckLake 需要额外的一步。在 DuckDB 中先运行 INSTALL ducklake,再运行 LOAD ducklake。本书的运行则改为从仓库中的一个文件加载 DuckDB 官方签名的 ducklake 扩展的副本,因此无需网络连接即可运行。DuckLake 还有一个会影响文件数量的内联默认设置:默认情况下,它把 10 行及以下的插入保存在其目录中,而不是保存在 Parquet 文件中。DuckLake 数据内联页面说明了这一默认值:“数据内联默认启用,行数限制为 10。”本示例把该限制设为 0,因此每次插入都会写入一个文件,文件数量在各章中的含义也就保持一致。

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

One load loop, three commit styles

最近一次修改见于版次 2026.11.7

The helper load_three_formats() in examples/lib/lakehouse.py holds the loop that rough-lakehouse calls. The loop writes each hour to all three tables, and each line that writes is one commit in one format:

for hour in hours:
    rows = read_cut_hour(hour)
    iceberg.append(rows)
    write_deltalake(delta_path, rows, mode="append")
    lake.register("hour", rows)
    lake.execute(f"INSERT INTO {DUCKLAKE_ALIAS}.{NAMESPACE}.{TABLE} SELECT * FROM hour")
    lake.unregister("hour")

read_cut_hour returns one hour of the cut as an Arrow table, with the same five columns in every format. The Iceberg append creates a snapshot. The Delta append creates a new version, and it creates the table on the first call, when the path does not yet hold one. The DuckLake insert writes a Parquet file and records a snapshot in the catalog file. The three calls differ, and the table each one writes is the same six hours of rows. The loop itself checks nothing. It runs the six loads in order and stops if one of them raises an error. The checks come after all six hours are in, when rough-lakehouse reads back each format's totals and compares them.

一次提交会指明表所包含的文件

最近一次修改见于版次 2026.11.10

Apache Iceberg 表规范把快照定义为表在某一时刻的状态,读取方借助快照找到表中的每一个数据文件。因此,快照做两件事。它指明表在该时刻所包含的数据文件,并记录产生该快照的操作。规范列出了各种操作类型。对于追加写入,操作类型为 append,Iceberg 规范对它的描述是“只添加了数据文件,没有删除任何文件”。

页面浏览量表可以把这一点说得更具体。你加载的每一个小时都会成为一个数据文件,每一次加载就是一次提交。第一次提交之后,表中只有第 00 小时的文件,没有别的文件。第二次提交之后,表中有两个文件,依此类推。数据文件从不被编辑。一次提交会添加文件,而新的快照则指明提交之后表所包含的文件。

表中数据文件的数量来自它的快照,而不是来自它的文件夹。rough-lakehouse 会打印各种格式为该表报告的数据文件数量。这个数字就是表自己所说的它包含的文件数,而列出文件夹内容时看到的数量可能与之不同。

**工作准则:**通过当前快照去询问表它包含什么,而不要通过列出它的文件夹来判断。文件夹里有写入方放进去的每一个文件,而快照说明其中哪些文件是表会读取的。

为什么通过 Python 库来讲授每种格式

最近一次修改见于版次 2026.11.10

rough-lakehouse 示例通过不同的库来写入每种格式,本节说明其中的原因。本书使用读者实际运行这两种格式时会用到的 Python 库来写入 Apache Iceberg 和 Delta Lake:pyiceberg,版本为 0.12.0;deltalake,版本为 1.6.6。DuckDB 的版本为 2.0.0,负责读取这些库写出的数据。它从一次扫描中把 Iceberg 表读取为 Arrow 表,并从 deltalake 运行的查询中把 Delta 表读取为 Arrow 表。DuckLake 是例外:DuckDB 通过其 ducklake 扩展自行运行 DuckLake,并挂载该表的目录文件。本书不使用 DuckDB 的 iceberg 或 delta 扩展,也没有任何示例运行它们。

格式 写入方 DuckDB 的读取方式
Apache Iceberg pyiceberg,0.12.0 从扫描得到的 Arrow 表
Delta Lake deltalake,1.6.6 从 deltalake 的 QueryBuilder 得到的 Arrow 表
DuckLake DuckDB 的 ducklake 扩展,运行于 DuckDB 2.0.0 使用 ATTACH 挂载目录文件

这一选择是有代价的。读者若通过 Spark 或 Trino 运行 Iceberg,会在那里接触到该格式的更多内容,其中的功能本书并未涉及。本书会指出这些地方,但不讲授这些引擎。其好处是活动部件更少:每种格式由它自己的库写入,再由 DuckDB 读取输出。每个库的版本都已固定,各章标明的是所固定的库版本,而不是该格式规范的版本。这些固定的版本记录在 examples/requirements.txt 中,该文件每行列出一个软件包及其唯一确切的版本。读者按该文件安装,得到的就是本章所用的那些库。请使用 examples/.python-version 所指明的 Python 版本,因为 pip 不会自行选择 Python 版本。

工作准则: 用你所固定版本的库来写入和读取每张表,并说明你的读取使用的是哪个版本。只有在你已经衡量过该库无法替你完成什么之后,才去使用引擎自带的扩展。

将三个小时的数据写入一张表

最近一次修改见于版次 2026.11.7

rough-lakehouse 示例展示了完整的循环,因此本节放慢节奏,只讲一张表。写入一个批次分为两步:先创建表,再把每个批次提交到表中。pageviews 表首先写入 00、01 和 02 三个小时的数据,所以每个小时对应一次提交。在前三个小时之后,该示例以同样的方式加载 03 到 05 时的数据。本节其余部分只讨论 Iceberg 表,因为它能展示的内容最多。

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

Create the table in a catalog

最近一次修改见于版次 2026.11.10

An Iceberg table needs a catalog, which is the registry that maps a table name to the table's current metadata. A Delta Lake table is found by its path, with no catalog, and a DuckLake table lives in its catalog file. The book uses pyiceberg's SQL catalog on SQLite for the Iceberg table. The catalog is one file, and the table's data files go in a warehouse folder beside it. The catalog holds pointers and metadata, not rows. Inside the catalog file, a table name such as wiki.pageviews_hourly maps to the location of the table's current metadata file. A commit writes a new metadata file and moves that mapping, so anyone who asks the catalog for the table gets the metadata that the most recent commit wrote. The helper new_warehouse() in examples/lib/lakehouse.py makes a temporary catalog and warehouse for each run, and removes them when the run ends. Because SQLite is a file and needs no server, the whole catalog runs on a laptop with the network off.

The table has five columns, and its schema says what each one holds:

Schema(
    NestedField(1, "hour_utc", TimestampType(), required=False),
    NestedField(2, "domain_code", StringType(), required=False),
    NestedField(3, "page_title", StringType(), required=False),
    NestedField(4, "views", LongType(), required=False),
    NestedField(5, "response_bytes", LongType(), required=False),
)

The hour_utc column holds a timestamp without a time zone, in UTC, and the two counts are 64-bit integers. The helper create_iceberg_table() creates the table in the catalog, unpartitioned. Chapter 4 adds a partition spec to it.

Working rule: Write the schema out in code, with the type each column really has, before the first commit. The types are then decided on purpose, and not by whichever batch happens to arrive first.

将每小时的数据作为一次提交追加

最近一次修改见于版次 2026.11.10

一次追加就是一次提交。下面的代码中,pyiceberg 创建表,依次追加 00、01 和 02 时的数据,然后按提交顺序列出各快照,以及每次提交的操作类型和新增的行数:

append-hours.py Python 3.12.15 · deltalake 1.6.6 · duckdb 2.0.0 · pyarrow 26.0.1 · pyiceberg 0.12.0 通过
"""Create the Iceberg table, append hours 00 to 02 as three commits, then repeat hour 00.The hour 00 point rests on the `snapshot 1 rows added` and `snapshot 2 rows added` lines, and the repeated-load point on the two `repeat of hour 00` lines."""from lib.lakehouse import (    create_iceberg_table,    iceberg_file_count,    new_warehouse,    read_cut_hour,    safe_error,    scan_arrow,    snapshot_labels,)def main():    try:        with new_warehouse() as wh:            table = create_iceberg_table(wh)            for hour in range(3):                table.append(read_cut_hour(hour))            # pyiceberg returns the snapshots in commit order, which the labels below depend on.            snapshots = table.snapshots()            # Snapshot IDs change from run to run, so each one prints as its position in commit order.            labels = snapshot_labels([snap.snapshot_id for snap in snapshots])            for snap in snapshots:                label = labels[snap.snapshot_id]                print(f"{label} operation: {snap.summary.operation.value}")                # The commit's own summary holds the rows it added, not a count of the whole table.                print(f"{label} rows added: {snap.summary['added-records']}")            print(f"rows in table: {scan_arrow(table).num_rows}")            # Counted from the current snapshot, not from the folder.            print(f"data files: {iceberg_file_count(table)}")            # Hour 00 again.            table.append(read_cut_hour(0))            repeat = table.current_snapshot()            print(f"repeat of hour 00 operation: {repeat.summary.operation.value}")            print(f"repeat of hour 00 rows added: {repeat.summary['added-records']}")            print(f"rows in table after the repeat: {scan_arrow(table).num_rows}")    except Exception as exc:        print(safe_error(exc))        raise SystemExit(1)if __name__ == "__main__":    main()
输出python append-hours.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
rows in table: 1499
data files: 3
repeat of hour 00 operation: append
repeat of hour 00 rows added: 499
rows in table after the repeat: 1998

00 时的数据少了一行:第一次提交新增 499 行,之后两次各新增 500 行。隐私检查从 00 时的数据中删除了一行,数据 README 对此有说明。三次提交之后,表中共有 1499 行,分布在 3 个数据文件中,每次提交对应一个文件。

每次提交还会写入一份摘要,而 pyiceberg 按提交顺序返回各快照,操作类型和新增行数正是由此得来。每次提交的操作类型都是 append,即规范所定义的追加操作。快照摘要是表对自身提交所做的记录,因此在计数出错时,应当首先查看它。

输出中的标签 snapshot 1、snapshot 2 和 snapshot 3 代替了快照 ID。Iceberg 的快照 ID 是一个长整数,规范要求其唯一,并且由 pyiceberg 在提交时选定,因此每次运行都会不同。把每个 ID 映射到它在提交顺序中的位置,可以使每次运行的输出保持一致。

工作准则: 每个可以命名的批次只做一次提交,并且在做下一次提交之前,把该次提交新增的行数与其数据源预期的行数进行比对。计数出错时,在对应提交仍是最近一次提交的时候最容易追查;在它之上又叠加了更多提交之后,追查就困难得多。

使用 DuckDB 查询该表

最近一次修改见于版次 2026.11.10

表建好之后,你想向它提问。DuckDB 运行 SQL,但 Iceberg 表并不是 DuckDB 的表。本书把该表的当前快照读成一个 Arrow 表(这是 pyiceberg 在扫描时返回的结果),再把这个 Arrow 表以名称 pageviews 注册到 DuckDB 中。随后 DuckDB 在其上运行普通的 SQL,无需任何 Iceberg 扩展。扫描是该表自身对某个快照的读取:它列出快照所指明的数据文件,读取这些文件,并只交出其中所含的行。DuckDB 看到的恰好就是这些行,快照未指明的内容一概看不到。

下一个示例把 00 时至 02 时的数据追加到一张新表中,并向它提两个问题:00 时哪五个标题的浏览量最高,以及这三个小时一共有多少次浏览。它还会把这个总数与扫描本身给出的求和结果进行核对。

scan-into-duckdb.py Python 3.12.15 · deltalake 1.6.6 · duckdb 2.0.0 · pyarrow 26.0.1 · pyiceberg 0.12.0 通过
"""Read the current Iceberg snapshot into DuckDB and check the totals.The point that DuckDB received every row rests on the two total views lines, which the assert compares."""from lib.lakehouse import (    create_iceberg_table,    new_warehouse,    print_rows,    read_cut_hour,    safe_error,    scan_arrow,    sql_rows,)def main():    try:        with new_warehouse() as wh:            table = create_iceberg_table(wh)            for hour in range(3):                table.append(read_cut_hour(hour))            # The current snapshot's rows as one Arrow table, sorted by every column.            arrow = scan_arrow(table)            top = sql_rows(                wh.con,                # hour_utc is UTC, so this is hour 00 of 3 June 2024; page_title breaks ties in views.                """                SELECT views, page_title FROM pageviews                WHERE hour_utc = TIMESTAMP '2024-06-03 00:00:00'                ORDER BY views DESC, page_title LIMIT 5                """,                # keep_order returns the rows in the order the SQL sorted them, not sorted again.                keep_order=True,                pageviews=arrow,            )            print("top five pages for hour 00 (views, page_title):")            print_rows(top, keep_order=True)            # One row with one column: the sum.            duckdb_total = sql_rows(wh.con, "SELECT sum(views) FROM pageviews", pageviews=arrow)[0][0]            # A second route to the same total, summed in Python from the scan's own rows.            pyiceberg_total = sum(arrow["views"].to_pylist())            print(f"total views in DuckDB: {duckdb_total}")            print(f"total views in the scan: {pyiceberg_total}")            assert duckdb_total == pyiceberg_total, "DuckDB and the scan disagree on the total"    except Exception as exc:        print(safe_error(exc))        raise SystemExit(1)if __name__ == "__main__":    main()
输出python scan-into-duckdb.py
top five pages for hour 00 (views, page_title):
61107	Main_Page
13791	メインページ
9492	Wikipedia:Hauptseite
7511	Wikipédia:Accueil_principal
3781	笹生優花
total views in DuckDB: 899451
total views in the scan: 899451

列表中是 00 时浏览量最高的五个标题,按浏览量从高到低排列,浏览量相同时以标题为次要排序依据,每一行依次显示浏览量、一个制表符和标题。DuckDB 中的总数为 899451 次浏览,与扫描自身的求和结果 899451 相同;如果两者出现差异,assert 会立即终止运行。

总数与扫描的求和结果一致,说明 DuckDB 收到了扫描返回的每一行。它并不检查这些行本身,也不检查前五名的查询。对总数的核对只需一行代码,因此每次修改查询之后都值得运行一次。把各行与其来源相核对,是后面各章的任务,那些章节会把每一次变更与其所源自的数据进行比较。

工作准则: 把 Iceberg 表读入 DuckDB 时,使用扫描所得的 Arrow 表,并将总数与扫描自身的求和结果相比较,以确认 DuckDB 收到了每一行。然后,再把每个查询的结果与某个可供比较的来源相核对。

生产环境中会出什么问题

最近一次修改见于版次 2026.11.10

第 1 章的路径很短,却掩盖了四个你在生产环境中一定会遇到的问题。

重复加载会再次添加相同的行。 追加操作只添加给定的数据文件,不删除任何文件,规范对该操作的定义即是如此。表中没有任何机制阻止第二份 00 点数据进入。携带第二份 00 点数据的提交,看起来与其他提交并无不同。append-hours 展示了这一点:重复提交的操作是 append,它添加了 499 行,与第一份的行数相同,随后表中共有 1998 行,全程没有任何报错。唯一能说明这次加载本应只运行一次的记录,就是你在加载之前写下的行数。第 5 章将说明如何更正被错误加载的行。

文件夹中的内容多于表中的内容。 统计仓库文件夹中的文件数,回答的是与统计表的文件数不同的问题。文件夹中保存着写入方放进去的每一个文件,而表中包含哪些文件则由快照来定义。统计文件夹中 Parquet 文件数量的工具,报告的是一个表从未承诺过的数字。第 6 章和第 7 章讨论表已不再引用的文件。

快照 ID、版本号和快照编号是不同种类的数字。 Iceberg 的 ID 是 64 位的值。Delta Lake 的版本号按提交顺序从 0 开始计数。DuckLake 同样为快照编号,并且每创建一个模式或一张表时都会记录一个快照,每插入行时也是如此。如果脚本保存了某一种格式的数字,却把它当作另一种格式的版本号来读取,读到的就是错误的状态。

DuckLake 的小规模插入不会写出文件。 默认情况下,DuckLake 会把 10 行及以下的插入保存在它的目录中,因此小规模插入之后文件数为零是预期的结果,而不是故障。本书中的 DuckLake 示例都把行数限制设为 0,只有第 10 章中的 ducklake-inlined-delete 例外,它保留默认值,以说明小规模删除不会写出删除文件。读者若把某个插入语句复制到自己的目录中,应当先了解这一默认值。

工作准则: 把每次提交应当添加的行数,写在产生该提交的加载操作旁边,并在每次加载之后,将这个数字与提交的摘要进行比对。表本身不会检查重复加载。预先写下的行数,才是能完成这项检查的手段。

本章做出的决定

最近一次修改见于版次 2026.11.8
  • 本章有三个示例。 rough-lakehouse 用三种格式完成整个结果,因此后续每一章只改动读者已经运行过的结果中的一个部分。另外两个示例 append-hours 和 scan-into-duckdb 每次提交一次数据,逐次提交地构建 Iceberg 表,并在 DuckDB 中读取。
  • 先写 00 至 02 点的数据,再写 03 至 05 点的数据。 Iceberg 示例写入三个小时的数据,粗略示例写入六个小时的数据。只有 rough-lakehouse 会汇总全部六个小时。
  • 未分区的表。 第 1 章创建表时不带分区规范。第 4 章会更改分区方式。pyiceberg-core 包与 pyiceberg 一起固定版本,因为第 4 章中的按日和按小时转换需要它。
  • 示例中关闭内联。 DuckLake 示例将 DATA_INLINING_ROW_LIMIT 设为 0,因此每次插入都会写入一个 Parquet 文件,文件数量在本书各处打印时含义一致。第 10 章的 ducklake-inlined-delete 保留默认值,因为它要说明的正是:此时一次小规模删除不会写出删除文件。
  • Delta 表只通过 deltalake 的 QueryBuilder 读取。 examples/lib/lakehouse.py 中的读取辅助函数走这条路径,之后每个读取 Delta 表的章节都使用同一个辅助函数。
  • 使用真实数据,而非替代数据。 本章的每个示例都读取 数据说明文件 所描述的、从六份公开转储中截取的数据。本书不为本章提供生成的数据。
  • Iceberg 目录使用 SQLite。 SQLite 文件不需要服务器,因此 Iceberg 示例可以在断网的笔记本电脑上运行。这些运行还会关闭 DuckDB 的扩展自动下载,因此需要网络的运行会直接失败,而不会去下载。
  • 用标签代替 ID。 打印出的 snapshot 1、snapshot 2 等用来代替快照 ID,因此每次运行的输出不会变化。

本章,在本版次中

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

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

引用本节

格式

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

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

本页内容

第 1 章,共 10 章: 构建第一张表:从头到尾

  1. 表格式为文件增加了什么
  2. One load loop, three commit styles
  3. 一次提交会指明表所包含的文件
  4. 为什么通过 Python 库来讲授每种格式
  5. 将三个小时的数据写入一张表
  6. Create the table in a catalog
  7. 将每小时的数据作为一次提交追加
  8. 使用 DuckDB 查询该表
  9. 生产环境中会出什么问题
  10. 本章做出的决定

返回顶部全部章节