毎時の追記が残す小さなファイルを圧縮する

読了まで約35 分分、9 節 節の 3 例 例。

第2026.11.10版 2026年11月20日時点で例が通過 39 例中 39 例が合格 変更点

AIによる翻訳。英語版は人による検証済みである。 当社の書籍の作り方

英語版の書籍(版2026.11.10)から翻訳した。 原文を読む

この章では、テーブルが保持するデータファイルの数を数える方法、Delta Lake、DuckLake、Iceberg でそれらをより少ないファイルにまとめる方法、そして各マージがディスク上に何を残すかを説明する。問題は、ロードから始まる。最初の章の pageviews テーブルは、3 つのフォーマットのそれぞれに 1 時間に 1 回ロードされる。各ロードは 1 つのコミットであり、各コミットは独自のデータファイルを書き出す。データファイルとは、テーブルの行を保持する Parquet ファイルである。

毎時の追記は小さなファイルを残す

最終変更:版2026.11.10

行を追記するコミットは、そのたびに少なくとも1つのデータファイルを書き出す。1時間に1回ロードを受け取るテーブルには、1日に24個のデータファイルができ、それぞれが1時間分の行を持つ。ここではおよそ500行である。クエリは、フィルタでスキップされないすべてのファイルを開き、1回開くごとに時間がかかる。テーブルのメタデータも、一覧に載せるファイルが増えるたびに大きくなる。どの形式も、現在のバージョンが使うすべてのデータファイルの記録を保持するからである。したがって、小さなファイルが多数あると、行の総数が少なくても、読み取りとプランニングのコストが増える。

注視すべき数値はファイル数である。ファイル数は時間とともに増えていく。ファイルサイズも重要だが、バイト単位のサイズは実行のたびに変わるため、本書ではファイルサイズを出力しない。ファイル数を数えることは、コンパクションを確かめる誠実な方法でもある。コンパクションの前後で行は同じであるべきであり、ファイル数は減るはずである。

対処法はコンパクションである。コンパクションは、多数の小さなデータファイルを、より少数の大きなファイルに書き直す。コンパクションも他のコミットと同じコミットである。置き換え後のファイルを書き出し、メタデータに載せ、古いファイルは、テーブルの履歴がそれらを参照している間はディスク上に残す。古いファイルをいつ削除できるかは第7章で扱う。

3つの形式には、それぞれ異なる呼び出しがある。次の表は、この章が作る6つの毎時ファイルに対して、各形式が何をしたかを示す。

形式 呼び出し 前のファイル数 後のファイル数
Delta Lake optimize.compact() 6 1
DuckLake ducklake_merge_adjacent_files 6 1
Iceberg table.overwrite(table.scan().to_arrow_batch_reader()) 6 1

表の数値は、各例が出力したものである。各例は、切り出した6時間分を1時間ごとに1回ずつ、パーティションのないテーブルにロードするため、どの形式も1回のロードにつき1つのデータファイルから始まる。第4章のパーティション付きテーブルでは挙動が異なる。対応している形式では、パーティションごとに個別にコンパクションされるからである。この章ではテーブルをパーティションなしにして、ファイル数の原因を1つに絞っている。

DuckLakeの数値には、意味を持たせるためにもう1つ設定が必要である。ここでの毎時のロードは1回あたり約500行で、第1章が示すインライン化の行数上限を超えるため、デフォルトのままでも結局ファイルとして書き出される。それでもDuckLakeの例は、その章で説明した設定であるインライン化を無効にしてアタッチする。ファイル数が、1回のロードがたまたま何行になるかに左右されないようにするためである。

実践ルール: 各ロードの後にテーブルごとのデータファイル数を数え、ファイルが到着する速度と、読み手が必要とするファイルサイズからコンパクションの頻度を決める。1時間に1回のロードでは、テーブルごとに1日24個のファイルができるため、まずは毎日のコンパクションが妥当である。これは経験則であり、測定結果ではない。コンパクションの頻度を上げるのは、自分の環境の読み取り時間やファイル数から必要だと分かった場合に限る。

