fdl-cli 0.16.0__tar.gz → 0.17.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/CHANGELOG.md +47 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/PKG-INFO +2 -1
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/guides/building-a-host.md +1 -1
- fdl_cli-0.17.0/docs/guides/meta.ts +7 -0
- fdl_cli-0.17.0/docs/guides/reading-without-duckdb.md +41 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/guides/stores.md +1 -1
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/guides/building-a-host.md +1 -1
- fdl_cli-0.17.0/docs/ja/guides/meta.ts +7 -0
- fdl_cli-0.17.0/docs/ja/guides/reading-without-duckdb.md +41 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/guides/stores.md +1 -1
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/reference/cli.md +16 -6
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/reference/python.md +2 -2
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/spec/versions.md +6 -4
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/spec/writing.md +9 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/reference/cli.md +16 -6
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/reference/python.md +2 -2
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/spec/versions.md +6 -4
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/spec/writing.md +9 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/pyproject.toml +2 -1
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/src/fdl/catalog.py +143 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/src/fdl/cli.py +32 -21
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/src/fdl/dataset.py +91 -8
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/src/fdl/repo.py +38 -4
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/src/fdl/stores.py +65 -17
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/src/fdl/version.py +3 -3
- fdl_cli-0.17.0/tests/test_cli.py +170 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/tests/test_dataset.py +72 -4
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/tests/test_stores.py +35 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/uv.lock +3 -1
- fdl_cli-0.16.0/docs/guides/meta.ts +0 -7
- fdl_cli-0.16.0/docs/ja/guides/meta.ts +0 -7
- fdl_cli-0.16.0/tests/test_cli.py +0 -82
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/.github/workflows/docs.yml +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/.github/workflows/publish.yml +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/.github/workflows/release.yml +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/.gitignore +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/.node-version +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/.python-version +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/CLAUDE.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/CONTRIBUTING.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/LICENSE +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/README.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/blume.config.ts +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/concepts/meta.ts +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/concepts/repositories.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/concepts/versions-and-refs.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/concepts/working-catalogs.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/getting-started.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/guides/mirrors.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/guides/public-and-private.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/guides/serving-over-http.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/index.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/internals/ducklake-formats.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/internals/inside-a-repository.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/internals/meta.ts +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/concepts/meta.ts +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/concepts/repositories.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/concepts/versions-and-refs.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/concepts/working-catalogs.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/getting-started.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/guides/mirrors.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/guides/public-and-private.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/guides/serving-over-http.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/index.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/internals/ducklake-formats.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/internals/inside-a-repository.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/internals/meta.ts +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/reference/meta.ts +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/spec/data-files.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/spec/http.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/spec/index.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/spec/layout.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/spec/meta.ts +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/spec/reading.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/ja/spec/refs.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/reference/meta.ts +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/spec/data-files.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/spec/http.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/spec/index.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/spec/layout.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/spec/meta.ts +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/spec/reading.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/docs/spec/refs.md +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/package-lock.json +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/package.json +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/public/CNAME +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/src/fdl/__init__.py +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/src/fdl/layout.py +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/src/fdl/py.typed +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/src/fdl/refs.py +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/src/fdl/store.py +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/tests/http_repo.py +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/tests/test_http.py +0 -0
- {fdl_cli-0.16.0 → fdl_cli-0.17.0}/tests/test_repo.py +0 -0
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
## v0.17.0 (2026-11-03)
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
- Compare rows by value and check the description first
|
|
9
|
+
([`5d17ae5`](https://github.com/queria-io/fdl/commit/5d17ae57ee79af2cf02ffe7ffd12f72176ecbdc0))
|
|
10
|
+
|
|
11
|
+
hash() gives NULL and empty nested values the same hash, so rows are compared with EXCEPT ALL once
|
|
12
|
+
the counts match. The dataset.json check runs before reading rows, table names are escaped, and
|
|
13
|
+
the message no longer names the checked-out version as where the branch is.
|
|
14
|
+
|
|
15
|
+
- Count a table's rows as a reader would
|
|
16
|
+
([`ca8c020`](https://github.com/queria-io/fdl/commit/ca8c02095f11763adbfb72c556fe00da1c0488a9))
|
|
17
|
+
|
|
18
|
+
dataset.json took rows from ducklake_table_stats, which keeps counting rows that were deleted or
|
|
19
|
+
updated. Rows are now the live data files' records less what their delete files remove.
|
|
20
|
+
|
|
21
|
+
### Documentation
|
|
22
|
+
|
|
23
|
+
- Add a guide to reading without DuckDB
|
|
24
|
+
([`b61328e`](https://github.com/queria-io/fdl/commit/b61328ef8ac0585dd5d547f25c8e0511370d4f28))
|
|
25
|
+
|
|
26
|
+
### Features
|
|
27
|
+
|
|
28
|
+
- Credential helper in fdl's config, views in dataset.json, and annotations
|
|
29
|
+
([#30](https://github.com/queria-io/fdl/pull/30),
|
|
30
|
+
[`e082f2b`](https://github.com/queria-io/fdl/commit/e082f2b189bae5491da0863bd1c48b1519e920f0))
|
|
31
|
+
|
|
32
|
+
BREAKING CHANGE: tokens saved by `fdl login` are no longer read. Set `FDL_TOKEN` or a credential
|
|
33
|
+
helper in fdl's config. `dataset.json` and `version.json` write `annotations` instead of
|
|
34
|
+
`extensions`.
|
|
35
|
+
|
|
36
|
+
- Make no version when nothing changed
|
|
37
|
+
([`fc08213`](https://github.com/queria-io/fdl/commit/fc08213f60195a474238f22bb1a513d903f8182e))
|
|
38
|
+
|
|
39
|
+
fdl commit compares the working catalog's last snapshot with the parent's. No new snapshot, or the
|
|
40
|
+
same tables, views, columns and rows (as a multiset) and the same dataset.json, prints "Nothing to
|
|
41
|
+
commit" and leaves the branch. Files are compared first, so rows are read only for tables written
|
|
42
|
+
to new files. --allow-empty makes the version anyway; rows that cannot be read are taken as
|
|
43
|
+
changed.
|
|
44
|
+
|
|
45
|
+
### Breaking Changes
|
|
46
|
+
|
|
47
|
+
- Tokens saved by `fdl login` are no longer read. Set `FDL_TOKEN` or a credential helper in fdl's
|
|
48
|
+
config. `dataset.json` and `version.json` write `annotations` instead of `extensions`.
|
|
49
|
+
|
|
50
|
+
|
|
4
51
|
## v0.16.0 (2026-11-01)
|
|
5
52
|
|
|
6
53
|
### Documentation
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: fdl-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.17.0
|
|
4
4
|
Summary: Versions of a DuckLake catalog on object storage, kept the way Git keeps commits
|
|
5
5
|
Project-URL: Homepage, https://fdl.flo8s.com/
|
|
6
6
|
Project-URL: Documentation, https://fdl.flo8s.com/
|
|
@@ -12,6 +12,7 @@ License-File: LICENSE
|
|
|
12
12
|
Requires-Python: >=3.10
|
|
13
13
|
Requires-Dist: duckdb<2.0,>=1.5.2
|
|
14
14
|
Requires-Dist: pyyaml>=6.0
|
|
15
|
+
Requires-Dist: tomli>=1.1; python_version < '3.11'
|
|
15
16
|
Requires-Dist: typer>=0.15
|
|
16
17
|
Provides-Extra: s3
|
|
17
18
|
Requires-Dist: boto3>=1.36; extra == 's3'
|
|
@@ -43,7 +43,7 @@ A scheduled import or a form in a web app writes the same way a person does: che
|
|
|
43
43
|
What a host adds goes outside the fields FDL defines:
|
|
44
44
|
|
|
45
45
|
- extra files in a version folder (a preview), which readers ignore
|
|
46
|
-
- `
|
|
46
|
+
- `annotations` in `version.json` and `dataset.json`, keyed by the host's name
|
|
47
47
|
- its own ID for the dataset in `fdl.json`'s `id`, written at `init` and never changed
|
|
48
48
|
|
|
49
49
|
Access rules, approvals and billing stay in the host's own database. A repository copied off the host still reads correctly, with nothing in it that only the host understands.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Reading without DuckDB
|
|
3
|
+
description: Reading a table's Parquet files from JavaScript with files.json, in Workers, browsers and Node.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
A reader that cannot run DuckDB, such as a Cloudflare Worker or a web page, can still read a version: `files.json` lists each table's data files, and the Parquet files can be read by range. [`@queria-io/fdl-js`](https://www.npmjs.com/package/@queria-io/fdl-js) does this in JavaScript.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @queria-io/fdl-js
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { httpStore, open, openParquet, readWhere, tableFiles } from "@queria-io/fdl-js";
|
|
14
|
+
|
|
15
|
+
const store = httpStore("https://data.example.org/towns/");
|
|
16
|
+
const version = await open(store); // HEAD, a branch, a tag or a version ID
|
|
17
|
+
const [file] = tableFiles(version, "main.towns") ?? [];
|
|
18
|
+
const rows = await readWhere(await openParquet(store, file), "town_code", "131016");
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`readWhere` reads only the row groups whose min/max can hold the value, so a table sorted by the column it is read by costs a few small requests.
|
|
22
|
+
|
|
23
|
+
## What it can read
|
|
24
|
+
|
|
25
|
+
It follows [Reading](/spec/reading) up to the catalog and then reads `files.json` in its place:
|
|
26
|
+
|
|
27
|
+
- A version without `files.json` cannot be read. Writers before fdl-cli 0.16 did not make one
|
|
28
|
+
- A table whose files have `deletes`, or whose `renamed_columns` is `true`, is refused (see [files.json](/spec/versions#filesjson))
|
|
29
|
+
- A version with `expired.json` is refused
|
|
30
|
+
|
|
31
|
+
Tables written once and replaced whole by each version, as `CREATE OR REPLACE TABLE` does, have neither deletes nor renamed columns.
|
|
32
|
+
|
|
33
|
+
## Stores
|
|
34
|
+
|
|
35
|
+
| Store | Reads from |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| `httpStore(root)` | A URL, with `Range` requests |
|
|
38
|
+
| `r2Store(bucket, prefix)` | An R2 binding in a Cloudflare Worker |
|
|
39
|
+
| `fileStore(dir)` from `@queria-io/fdl-js/node` | A local folder |
|
|
40
|
+
|
|
41
|
+
Refs move, so keep the version a reader opened for a few minutes at most. Data files never change, so their Parquet footers can be cached forever.
|
|
@@ -3,7 +3,7 @@ title: Stores
|
|
|
3
3
|
description: Using a local folder, S3, R2 or another S3-compatible store as a repository, and what credentials the fdl command reads.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
A repository's URL picks the store. `s3://bucket/prefix/` is S3 or anything that speaks its API. `https://host/path/` is a host that takes [pushes over HTTP](/spec/http), with
|
|
6
|
+
A repository's URL picks the store. `s3://bucket/prefix/` is S3 or anything that speaks its API. `https://host/path/` is a host that takes [pushes over HTTP](/spec/http), with a token from `FDL_TOKEN` or a credential helper ([Tokens for HTTP](/reference/cli#tokens-for-http)). Anything else is a folder on disk.
|
|
7
7
|
|
|
8
8
|
## A folder
|
|
9
9
|
|
|
@@ -43,7 +43,7 @@ refs.write(store, "refs/heads/main", version.id, expected=current)
|
|
|
43
43
|
ホストが足すものは、FDL が決めた項目の外に置きます。
|
|
44
44
|
|
|
45
45
|
- バージョンのフォルダに置く追加のファイル(プレビューなど)。読み手は無視する
|
|
46
|
-
- `version.json` と `dataset.json` の `
|
|
46
|
+
- `version.json` と `dataset.json` の `annotations`。ホストの名前をキーにする
|
|
47
47
|
- `fdl.json` の `id` に書く、ホスト側のデータセットの ID。`init` のときに書き、変えない
|
|
48
48
|
|
|
49
49
|
権限、承認、課金はホスト自身のデータベースに置きます。ホストから持ち出したリポジトリも、ホストにしか分からないものを含まずに正しく読めます。
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: DuckDB を使わずに読む
|
|
3
|
+
description: files.json を使い、表の Parquet ファイルを JavaScript で読む方法。Workers・ブラウザ・Node で動きます。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Cloudflare Worker や Web ページのように DuckDB を動かせない読み手も、バージョンを読めます。`files.json` に表ごとのデータファイルが並んでいるので、Parquet ファイルを範囲指定で読めば済みます。JavaScript では [`@queria-io/fdl-js`](https://www.npmjs.com/package/@queria-io/fdl-js) がこれを行います。
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @queria-io/fdl-js
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { httpStore, open, openParquet, readWhere, tableFiles } from "@queria-io/fdl-js";
|
|
14
|
+
|
|
15
|
+
const store = httpStore("https://data.example.org/towns/");
|
|
16
|
+
const version = await open(store); // HEAD、ブランチ、タグ、バージョン ID
|
|
17
|
+
const [file] = tableFiles(version, "main.towns") ?? [];
|
|
18
|
+
const rows = await readWhere(await openParquet(store, file), "town_code", "131016");
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`readWhere` は、min/max にその値が入りうる行グループだけを読みます。読むときの列で並べた表なら、小さな読み取り数回で済みます。
|
|
22
|
+
|
|
23
|
+
## 読めるもの
|
|
24
|
+
|
|
25
|
+
[読み方](/ja/spec/reading)の手順にカタログの手前まで従い、カタログの代わりに `files.json` を読みます。
|
|
26
|
+
|
|
27
|
+
- `files.json` の無いバージョンは読めません。fdl-cli 0.16 より前の書き手は作りません
|
|
28
|
+
- ファイルに `deletes` がある表と、`renamed_columns` が `true` の表は断ります([files.json](/ja/spec/versions#filesjson) を参照)
|
|
29
|
+
- `expired.json` のあるバージョンは断ります
|
|
30
|
+
|
|
31
|
+
`CREATE OR REPLACE TABLE` のように、バージョンごとに表をまるごと作り直す書き方なら、削除も列の改名も起きません。
|
|
32
|
+
|
|
33
|
+
## 置き場
|
|
34
|
+
|
|
35
|
+
| 置き場 | 読む先 |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| `httpStore(root)` | URL(`Range` リクエスト) |
|
|
38
|
+
| `r2Store(bucket, prefix)` | Cloudflare Worker の R2 バインディング |
|
|
39
|
+
| `@queria-io/fdl-js/node` の `fileStore(dir)` | 手元のフォルダ |
|
|
40
|
+
|
|
41
|
+
ref は動くので、開いたバージョンを覚えておくのは数分までにしてください。データファイルは変わらないので、Parquet のフッターはずっとキャッシュしてかまいません。
|
|
@@ -3,7 +3,7 @@ title: 置き場
|
|
|
3
3
|
description: フォルダ、S3、R2、ほかの S3 互換ストレージをリポジトリの置き場にする方法と、fdl コマンドが読む認証情報。
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
リポジトリの URL で置き場が決まります。`s3://bucket/prefix/` は S3 か、S3 の API を話すストレージです。`https://host/path/` は [HTTP で push を受け付ける](/ja/spec/http)ホストで、`
|
|
6
|
+
リポジトリの URL で置き場が決まります。`s3://bucket/prefix/` は S3 か、S3 の API を話すストレージです。`https://host/path/` は [HTTP で push を受け付ける](/ja/spec/http)ホストで、`FDL_TOKEN` か credential helper のトークンを使います([HTTP のトークン](/ja/reference/cli#http-のトークン))。それ以外はディスク上のフォルダです。
|
|
7
7
|
|
|
8
8
|
## フォルダ
|
|
9
9
|
|
|
@@ -3,15 +3,23 @@ title: コマンドライン
|
|
|
3
3
|
description: fdl のコマンド、オプション、断られるとき。
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
`<remote>` はリポジトリで、`s3://bucket/prefix/`、`https://host/path/`、またはフォルダです。S3 の認証情報とエンドポイントは boto3 の通常の場所から読みます(`AWS_*` の環境変数、R2 などの S3 互換ストレージには `AWS_ENDPOINT_URL`)。HTTP のリポジトリには、`
|
|
6
|
+
`<remote>` はリポジトリで、`s3://bucket/prefix/`、`https://host/path/`、またはフォルダです。S3 の認証情報とエンドポイントは boto3 の通常の場所から読みます(`AWS_*` の環境変数、R2 などの S3 互換ストレージには `AWS_ENDPOINT_URL`)。HTTP のリポジトリには、`FDL_TOKEN` か credential helper でトークンを渡します([HTTP のトークン](#http-のトークン))。
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## HTTP のトークン
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
fdl はトークンを保存せず、ログインのコマンドもありません。HTTP のリポジトリには、次の順に見つけたトークンを `Authorization: Bearer` で送ります。
|
|
11
|
+
|
|
12
|
+
1. `FDL_TOKEN` があればそれ(CI 向け)
|
|
13
|
+
2. 無ければ、fdl の設定でリポジトリの URL に設定した credential helper が答えたもの。helper が無ければトークンを送りません
|
|
14
|
+
|
|
15
|
+
設定は `~/.config/fdl/config.toml`(`$XDG_CONFIG_HOME/fdl/config.toml`、または `FDL_CONFIG` で指定したファイル)です。helper は URL の前方一致で設定し、パスが一番長く一致したものを使います。
|
|
16
|
+
|
|
17
|
+
```toml
|
|
18
|
+
[credential."https://data.example.org"]
|
|
19
|
+
helper = "example-cli fdl-credential"
|
|
12
20
|
```
|
|
13
21
|
|
|
14
|
-
|
|
22
|
+
fdl は `<helper> get` を実行し、標準入力に `protocol=`・`host=`・`path=` の行と空行を渡して、出力の `password=` の行を読みます。何も出さないか、エラーで終わったら、トークンは無いものとします。トークンの保存と helper の書き込みは、ホストの側の道具が行います。
|
|
15
23
|
|
|
16
24
|
## fdl init
|
|
17
25
|
|
|
@@ -36,13 +44,15 @@ HTTP のリポジトリでは、新しいデータファイルは `<working.sqli
|
|
|
36
44
|
## fdl commit
|
|
37
45
|
|
|
38
46
|
```bash
|
|
39
|
-
fdl commit <working.sqlite> -m "What changed" --author alice [--dataset dataset.json]
|
|
47
|
+
fdl commit <working.sqlite> -m "What changed" --author alice [--dataset dataset.json] [--allow-empty]
|
|
40
48
|
```
|
|
41
49
|
|
|
42
50
|
作業カタログを、チェックアウトしたバージョンを親とする新しいバージョンに固め、アップロードし、条件付きでブランチを動かします。ブランチ、新しいバージョン ID、`seq` を表示します。
|
|
43
51
|
|
|
44
52
|
バージョンはそれぞれ `dataset.json`([バージョン](/ja/spec/versions#datasetjson)を参照)で説明します。`--dataset` で指定したファイルか、なければいまのディレクトリの `dataset.json` か `dataset.yml` から読みます。そのフォルダより下にある `*.table.yml`(または `*.table.json`)のテーブルの説明も合わせて読みます。隠しフォルダの中は読みません。コマンドはそれをカタログと照らし合わせ、列の型、行数、カタログのコメントを書き足します。
|
|
45
53
|
|
|
54
|
+
親と同じ中身になるとき([変更がないとき](/ja/spec/writing#変更がないとき))は `Nothing to commit` と表示し、ブランチを動かさずに終了コード 0 で終わります。同じ行を新しいファイルに書き直しただけの作り直しも、変更なしとみなします。`--allow-empty` を付けると、それでもバージョンを作ります。行を読めず判定できないときは、警告を出してバージョンを作ります。
|
|
55
|
+
|
|
46
56
|
次のときは断られます。
|
|
47
57
|
|
|
48
58
|
- `dataset.json` が無いとき、カタログに無い表や列を説明しているとき、形式が決めていないキーがあるとき
|
|
@@ -49,13 +49,13 @@ repo.checkout(store, working, *, ref="HEAD") -> Version | None
|
|
|
49
49
|
`ref` が指すバージョンから、`working` に作業カタログを作ります。そのバージョンを返し、最初のバージョンの前は `None` を返します。
|
|
50
50
|
|
|
51
51
|
```python
|
|
52
|
-
repo.commit(working, out_dir, *, parent, data_path, author, message, inputs=(),
|
|
52
|
+
repo.commit(working, out_dir, *, parent, data_path, author, message, inputs=(), annotations=None, dataset=None) -> Version
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
作業カタログを `out_dir/<ID>/` に固めます。`dataset`(読み込んだ `dataset.json`)をカタログと照らし合わせ、カタログから書き足します。`data_path` は `repo.data_url(store)` です。アップロードはしません。
|
|
56
56
|
|
|
57
57
|
```python
|
|
58
|
-
repo.record(frozen, out_dir, *, parent, author, message, inputs=(),
|
|
58
|
+
repo.record(frozen, out_dir, *, parent, author, message, inputs=(), annotations=None, dataset=None) -> Version
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
固め終えたカタログからバージョンを作ります。自分でカタログを固める書き手向けです。
|
|
@@ -59,7 +59,7 @@ description: バージョン ID、version.json の項目、固めたカタログ
|
|
|
59
59
|
"url": "https://example.org/population-2025.csv"
|
|
60
60
|
}
|
|
61
61
|
],
|
|
62
|
-
"
|
|
62
|
+
"annotations": {}
|
|
63
63
|
}
|
|
64
64
|
```
|
|
65
65
|
|
|
@@ -78,7 +78,7 @@ description: バージョン ID、version.json の項目、固めたカタログ
|
|
|
78
78
|
| `files` | may | カタログの隣の `files.json` を書いたときの、そのファイル名、大きさ、sha256([files.json](#filesjson)) |
|
|
79
79
|
| `changes` | may | 親との列の違い。`breaking` は、親に向けて書いた SQL が失敗しうるか(列の削除・改名・作り直し) |
|
|
80
80
|
| `inputs` | may | 使った元のファイル。`source_id` の付け方は書き手が決める |
|
|
81
|
-
| `
|
|
81
|
+
| `annotations` | may | 形式が解釈しない情報。読む側(ホストやツール)の名前をキーにする |
|
|
82
82
|
|
|
83
83
|
読み手は、知らない項目を無視しなければなりません。
|
|
84
84
|
|
|
@@ -175,7 +175,7 @@ DuckLake を使わずに Parquet ファイルを読む読み手は、`deletes`
|
|
|
175
175
|
]
|
|
176
176
|
}
|
|
177
177
|
],
|
|
178
|
-
"
|
|
178
|
+
"annotations": {}
|
|
179
179
|
}
|
|
180
180
|
```
|
|
181
181
|
|
|
@@ -183,8 +183,10 @@ DuckLake を使わずに Parquet ファイルを読む読み手は、`deletes`
|
|
|
183
183
|
- 書き手は説明を YAML(`dataset.yml`)で持ってもよく、テーブルごとに別のファイル(`<name>.table.yml`、`tables` の 1 項目)に分けてもよい。バージョンには常に説明全体が 1 つの JSON で入る
|
|
184
184
|
- `licenses` の各要素は SPDX の識別子か、`id` に書き手が足したいもの(`spdx`・`url`・`title`)を添えたオブジェクト
|
|
185
185
|
- `tables` には、カタログの最後のスナップショットにある表をすべて並べる。書き手が説明しなかった表は、書き手のツールがカタログから分かることで足す。カタログに無い表や列を説明していたら断る
|
|
186
|
+
- カタログのビューは表のあとに `"kind": "view"` を付けて並べ、`sql` はカタログのものを入れる。カタログはビューの列を記録しないので、ビューの `fields` は書き手が書いたままで、`type`・`nullable`・`rows` を持たない。表には `kind` を付けない
|
|
186
187
|
- カタログから取るもの: 表ごとの `rows`、列ごとの `type`(DuckLake の型名)と `nullable`。書き手が `description` を書かなかったところには、カタログのコメント(`COMMENT ON`)を使う
|
|
187
|
-
-
|
|
188
|
+
- この仕様が決めていないキーは断る。形式が解釈しない情報は、最上位・表・列それぞれの `annotations` に、読む側の名前をキーにして置く。書き手は書かれたまま残す
|
|
189
|
+
- `annotations` という名前になる前のバージョンは、同じものを `extensions` に持つ。読み手は `extensions` を `annotations` として読む
|
|
188
190
|
- ライセンスや出典に書いたことは書き手の主張で、ホストは公開する前に確かめてよい
|
|
189
191
|
|
|
190
192
|
## ほかの形式のカタログ
|
|
@@ -27,6 +27,15 @@ description: チェックアウト、コミット、push。作業カタログ、
|
|
|
27
27
|
- 固めたカタログの `data_path` を `<root><data_dir>` の絶対 URL にする
|
|
28
28
|
- 絶対パスで記録されたデータファイルや、`data_dir` の外のデータファイルがあれば断る
|
|
29
29
|
|
|
30
|
+
## 変更がないとき
|
|
31
|
+
|
|
32
|
+
書き手は、親と同じ中身のバージョンを作らないようにするべきです。Git が親と同じ tree のコミットを作らないのと同じです。次のどちらかなら、親と同じ中身です。
|
|
33
|
+
|
|
34
|
+
- 最後のスナップショットが親のもの(`ducklake.snapshot_id`)と同じ
|
|
35
|
+
- 同じ表とビューがあり、どの表も列の名前と型が同じで、行が同じ(重複を数え、順番は問わない)。さらに `dataset.json` の sha256 が親と同じ
|
|
36
|
+
|
|
37
|
+
同じ入力から作り直した表は新しいデータファイルに書かれるので、ファイルやカタログのバイトを比べても判定できません。書き手はまずファイルを比べ、ファイルが違う表だけ行を読みます。行を読めないときはバージョンを作ります。頼まれたときは、`git commit --allow-empty` と同じく、変更がなくても作ってかまいません。
|
|
38
|
+
|
|
30
39
|
## 書き込みの順番
|
|
31
40
|
|
|
32
41
|
1. データファイル
|
|
@@ -3,15 +3,23 @@ title: Command line
|
|
|
3
3
|
description: The fdl commands, their options and when they refuse.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
`<remote>` is a repository: `s3://bucket/prefix/`, `https://host/path/` or a folder. Credentials and the endpoint for S3 come from boto3's usual places (`AWS_*` environment variables, `AWS_ENDPOINT_URL` for R2 and other S3-compatible stores). A repository over HTTP takes
|
|
6
|
+
`<remote>` is a repository: `s3://bucket/prefix/`, `https://host/path/` or a folder. Credentials and the endpoint for S3 come from boto3's usual places (`AWS_*` environment variables, `AWS_ENDPOINT_URL` for R2 and other S3-compatible stores). A repository over HTTP takes a token from `FDL_TOKEN` or a credential helper (see [Tokens for HTTP](#tokens-for-http)).
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Tokens for HTTP
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
fdl keeps no tokens and has no login. For a repository over HTTP it sends, as `Authorization: Bearer`:
|
|
11
|
+
|
|
12
|
+
1. `FDL_TOKEN`, when set (for CI)
|
|
13
|
+
2. Otherwise what the credential helper set for the repository's URL in fdl's config answers. With no helper set, fdl sends no token
|
|
14
|
+
|
|
15
|
+
The config is `~/.config/fdl/config.toml` (`$XDG_CONFIG_HOME/fdl/config.toml`, or the file `FDL_CONFIG` names). A helper is set per URL prefix; the one with the longest matching path wins:
|
|
16
|
+
|
|
17
|
+
```toml
|
|
18
|
+
[credential."https://data.example.org"]
|
|
19
|
+
helper = "example-cli fdl-credential"
|
|
12
20
|
```
|
|
13
21
|
|
|
14
|
-
|
|
22
|
+
fdl runs `<helper> get`, writes `protocol=`, `host=` and `path=` lines and a blank line to its stdin, and reads the `password=` line it prints. A helper that prints nothing, or exits with an error, means no token. The host's own tool stores the token and writes its helper here.
|
|
15
23
|
|
|
16
24
|
## fdl init
|
|
17
25
|
|
|
@@ -36,13 +44,15 @@ Refused when the version is past retention.
|
|
|
36
44
|
## fdl commit
|
|
37
45
|
|
|
38
46
|
```bash
|
|
39
|
-
fdl commit <working.sqlite> -m "What changed" --author alice [--dataset dataset.json]
|
|
47
|
+
fdl commit <working.sqlite> -m "What changed" --author alice [--dataset dataset.json] [--allow-empty]
|
|
40
48
|
```
|
|
41
49
|
|
|
42
50
|
Freezes the working catalog into a new version whose parent is the version it was checked out at, uploads it, and moves the branch on condition. It prints the branch, the new version ID and its `seq`.
|
|
43
51
|
|
|
44
52
|
Every version is described by a `dataset.json` (see [Versions](/spec/versions#datasetjson)), read from `--dataset` or else from `dataset.json` or `dataset.yml` in the current directory. Tables described in `*.table.yml` (or `*.table.json`) files below that folder are added to it; hidden folders are skipped. The command checks it against the catalog and fills in the column types, row counts and catalog comments.
|
|
45
53
|
|
|
54
|
+
When the version would hold what its parent holds (see [When nothing changed](/spec/writing#when-nothing-changed)), it prints `Nothing to commit`, leaves the branch where it is and exits 0. A rebuild that writes the same rows to new files counts as unchanged. `--allow-empty` makes the version anyway. If the rows cannot be read to tell, it warns and makes the version.
|
|
55
|
+
|
|
46
56
|
Refused when:
|
|
47
57
|
|
|
48
58
|
- there is no `dataset.json`, or it describes a table or column the catalog lacks, or has keys the format does not define
|
|
@@ -49,13 +49,13 @@ repo.checkout(store, working, *, ref="HEAD") -> Version | None
|
|
|
49
49
|
Make a working catalog at `working` from the version `ref` holds. Returns that version, or `None` before the first one.
|
|
50
50
|
|
|
51
51
|
```python
|
|
52
|
-
repo.commit(working, out_dir, *, parent, data_path, author, message, inputs=(),
|
|
52
|
+
repo.commit(working, out_dir, *, parent, data_path, author, message, inputs=(), annotations=None, dataset=None) -> Version
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
Freeze the working catalog into `out_dir/<ID>/`, with `dataset` (the parsed `dataset.json`) checked against the catalog and completed from it. `data_path` is `repo.data_url(store)`. Nothing is uploaded.
|
|
56
56
|
|
|
57
57
|
```python
|
|
58
|
-
repo.record(frozen, out_dir, *, parent, author, message, inputs=(),
|
|
58
|
+
repo.record(frozen, out_dir, *, parent, author, message, inputs=(), annotations=None, dataset=None) -> Version
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
Make a version around a catalog that is already frozen, for a writer that freezes it itself.
|
|
@@ -59,7 +59,7 @@ A version is the files under `versions/<version ID>/`. They must not change once
|
|
|
59
59
|
"url": "https://example.org/population-2025.csv"
|
|
60
60
|
}
|
|
61
61
|
],
|
|
62
|
-
"
|
|
62
|
+
"annotations": {}
|
|
63
63
|
}
|
|
64
64
|
```
|
|
65
65
|
|
|
@@ -78,7 +78,7 @@ A version is the files under `versions/<version ID>/`. They must not change once
|
|
|
78
78
|
| `files` | may | The `files.json` beside the catalog, if written: its file name, size and sha256 ([files.json](#filesjson)) |
|
|
79
79
|
| `changes` | may | Column differences from the parent. `breaking` says whether SQL written for the parent may fail (a column dropped, renamed or recreated) |
|
|
80
80
|
| `inputs` | may | Source files used. How `source_id` is assigned is up to the writer |
|
|
81
|
-
| `
|
|
81
|
+
| `annotations` | may | What the format does not interpret, keyed by the name of whoever reads it (a host, a tool) |
|
|
82
82
|
|
|
83
83
|
A reader must ignore fields it does not know.
|
|
84
84
|
|
|
@@ -175,7 +175,7 @@ The writer describes; the writer's tool checks the description against the froze
|
|
|
175
175
|
]
|
|
176
176
|
}
|
|
177
177
|
],
|
|
178
|
-
"
|
|
178
|
+
"annotations": {}
|
|
179
179
|
}
|
|
180
180
|
```
|
|
181
181
|
|
|
@@ -183,8 +183,10 @@ The writer describes; the writer's tool checks the description against the froze
|
|
|
183
183
|
- A writer may keep its description as YAML (`dataset.yml`), and may keep each table in its own file (`<name>.table.yml`, one entry of `tables`). The version always holds the whole description as one JSON
|
|
184
184
|
- Each of `licenses` is an SPDX identifier, or an object with `id` and what the writer wants to add (`spdx`, `url`, `title`)
|
|
185
185
|
- `tables` lists every table of the catalog's last snapshot. The writer's tool adds the tables the writer did not describe, with what the catalog knows of them, and refuses a described table or column the catalog lacks
|
|
186
|
+
- A view of the catalog is listed after the tables with `"kind": "view"` and its `sql` from the catalog. The catalog records no columns for a view, so its `fields` are the writer's, without `type`, `nullable` or `rows`. `kind` is left out for a table
|
|
186
187
|
- From the catalog: each table's `rows`, and each field's `type` (DuckLake's type name) and `nullable`. Comments in the catalog (`COMMENT ON`) are used where the writer gave no `description`
|
|
187
|
-
- Keys this specification does not define are refused.
|
|
188
|
+
- Keys this specification does not define are refused. What the format does not interpret goes under `annotations`, keyed by the name of whoever reads it, at the top, in a table or in a field. Writers keep it as written
|
|
189
|
+
- Versions written before `annotations` had its name carry it as `extensions`. A reader reads `extensions` as `annotations`
|
|
188
190
|
- What a license or a source says is the writer's claim. A host may check it before it publishes
|
|
189
191
|
|
|
190
192
|
## Catalogs in other formats
|
|
@@ -27,6 +27,15 @@ When freezing, a writer must:
|
|
|
27
27
|
- set the frozen catalog's `data_path` to the absolute URL of `<root><data_dir>`
|
|
28
28
|
- refuse if any data file is recorded with an absolute path, or outside `data_dir`
|
|
29
29
|
|
|
30
|
+
## When nothing changed
|
|
31
|
+
|
|
32
|
+
A writer should not make a version that holds what its parent holds, as Git makes no commit when the tree is the parent's. A version holds the same as its parent when:
|
|
33
|
+
|
|
34
|
+
- the last snapshot is the parent's (`ducklake.snapshot_id`), or
|
|
35
|
+
- the same tables and views are there, each table with the same columns and types and the same rows, counted as a multiset (order does not matter), and `dataset.json` has the parent's sha256
|
|
36
|
+
|
|
37
|
+
A table rebuilt from the same input is written to new data files, so comparing files or catalog bytes is not enough. A writer compares the files first and reads the rows only of tables whose files differ. A writer that cannot read the rows makes the version. A writer may make one anyway when asked, as `git commit --allow-empty` does.
|
|
38
|
+
|
|
30
39
|
## Order of writes
|
|
31
40
|
|
|
32
41
|
1. Data files
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "fdl-cli"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.17.0"
|
|
4
4
|
description = "Versions of a DuckLake catalog on object storage, kept the way Git keeps commits"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -9,6 +9,7 @@ authors = [{ name = "flo8s" }]
|
|
|
9
9
|
dependencies = [
|
|
10
10
|
"duckdb>=1.5.2,<2.0",
|
|
11
11
|
"pyyaml>=6.0",
|
|
12
|
+
"tomli>=1.1; python_version < '3.11'",
|
|
12
13
|
"typer>=0.15",
|
|
13
14
|
]
|
|
14
15
|
|
|
@@ -623,3 +623,146 @@ def snapshot_range(catalog_path: Path, after: int | None) -> tuple[int, int]:
|
|
|
623
623
|
if last is None:
|
|
624
624
|
raise CatalogError(f"{catalog_path} holds no snapshot")
|
|
625
625
|
return (first if first is not None else last, last)
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
# -- whether anything changed --------------------------------------------------
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
def _working_data_path(working: Path) -> str:
|
|
632
|
+
import sqlite3
|
|
633
|
+
|
|
634
|
+
con = sqlite3.connect(f"file:{working}?mode=ro", uri=True)
|
|
635
|
+
try:
|
|
636
|
+
row = con.execute(
|
|
637
|
+
"SELECT value FROM ducklake_metadata WHERE key = ? AND scope IS NULL",
|
|
638
|
+
(DATA_PATH_KEY,),
|
|
639
|
+
).fetchone()
|
|
640
|
+
except sqlite3.Error as exc:
|
|
641
|
+
raise CatalogError(f"{working} is not a working catalog: {exc}") from exc
|
|
642
|
+
finally:
|
|
643
|
+
con.close()
|
|
644
|
+
if not row:
|
|
645
|
+
raise CatalogError(f"{working} records no data path")
|
|
646
|
+
return row[0]
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
def last_snapshot(working: Path) -> int:
|
|
650
|
+
"""The newest snapshot of a working catalog."""
|
|
651
|
+
import sqlite3
|
|
652
|
+
|
|
653
|
+
con = sqlite3.connect(f"file:{working}?mode=ro", uri=True)
|
|
654
|
+
try:
|
|
655
|
+
return con.execute("SELECT max(snapshot_id) FROM ducklake_snapshot").fetchone()[0]
|
|
656
|
+
except sqlite3.Error as exc:
|
|
657
|
+
raise CatalogError(f"{working} is not a working catalog: {exc}") from exc
|
|
658
|
+
finally:
|
|
659
|
+
con.close()
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
def same_contents(working: Path, since: int) -> bool:
|
|
663
|
+
"""Whether the working catalog's last snapshot holds what snapshot ``since`` held.
|
|
664
|
+
|
|
665
|
+
The same tables and views, each table with the same columns and the same
|
|
666
|
+
rows, in any order. A table rebuilt from the same input is written to new
|
|
667
|
+
files, so files are compared first and rows only where the files differ.
|
|
668
|
+
Reading those rows needs the data files: one the writer cannot read raises
|
|
669
|
+
`CatalogError`.
|
|
670
|
+
"""
|
|
671
|
+
import duckdb
|
|
672
|
+
|
|
673
|
+
working = Path(working)
|
|
674
|
+
last = last_snapshot(working)
|
|
675
|
+
if last == since:
|
|
676
|
+
return True
|
|
677
|
+
con = duckdb.connect()
|
|
678
|
+
try:
|
|
679
|
+
for statement in attach_sql(
|
|
680
|
+
working, alias="lake", data_path=_working_data_path(working), read_only=True
|
|
681
|
+
):
|
|
682
|
+
if statement:
|
|
683
|
+
con.execute(statement)
|
|
684
|
+
meta = "__ducklake_metadata_lake.main"
|
|
685
|
+
|
|
686
|
+
def live(alias: str) -> str:
|
|
687
|
+
return f"{alias}.begin_snapshot <= $s AND ({alias}.end_snapshot IS NULL OR {alias}.end_snapshot > $s)"
|
|
688
|
+
|
|
689
|
+
def tables(snapshot: int) -> dict[tuple[str, str], int]:
|
|
690
|
+
rows = con.execute(
|
|
691
|
+
f"""
|
|
692
|
+
SELECT s.schema_name, t.table_name, t.table_id
|
|
693
|
+
FROM {meta}.ducklake_table t JOIN {meta}.ducklake_schema s USING (schema_id)
|
|
694
|
+
WHERE {live('t')} AND {live('s')}
|
|
695
|
+
""",
|
|
696
|
+
{"s": snapshot},
|
|
697
|
+
).fetchall()
|
|
698
|
+
return {(schema, name): table_id for schema, name, table_id in rows}
|
|
699
|
+
|
|
700
|
+
def views(snapshot: int) -> set[tuple]:
|
|
701
|
+
return set(
|
|
702
|
+
con.execute(
|
|
703
|
+
f"""
|
|
704
|
+
SELECT s.schema_name, v.view_name, v.dialect, v.sql
|
|
705
|
+
FROM {meta}.ducklake_view v JOIN {meta}.ducklake_schema s USING (schema_id)
|
|
706
|
+
WHERE {live('v')} AND {live('s')}
|
|
707
|
+
""",
|
|
708
|
+
{"s": snapshot},
|
|
709
|
+
).fetchall()
|
|
710
|
+
)
|
|
711
|
+
|
|
712
|
+
def files(table_id: int, snapshot: int) -> set[tuple]:
|
|
713
|
+
return set(
|
|
714
|
+
con.execute(
|
|
715
|
+
f"""
|
|
716
|
+
SELECT d.data_file_id, x.delete_file_id
|
|
717
|
+
FROM {meta}.ducklake_data_file d
|
|
718
|
+
LEFT JOIN {meta}.ducklake_delete_file x
|
|
719
|
+
ON x.data_file_id = d.data_file_id AND {live('x')}
|
|
720
|
+
WHERE d.table_id = $t AND {live('d')}
|
|
721
|
+
""",
|
|
722
|
+
{"s": snapshot, "t": table_id},
|
|
723
|
+
).fetchall()
|
|
724
|
+
)
|
|
725
|
+
|
|
726
|
+
def shape(name: str, snapshot: int) -> list[tuple]:
|
|
727
|
+
return con.execute(
|
|
728
|
+
f"SELECT column_name, column_type FROM "
|
|
729
|
+
f"(DESCRIBE SELECT * FROM {name} AT (VERSION => {int(snapshot)}))"
|
|
730
|
+
).fetchall()
|
|
731
|
+
|
|
732
|
+
def same_rows(name: str) -> bool:
|
|
733
|
+
# Compared as values, not hashes: DuckDB's hash() gives a NULL
|
|
734
|
+
# list, struct or map the hash of an empty one, so a sum of row
|
|
735
|
+
# hashes misses rows that trade the two. With the counts equal,
|
|
736
|
+
# nothing left by EXCEPT ALL means the same multiset.
|
|
737
|
+
old = f"SELECT * FROM {name} AT (VERSION => {int(since)})"
|
|
738
|
+
new = f"SELECT * FROM {name} AT (VERSION => {int(last)})"
|
|
739
|
+
counts = con.execute(
|
|
740
|
+
f"SELECT (SELECT count(*) FROM ({old})), (SELECT count(*) FROM ({new}))"
|
|
741
|
+
).fetchone()
|
|
742
|
+
if counts[0] != counts[1]:
|
|
743
|
+
return False
|
|
744
|
+
return bool(con.execute(f"SELECT NOT EXISTS ({old} EXCEPT ALL {new})").fetchone()[0])
|
|
745
|
+
|
|
746
|
+
def quoted(identifier: str) -> str:
|
|
747
|
+
return '"' + identifier.replace('"', '""') + '"'
|
|
748
|
+
|
|
749
|
+
before, after = tables(since), tables(last)
|
|
750
|
+
if before.keys() != after.keys() or views(since) != views(last):
|
|
751
|
+
return False
|
|
752
|
+
for (schema, table), table_id in after.items():
|
|
753
|
+
name = f"lake.{quoted(schema)}.{quoted(table)}"
|
|
754
|
+
if shape(name, since) != shape(name, last):
|
|
755
|
+
return False
|
|
756
|
+
if before[(schema, table)] == table_id and files(table_id, since) == files(
|
|
757
|
+
table_id, last
|
|
758
|
+
):
|
|
759
|
+
continue
|
|
760
|
+
if not same_rows(name):
|
|
761
|
+
return False
|
|
762
|
+
return True
|
|
763
|
+
except CatalogError:
|
|
764
|
+
raise
|
|
765
|
+
except Exception as exc: # noqa: BLE001 - duckdb raises several types
|
|
766
|
+
raise CatalogError(f"could not compare {working} with snapshot {since}: {exc}") from exc
|
|
767
|
+
finally:
|
|
768
|
+
con.close()
|