> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Datasets

A dataset is an Apache Iceberg table in a REST catalog whose versions Bijection
keeps: which snapshot is each version, which version is current, who holds which
version, and when an unheld version retires. Your engines (Spark, Trino, DuckDB,
PyIceberg) read and write the table in the catalog. Bijection writes no data
files and runs no computation; it keeps the versions and governs the reads.
Datasets has no SQL authoring syntax: a derived dataset is a
[pipeline](https://docs.bijection.com/transforms/pipelines.md) output written as a
[typed relation](https://docs.bijection.com/sql/relations.md), and a table's partitioning, write order
and properties are its declared [layout](https://docs.bijection.com/datasets/catalogs.md#declare-a-table-layout).

The `@bijectionhq/datasets-app` app owns datasets. You mount it by calling
`datasets(options)` at a path of your tree. Only its receivers talk to the
catalog and only its functions write a version or a hold. Your code calls its
functions with `ctx.call` and submits to its targets with `ctx.submit`.

| Idea | Meaning |
| - | - |
| **Catalog** | An Iceberg REST catalog the mount declares by name (`lake` by default): the hosting cell's managed catalog (Lakekeeper) or your own, chosen by [placement](https://docs.bijection.com/operate/placement.md). |
| **Dataset** | One table in one catalog, with a read lease length. |
| **Version** | One tagged snapshot of the table (`bijection-v<n>`). |
| **Current** | The version `main` points at; readers get it by default. |
| **Hold** | A holder's claim that keeps a version readable until it ends. |
| **Read lease** | A read of one version that lasts at most the dataset's lease length. |
| **Sync** | A table of your app kept continuously in a dataset from its feed. |

> [!NOTE]
>
> The Datasets app has not yet run on a deployment.

## Mount the app

```ts bijection/app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app, query, t, table } from "@bijectionhq/bijection";
import { datasets } from "@bijectionhq/datasets-app";

// Your CI records which candidate digests passed its checks.
export const checks = table(
  { dataset: t.string, digest: t.string, passed: t.boolean },
  { key: ["dataset", "digest"] },
);

// The publication gate: may this candidate snapshot become a version?
export const candidatePassed = query(
  { args: { dataset: t.string, snapshot: t.string, digest: t.string } },
  async (ctx, { dataset, digest }) => (await ctx.get(checks({ dataset, digest })))?.passed === true,
);

export const lake = datasets({
  admit: candidatePassed,
  versionRetentionDays: 7,
  keepVersions: 1,
  maxHoldDays: 30,
});

export default app({ checks, candidatePassed, lake });
```

The `admit` query is asked once per candidate and answers a boolean. The other
options set [retention](https://docs.bijection.com/datasets/maintenance.md#version-retention); they change
only with a deploy. Each `datasets(...)` call is one installation with its own
ledger, roles, targets, receivers and secrets, so a tree may mount it at
several paths (`app({ lake: datasets(a), archive: datasets(b) })`).

The installation declares `lake.roles.operator`, which the functions the
console's Datasets panel calls allow. Grant it to whoever manages the
installation:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
await ctx.grant(lake.roles.operator, { to: "person:ada", under: ctx.frame.under });
```

Calls from your own code with `ctx.call` need no grant.

## Declare a dataset

The mount above has one catalog, `lake`, operated by the hosting cell unless
you bind it elsewhere ([catalogs](https://docs.bijection.com/datasets/catalogs.md)). Declare a dataset in
it from any of your mutations:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
await ctx.call(lake.catalogs.create, {
  name: "orders", catalog: "lake", table: "orders", label: null, leaseMinutes: 60, layout: null,
});
```

`leaseMinutes` (60 when null, 15 to 720) is the longest any read of the dataset
lasts. See [catalogs](https://docs.bijection.com/datasets/catalogs.md) for named catalogs, your own catalog and your own lake storage.

## Publish a version

Your engine writes files and adds a snapshot to the table without moving
`main`. Then submit to the installation's `publication` target, and receive its
result in a continuation:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { mutation, t } from "@bijectionhq/bijection";

export const published = mutation(
  { args: { snapshot: t.string, result: t.result(lake.publication) } },
  async (ctx, { snapshot, result }) => {
    if (result.ok) {
      // result.value: { dataset, number, snapshot, tag, selected }
    } else {
      // result.code === "Refused"; result.message is the reason
    }
    return null;
  },
);

export const nightly = mutation(
  { args: { snapshot: t.string, digest: t.string } },
  async (ctx, { snapshot, digest }) => {
    await ctx.submit(lake.publication, {
      dataset: "orders", snapshot, digest, parent: null, cut: null, acceptance: null, hint: null,
      meaning: null, rule: null, cell: null, changes: null, label: null, select: null,
    }, {
      once: ["publish", snapshot],
      within: { hours: 1 },
      then: published.with({ snapshot }),
    });
    return null;
  },
);
```

The app asks `admit`, then sends one catalog commit that asserts `main` is still
at the expected parent, moves `main` to the snapshot and tags it. A stale
publication refuses. An answer that decides nothing is resolved by reading the
table's refs, so a version is never published twice, and the same `once`
returns the original task. `lake.versions.current`, `get` and `list` read the
ledger. An app reaches only the exports of the apps it mounts, so its own code
calls them under a role it passed in `datasets({ readers })`; `publishers`
(cuts and producer runs), `erasers` (legal erasure and its reach) and
`keepers` (lake syncs) admit the other groups. A function no passed role
allows stays internal to Datasets.

To keep one of your tables in a dataset continuously instead, declare a
[sync](https://docs.bijection.com/datasets/publish-a-table.md).

## View dataset erasure

A [pipeline over a view relation](https://docs.bijection.com/transforms/pipelines.md#publish-a-view-relation)
with warehouse contributors writes sealed files grouped by the identity
subject's bucket. A contributor aligns when its view route and SQL closure
key both match that subject. Aligned contributors hash the same typed
subject with the same salt. The lock records the bucket count and reports
the contributor's bucket share or its whole-dataset withdrawal scope.
Inherited input custody can widen the actual withdrawal.

The bucket count defaults to 64. Supply row and target file-size estimates
with the pipeline's `viewBuckets` option to derive it from their ratio.
Bijection rounds up to a power of two between 16 and 1,024. Changing the
count changes the reviewed pipeline contract. Each sealed output file has
a cap of 1,024 individual custody units including its warehouse bucket
units and inherited input units.

For an erasable local row, check counts the row's own `_id` unit once
and adds one unit for each distinct blind unique or natural-key address.
Put an upper bound on distinct local rows per file in
`viewBuckets[dataset].localRows` by table path. Check multiplies that bound
by the table's units per row. Datasets validates each staged file's
custody proof against the pinned input files and reports the actual
per-file unit counts.

End-to-end managed writer proof production is designed, not implemented. Bucketed view output staging requires those proofs.

Lake custody admission of native blind address epochs is designed, not implemented.

Datasets can pin and issue keys in one member frame. Set
`warehouseMemberFamily` and grant `roles.memberLakeWriter` at the
dataset's exact member. Use a separate bound table and scoped input
publications for that member. The authenticated `lake.issueMemberRunOutput`
entry uses that scope for SQL pins and Lake key issue.

End-to-end member dataset publishing and reading are designed, not implemented.

SQL deletion consumers and erase operations close the affected bucket
units. Lifetime expiry closes them when the relation has no deletion
signal. Key handoff then reports `erased`, and custody destroys the keys
within the dataset's lease and key-lifetime bound. A rebuild can pin a new
unit for a closed bucket only after the source has been observed beyond
its closure cutoff. If that observation is unavailable, the writer
refuses `SourceRetention`.

## Next steps

* [Publish a table](https://docs.bijection.com/datasets/publish-a-table.md): sync a table of your app into a dataset.
* [Read a version](https://docs.bijection.com/datasets/exact-reads.md): read leases, holds and cuts.
* [Catalogs](https://docs.bijection.com/datasets/catalogs.md): the managed catalog, your own catalog and lake storage.
* [Views](https://docs.bijection.com/datasets/consumer-views.md) for engines that read the catalog directly.
* [Retention, maintenance and erasure](https://docs.bijection.com/datasets/maintenance.md).
* [Branches](https://docs.bijection.com/datasets/branches.md): a world's branch of a synced dataset.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.