optimize.compact() による圧縮

最終変更:版2026.11.10

Delta Lake は、上の表にある三つの形式のうち最初のものである。その Python ライブラリ deltalake は、圧縮をテーブルの optimize プロパティに置いている。compact() メソッドは、テーブルの小さなデータファイルをより大きなファイルに書き直し、メトリクスの辞書を返す。この辞書には、追加されたファイルと削除されたファイルの数、およびサイズに関するフィールドが入っているが、サイズのフィールドは本書では出力しない。

六時間分のデータを、一時間ごとに一回ずつ追記して Delta テーブルに読み込む。次に、テーブルが一覧に挙げるファイルを数え、圧縮を行い、もう一度数える。どちらの数も、現在のバージョンについてテーブル自身が持つファイル一覧から得たものである。

file-counts-before-after.py Python 3.12.15 · deltalake 1.6.6 · duckdb 2.0.0 · pyarrow 26.0.1 · pyiceberg 0.12.0 合格
"""Load six hourly appends into a Delta Lake table, compact it, and count its files and rows before and after.The point rests on the file-count lines, and on the row count read from the version before the compaction."""from deltalake import DeltaTable, write_deltalakefrom lib.lakehouse import delta_file_count, new_warehouse, read_cut_hour, read_deltadef main():    with new_warehouse() as wh:        path = str(wh.root / "delta" / "pageviews_hourly")        for hour in range(6):            write_deltalake(path, read_cut_hour(hour), mode="append")        table = DeltaTable(path)        version_before = table.version()  # the version the read at the end goes back to        print(f"files before compaction: {delta_file_count(table)}")  # counts the files this version lists, not the disk        metrics = table.optimize.compact()  # a dict; numFilesAdded and numFilesRemoved are the two counts printed below        print(f"files added by compaction: {metrics['numFilesAdded']}")        print(f"files removed by compaction: {metrics['numFilesRemoved']}")        table = DeltaTable(path)        print(f"files after compaction: {delta_file_count(table)}")        print(f"rows after compaction: {len(read_delta(path))}")        before = read_delta(path, version=version_before)        print(f"rows at the version before compaction: {len(before)}")        parquet = list((wh.root / "delta").rglob("*.parquet"))  # every file on disk, including ones the current version dropped        print(f"parquet files on disk after compaction: {len(parquet)}")if __name__ == "__main__":    main()
出力python file-counts-before-after.py
files before compaction: 6
files added by compaction: 1
files removed by compaction: 6
files after compaction: 1
rows after compaction: 2999
rows at the version before compaction: 2999
parquet files on disk after compaction: 7

圧縮が変えるのはファイルであり、行ではない。テーブルが一覧に挙げるデータファイルは、呼び出しの前が 6 個、後が 1 個である。現在のバージョンを読むと 2999 行が返り、行は以前と同じで、ファイルの数だけが少なくなっている。

呼び出しが返すメトリクスは、同じ変化をライブラリの側から数えたもので、追加が 1 ファイル、削除が 6 ファイルである。

圧縮は古いファイルを削除しなかった。呼び出し前のバージョンで読むと、テーブルは今も 2999 行をすべて返す。そのバージョンが古いファイルを指しているためである。呼び出しの後、ディレクトリには 7 個の Parquet ファイルがあり、その内訳は古い六個と新しい一個である。どの保持バージョンからも使われていないファイルを削除するのは、vacuum と呼ばれる別の手順であり、7章で示す。その手順が実行されるまでは、圧縮はディスク上のファイルを減らすのではなく、増やす。

ここでの Delta の読み取りは、本書のすべての Delta の読み取りと同様に、ライブラリのクエリビルダーを通して行う。ここで注目するのはファイル数なので、行は件数だけで比較する。

実践ルール: Delta テーブルは、最初の節で示したスケジュール(一時間ごとのロードなら毎日)で圧縮し、その後でファイル数を確認する。何かを削除する前に、7章の保持規則を読む。圧縮はコミットを一つ加え、古いファイルをそのまま残すので、vacuum が実行されるまでは使用する記憶容量が増える。

DuckLakeにおけるコンパクション

DuckLakeには、SQLから呼び出すメンテナンス関数としてコンパクションが用意されている。この関数は1回の呼び出しで実行でき、統合した各テーブルについて、何を行ったかを示す行を返す。次の部分では、この関数と、関数が処理を行わない1つのケースについて説明する。

この部分はまだ翻訳されていないため、英語で表示している。

Merge adjacent files

最終変更:版2026.11.10

ducklake_merge_adjacent_files takes a catalog, and optionally a table name and a schema name, which the call needs when the table is not in the main schema. Without a table name it merges the files of every table. The DuckLake documentation says the function can "merge multiple Parquet files into a single Parquet file that holds data inserted by multiple snapshots" (DuckLake documentation: Merge Files). The merge also works without expiring snapshots, and it does not delete the old files at once. Both points matter for the rest of this chapter. Because the merge does not expire snapshots, every older snapshot still refers to the old files.

What does the merge leave for a snapshot from before it? The example below reads one. It attaches the catalog with inlining off, inserts the six hours one insert each, and calls the merge once. The table lives in the wiki schema, so the call names it. It reads the snapshot number before the merge, so it can read the table as it was at that point.

compact-ducklake.py Python 3.12.15 · deltalake 1.6.6 · duckdb 2.0.0 · pyarrow 26.0.1 · pyiceberg 0.12.0 合格
"""Merge six DuckLake data files, then read a snapshot from before the merge to see what the merge left behind.The point rests on the data-file lines, and on the row count read at the earlier snapshot."""from lib.lakehouse import (    DUCKLAKE_ALIAS,    NAMESPACE,    TABLE,    connect_ducklake,    create_ducklake_table,    ducklake_file_count,    new_warehouse,    read_cut_hour,)def main():    with new_warehouse() as wh:        lake = connect_ducklake(wh.con)        create_ducklake_table(lake, wh.root)  # inlining is off here, so every insert writes a data file        table = f"{DUCKLAKE_ALIAS}.{NAMESPACE}.{TABLE}"        for hour in range(6):            lake.register("hour", read_cut_hour(hour))            lake.execute(f"INSERT INTO {table} SELECT * FROM hour")            lake.unregister("hour")        # the newest snapshot before the merge, which the read at the end goes back to        before = lake.execute(f"SELECT max(snapshot_id) FROM ducklake_snapshots('{DUCKLAKE_ALIAS}')").fetchall()[0][0]        print(f"data files before merge: {ducklake_file_count(lake, DUCKLAKE_ALIAS, TABLE)}")        # the schema is named because the table is not in main; the call returns one row        result = lake.execute(            f"CALL ducklake_merge_adjacent_files('{DUCKLAKE_ALIAS}', '{TABLE}', schema => '{NAMESPACE}')"        ).fetchall()        # the row's fields: schema, table, files merged, files created        print(f"files merged: {result[0][2]}")        print(f"files created: {result[0][3]}")        print(f"data files after merge: {ducklake_file_count(lake, DUCKLAKE_ALIAS, TABLE)}")        print(f"rows after merge: {lake.execute(f'SELECT count(*) FROM {table}').fetchall()[0][0]}")        old = lake.execute(f"SELECT count(*) FROM {table} AT (VERSION => {before})").fetchall()[0][0]        print(f"rows at the snapshot before merge: {old}")        # every Parquet file under the data path, including the ones the table no longer lists        parquet = list((wh.root / f"{DUCKLAKE_ALIAS}_data").rglob("*.parquet"))        print(f"parquet files on disk after merge: {len(parquet)}")if __name__ == "__main__":    main()
出力python compact-ducklake.py
data files before merge: 6
files merged: 6
files created: 1
data files after merge: 1
rows after merge: 2999
rows at the snapshot before merge: 2999
parquet files on disk after merge: 7

The merge's result row says what it did: 6 files merged into 1 file. The table lists 1 data file afterwards, down from 6. The row also names the schema and the table, so a merge aimed at the wrong table shows before anything else is read.

The old snapshot still reads. A count taken at the snapshot before the merge returns 2999 rows, the same count the current table returns. The Parquet files on disk number 7, the six the inserts wrote and the one the merge wrote. The six old files stay on disk until the cleanup in chapter 7 removes them.

The merge skips a file that has a delete file attached. A delete file is a record of deleted rows, which DuckLake writes instead of rewriting the data file when rows are deleted. Chapter 5 writes delete files in DuckLake, so this limit applies there. The DuckLake documentation names ducklake_rewrite_data_files as the call that rewrites those files, and its default delete_threshold is 0.95, which rewrites a file only when that share of its rows is deleted (DuckLake documentation: Rewrite Files with Deletes). The default is a value you should choose for your own data, not accept without a look.

Working rule: Run ducklake_merge_adjacent_files after the inserts for a period are done, and read the file count it returns. A merge does not remove deleted rows, so for a table with delete files, call ducklake_rewrite_data_files with a delete_threshold that you chose for that table, and check the result.

テーブルを書き換えてコンパクションする

最終変更:版2026.11.7

固定されたバージョンの pyiceberg では、Iceberg のコンパクションは上書きによる書き換えとして行う。この章ではテーブル全体を書き換える。これはパーティション化されていないテーブルの場合である。スキャンでテーブルを読み、そのスキャンが返す行でテーブルを上書きする。上書きは、その行を置き換え用のデータファイルとして書き出し、古いファイルは現在のスナップショットから外れる。これは本書における Iceberg 唯一のコンパクションの手段であり、存在しない呼び出しを補うための回避策である。その理由は次の部で説明する。

書き換えの良否は、その後に何が残るかで判断する。以下の確認では、6 回の追加と 1 回の上書きを行った後のテーブルのファイルと行を読み、あわせて書き換え前のスナップショットも読む。

iceberg-rewrite-by-overwrite.py Python 3.12.15 · deltalake 1.6.6 · duckdb 2.0.0 · pyarrow 26.0.1 · pyiceberg 0.12.0 合格
"""Rewrite an unpartitioned Iceberg table by overwriting it with its own scan, then check its data files, its snapshothistory and a snapshot from before the rewrite. The point rests on the data-file lines and on the row count of snapshot 6."""from lib.lakehouse import (    create_iceberg_table,    iceberg_file_count,    new_warehouse,    read_cut_hour,    scan_arrow,    snapshot_labels,)def main():    with new_warehouse() as wh:        table = create_iceberg_table(wh)        for hour in range(6):            table.append(read_cut_hour(hour))        last_append = table.current_snapshot().snapshot_id  # the snapshot after the sixth append        print(f"data files before rewrite: {iceberg_file_count(table)}")        # a batch reader, so the rows are not all read into one Arrow table first        table.overwrite(table.scan().to_arrow_batch_reader())        print(f"data files after rewrite: {iceberg_file_count(table)}")        print(f"rows after rewrite: {len(scan_arrow(table))}")        # sorted by sequence number, which puts the snapshots in commit order        snapshots = sorted(table.snapshots(), key=lambda snapshot: snapshot.sequence_number)        # labels count up in commit order, so the sixth append is snapshot 6        labels = snapshot_labels([snapshot.snapshot_id for snapshot in snapshots])        operations = [snapshot.summary.operation.value for snapshot in snapshots]        print("snapshot operations in order: " + ", ".join(operations))        print(f"{labels[last_append]} rows: {len(scan_arrow(table, snapshot_id=last_append))}")        # every Parquet file in the warehouse, including those that only older snapshots still hold        parquet = list((wh.root / "warehouse").rglob("*.parquet"))        print(f"parquet files on disk after rewrite: {len(parquet)}")if __name__ == "__main__":    main()
出力python iceberg-rewrite-by-overwrite.py
data files before rewrite: 6
data files after rewrite: 1
rows after rewrite: 2999
snapshot operations in order: append, append, append, append, append, append, delete, append
snapshot 6 rows: 2999
parquet files on disk after rewrite: 7

データファイルは 6 個から 1 個に減り、テーブルの読み手は、同じ方法で読んで、より少ないファイルから同じ 2999 行を得る。書き換えは 1 回のコミットであり、スナップショットが 2 つ追加される。コミット順の操作は、6 回の追加に続く delete と append である。delete のスナップショットはテーブルからすべてのデータファイルを取り除き、append のスナップショットは書き換えられたファイルを追加する。現在のスナップショットが動くのは 1 回だけなので、どの読み手にもテーブルが空に見えることはないが、履歴には両方のスナップショットが残る。このようにファイル全体を削除する動作は、第 5 章で Iceberg の削除について説明したコピーオンライトの動作である。

書き換え前のスナップショットは、今もすべての行を読み出せる。ラベルはコミット順にスナップショットを数え上げているので、スナップショット 6 は書き換え前の最後の追加である。そのスナップショットで読むと、テーブルは今も 2999 行を返す。ディスク上の Parquet ファイルは 7 個であり、これは古い 6 個のファイルと書き換えで書かれた 1 個である。古いスナップショットを期限切れにする方法と、それらがまだ保持しているものを数える方法は、第 7 章で扱う。

実践ルール: Iceberg のテーブルを上書きで書き換えるのは、書き換えの間にそのテーブルへコミットする他のライターがいない場合に限る。パーティション化されていないテーブルでは、この例のようにスキャンをストリームで読む。パーティション化されたテーブルでは、スキャンを to_arrow() で読まなければならないため、スキャン全体がジョブのメモリに収まる必要がある。ストリームのリーダーは 1 回しか読めない。コミットが失敗した場合は、次の試行のために新しいリーダーを作る。書き換えのたびにファイル数と行数を確認し、結果を確認し終えるまでは書き換え前のスナップショットを残しておく。

この部分はまだ翻訳されていないため、英語で表示している。

Why pyiceberg has no rewrite call

最終変更:版2026.11.7

The pyiceberg API documentation lists overwrite among its table operations (PyIceberg API documentation). Its one sentence on compaction is in the note on fast appends, and it is about metadata: the page says that metadata compaction is planned. It says nothing about data files. Its only maintenance call is expire_snapshots, which chapter 7 covers. The source of pyiceberg 0.12.0, in pyiceberg/table/__init__.py, has no method that compacts or rewrites data files. Its write operations are append, overwrite, delete, upsert, dynamic_partition_overwrite and add_files. Every one except add_files writes data files, and add_files registers files that already exist and writes none. dynamic_partition_overwrite, and overwrite with an overwrite_filter, can replace the rows of one partition, so a partitioned table can be rewritten one partition at a time. A compaction is therefore a rewrite built from those operations.

The rewrite has a memory cost that the file counts do not show, and the way the scan is read decides it. table.scan().to_arrow() reads the whole current snapshot into one Arrow table in memory before the overwrite starts. The rewrite above passes table.scan().to_arrow_batch_reader() instead, and pyiceberg documents that a streamed overwrite is microbatched by write.target-file-size-bytes, so its memory stays bounded. Streaming works only on unpartitioned tables, which this chapter uses. A partitioned table has to be read with to_arrow(), so memory must hold all of its rows at once. The bound is pyiceberg's documented behaviour, not a measurement made here.

The rewrite also reads every file and writes every file, including the ones that were already large enough. A table whose files are mostly the right size gets no benefit from it. This is the reason to use it only when the file count has grown and the table fits in memory.

Working rule: Check the pyiceberg release notes at each upgrade for a compaction call, because a call would replace the overwrite rewrite in this chapter. Until then, treat the overwrite as a batch job, run it when no other writer is committing, and for a partitioned table budget memory for the whole scan.

圧縮のたびに結果を確認してから信頼する

最終変更:版2026.11.7

この章の例は、全体で四つの値を出力する。この四つは、どの圧縮を実行した後でも確認すべき項目である。一つ目は、テーブル自身のファイル一覧から得たファイル数である。二つ目は、現在のバージョンの行数であり、圧縮前の行数と一致していなければならない。三つ目は、圧縮前のバージョンまたはスナップショットの行数であり、これは引き続き読み取れなければならない。四つ目は、テーブルの場所にある Parquet ファイルの数であり、ファイル数を、クリーンアップを待っている古いファイルの数だけ上回るべきである。

最初の二つの確認は、圧縮が主張どおりに動作し、行を一切変更しなかったことを示す。三つ目の確認は、履歴が引き続き機能することを示す。これは、古いバージョンを固定して参照するどの読み手にとっても重要である。四つ目の確認は、圧縮がディスク上に何を残したかを示す。一つ目と四つ目は異なる場所から得られる値であり、本書の例は両方を出力する。これにより、不一致が一つの数値に隠れず、出力の中に見えるようになる。四つ目の数は、DuckLake のテーブルでは 7、Iceberg のテーブルでは 7 であり、いずれも一覧に残っているファイルより一つ多い。最初の三つの確認に通った圧縮は、このような数について問題があるわけではない。余分なファイルは、第7章で片付ける状態である。

各ライブラリには、それぞれ独自のファイル一覧がある。Delta の例は現在のバージョンの URI を数え、DuckLake の例はカタログにテーブルのファイルを問い合わせ、Iceberg の例はテーブルのファイル検査のエントリを数える。この三つの数はメタデータから読み取られるため、第二の情報源であるディレクトリ一覧には依存しない。メタデータから読み取った数とディレクトリ一覧の数が食い違うときは、次の圧縮を実行する前に手を止め、原因を突き止める。

確認に失敗したときは、ジョブを停止し、テーブルをそのままにしておく。最初の圧縮を直すために二度目の圧縮を実行してはならない。実行のたびにコミットが生まれ、二度目の実行は履歴を読みにくくするからである。テーブルの履歴をコミット順に読み、行数を変えたコミットを見つけ、そこから判断する。障害が起きる前の状態は、テーブルがまだそれを保持しているうちのほうが調べやすい。

実践ルール: 圧縮のたびに、行数を圧縮前の行数と比較し、圧縮前のバージョンを読み取ること。行数を変える圧縮は障害であり、そのテーブルで他の処理を実行する前に修正しなければならない。

本番環境で起こる問題

最終変更:版2026.11.10

ストレージは縮む前にまず増える。 この章のどの圧縮(compaction)も、置き換え用のファイルを書き出し、古いファイルをディスク上に残す。件数がそれを示している。DuckLake のマージ後、テーブルが列挙するデータファイルは 1 個だが、ディスク上には Parquet ファイルが 7 個ある。Iceberg の書き換え後も、テーブルが列挙するのは 1 個だが、ディスク上には 7 個ある。期限切れ処理の手順を伴わずに圧縮を実行すると、ストレージ費用は以前より高くなる。期限切れ処理とクリーンアップは圧縮と合わせて計画し、両方を終えたあとでディスクを計測すること。兆候は、テーブルの行数とファイル数が変わらないまま、実行のたびにディスクが増えていくことである。

削除された行は、書き換えで処理されるまで残る。 マージの節が示すとおり、DuckLake のマージは削除ファイルを持つファイルをすべてスキップする。削除を含むテーブルをマージだけで処理すると、それらのファイルはそのまま残る。そうしたファイルには、自分で決めたしきい値を指定して ducklake_rewrite_data_files を使うこと。マージだけでは削除された行がファイル内に残っていることが分からないため、前後で行数を計測する。マージのたびに、削除ファイルを持つファイルの数が変わらないままであれば注意が必要である。

並行する書き込み側は、ここでは検証していない。 この章の例は書き込み側を一度に一つだけ動かしており、コミットと重なる圧縮は検証していない。重なりの検証は自分のエンジンで行い、その検証が済むまでは、どの書き込み側もコミットしない時間帯に圧縮を予定すること。3 つのうち Iceberg の書き換えは、テーブル全体を読んでから書き戻すため、最も影響を受けやすい。重なりに失敗した場合は、書き込み側か圧縮側のエラーとして現れるが、本書ではそれを再現していない。

頻度が高すぎるとコミットが増え、低すぎると読み取りが遅くなる。 圧縮は 1 回ごとにコミットとなり、コミットのたびにメタデータが増える。ロードのたびに圧縮すると、ロード 1 回あたりのコミット数は 2 倍になる。月に 1 回の圧縮では、小さなファイルが 1 か月分たまる。前者はロードより速く増えるコミット数として、後者はファイル数とともに上がるクエリ時間として現れる。これは自分のテーブルで計測して判断するトレードオフであり、例が証明する規則ではない。

件数の目標はサイズの目標ではない。 非常に大きなファイルが 1 つあると、読み取り側の並列作業は減り、ファイル単位の統計によって除外できるファイルも減る。これらの例はファイル数を目標としており、ファイルサイズは出力していない。これは読み取り側についての判断であり、目標は読み手のクエリ時間によって決めるべきである。非常に大きな 1 つのファイルを生んだ圧縮のあとでクエリ時間が悪化したなら、それが警告である。

実践ルール: 圧縮は、期限切れ処理およびクリーンアップと切り離さず、並べてスケジュールする。実行のたびに確認の節の 4 つの確認を行い、行数が変わった場合、または並行する書き込み側が失敗した場合は、スケジュールを止める。

この章で下した判断

最終変更:版2026.11.7
  • 各フォーマットでは、それぞれのライブラリの呼び出しを使う。この章の例には、Iceberg や Delta Lake 向けの DuckDB 拡張を使うものはない。読み取りと書き込みは Python ライブラリと DuckDB の DuckLake サポートを通して行うため、各カウントは、そのファイルを書き込んだツールから得られる。
  • DuckLake の例では、データインライン化を無効にしてアタッチする。インライン化を無効にすると、ロードのサイズにかかわらず、すべてのカウントがファイル数になる。
  • ファイル数は、各ライブラリ自身のファイル一覧から得る。ディスク上の Parquet ファイル数は二つ目の確認であり、ファイルサイズを出力するものはない。
  • テーブルはパーティション化していないため、各カウントの原因は一つ、すなわちロードの回数である。パーティション化したテーブルの場合は、パーティションエボリューションの章に譲る。
  • pyiceberg 0.12.0 にはコンパクションの呼び出しがないため、Iceberg のコンパクションは上書きによる書き換えとして行う。この書き換えではスキャンをストリーミングで処理する。これは pyiceberg がパーティション化していないテーブルに対して認めている方法である。この章では、この回避策と、パーティション化したテーブルで残るメモリコストを明示する。
  • この章では、スナップショットの期限切れ処理もファイルの削除も行わない。第7章ではその両方を行い、この章のカウントがその作業の出発点となる。
  • 実践ルールに示すスケジュールは出発点である。最適な間隔は、テーブルのファイルが届く速さと、読み取り側が求めるファイルの大きさによって決まるため、本書は最適な間隔を主張しない。

この版における本章

第2026.11.10版2026年11月20日時点で例が通過この章の3 例件のうち3件が合格

英語版の書籍(版2026.11.10)から翻訳した。

この節を引用する

形式

いずれの形式も、本訳書が従う英語版の書籍を出典として示す。

いずれの形式もこの版を明示している。そのリンクは現行版を開き、節の見出しには本文が最後に変更された日付が示される。アクセス日と取得日は、これを開いた日である。

このページの内容

全10章中の第6章: 毎時の追記が残す小さなファイルを圧縮する

  1. 毎時の追記は小さなファイルを残す
  2. optimize.compact() による圧縮
  3. DuckLakeにおけるコンパクション
  4. Merge adjacent files
  5. テーブルを書き換えてコンパクションする
  6. Why pyiceberg has no rewrite call
  7. 圧縮のたびに結果を確認してから信頼する
  8. 本番環境で起こる問題
  9. この章で下した判断

ページの先頭に戻るすべての章