> ## 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.

# Read warehouse data

> Read dated warehouse answers, publish typed snapshots, or submit large transformations to compute.

Choose how the app will use the warehouse data.

| Need | Interface |
| - | - |
| Serve bounded warehouse selections | Declare a [virtual table](https://docs.bijection.com/sql/application-api.md) with compiled pushdown shapes. |
| Publish a complete SQL relation | Use compute and Datasets for bulk materialization. |
| Read an installed lake generation through local selections | Keep a typed copy of the published generation. |
| Transform large inputs or materialize large outputs | Submit an [external compute job](https://docs.bijection.com/transforms/external-runtimes.md) or a [pipeline](https://docs.bijection.com/transforms/pipelines.md). |

## Virtual-table contract

A virtual table declares a warehouse receiver, the source relation it reads,
and a closed set of pushdown shapes. The relation declares the source key,
typed columns, subject, deletion signal and travel window. Every
shape has a fixed parameterized statement. `first` bounds results and
`keys` bounds a list pushed across a key join. An unsupported selection
refuses `PushdownMissing`. An unbounded join needs a bounded driving side,
or a point lookup. Trino can serve as one receiver for a federation: its
`forwards` map each catalog name to `{ receiver, database, travel? }`, the
receiver and database the catalog exposes and the connector's cut window.
A relation declared on a forwarded receiver is rendered through its catalog,
and one reaching the federation through no forward refuses
`RelationUndeclared`. A forward without `travel` has no cut, so a table that
reads through it serves no dated read. A table's `travel` is an opt-in at
most the derived window: the minimum of its relation's travel and the
crossed forward's. A larger value refuses `TravelMissing`, naming the
limiting relation or forward.

Each warehouse receiver declares its provider's reviewed finite request-log
policy with `requests: { retain, message }`. The lock prints the policy for
the receiver and each crossed forward. The provider keeps request logs for
the declared duration. The credential's scope determines who the warehouse
sees. Caller-scoped answers stay in the
caller's own member. Every receiver also declares `isolation`, a reviewed
statement of what confines its credential or the reviewed `"none"` when
every answer lands at its one receiving label. `bijection check` refuses a
receiver without one, a receiver serving several members needs a statement,
and the lock prints the choice.

Request-log erasure removes the receiver's record of a request. To review
an explicit source erase, declare `upstream: { erase, lifetime }` on the
virtual table. The lock records a pending target. The design sends from the
explicit eraser only, in the commit that closes the blind address and
writes the standing ban. [Upstream erase contract](https://docs.bijection.com/sql/application-api.md#forward-a-source-erase)

End-to-end upstream erase forwarding is designed, not implemented.

The refresh mutation asks the warehouse. Its private continuation validates
and lands erasable, dated facts, then closes the raw reply. A query or watch
reads the landed answer with its source observation and position. A key the
warehouse answers absent reads `ready` with a null value and closes nothing
derived from an earlier answer. Only the deletion signal, the lifetime or an
erase closes a key. A source deletion excludes observations at or before
the commit that applies it. A new observation after that cutoff can land
a re-created key. An explicit local erase keeps a standing ban until
audited readmission. A past
Bijection version or a branch reads its own landed answers. To read a past
source instant, request it explicitly within the declared travel window.
A travelling receiver declares `skew`, which the default source cut
subtracts from the refresh instant. A `timeline` declaration lands a
bounded valid window per key. Supply `over: { from, to }` to request
another window, which lands as its own answer beside the latest one.
Queries select the period in force from the covering window with the
newest source observation, the latest landing breaking a tie, and read
`unasked` outside every window. A key whose periods overlap is
refused alone, and the reply's other keys land. Use
`ready(ctx, value, { within })` to require a fresh value in a mutation.

The optional `evict` interval removes answers from the live cache while
retaining their history. The kernel enforces row and total lifetimes,
including after eviction. A relation without a deletion signal requires
a table lifetime. Totals that share a destination use one kernel lifetime.

## Scaffold a source schema

Capture metadata using your warehouse's tools. Feed the saved document to
`bijection schema import`. Use an Iceberg struct schema for Iceberg and a
complete catalog observation containing `is_complete` and `columns`
for the other formats.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection schema import snowflake ./orders-metadata.json \
  --name orders --table SALES.PUBLIC.ORDERS --key order_id \
  --out bijection/sources/orders.ts
```

The scaffold records the source address, logical key and field value types.
Review the types, nullable columns and key before committing the file.
The command reads local metadata. Add the reviewed module to the app and
configure the receiver's credential separately. The supported
format commands are `iceberg`, `delta`, `hudi`, `snowflake` and
`bigquery`.

Add `--virtual <receiver>` for a Snowflake, BigQuery, Databricks or Trino
virtual-table scaffold. It transcribes the relation, source keys, types and
column mappings from local metadata. Fill in the marked audience, pushdown,
freshness and deletion or lifetime choices during review. Check drift
with `bijection schema diff <before> <after> --check`.

## Work with copies and versions

A selection over a copy reads the rows the copy last published, at the
reading transaction's version, so queries, mutations and watches see one
complete snapshot. Track the source position and the published snapshot
separately. For bulk data, read [dataset versions](https://docs.bijection.com/datasets/exact-reads.md) and
hand them to compute by reference.

## Keep a typed copy

Use `tableCopy` from `@bijectionhq/library-sources` to give the app a typed
table. It returns a subtree: `rows` (the copy, keyed by `key`), `state`,
`refresh` and `status`. For Iceberg, Delta or Hudi, mount the Tables app at
the copy's label and pass it to `lakeSnapshot`. The mount must have an active,
complete generation before the copy can refresh.

```ts bijection/app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app, label, secret } from "@bijectionhq/bijection";
import { s3Bucket } from "@bijectionhq/app-objects";
import tables, { lakeSnapshot } from "@bijectionhq/app-tables";
import { tableCopy } from "@bijectionhq/library-sources";
import { orders } from "./sources/orders";

const warehouseData = label();
const key = secret();
const bucket = s3Bucket({ bucket: "lake", region: "eu-west-1", prefix: "orders/" }, key, warehouseData);
const lake = tables({ data: warehouseData, provider: bucket });

export const ordersCopy = tableCopy({
  label: warehouseData,
  fields: orders.fields,
  key: orders.key,
  from: lakeSnapshot(lake, { columns: orders.columns }),
});

export default app({ warehouseData, key, bucket, lake, ordersCopy });
```

Here `orders` is the reviewed scaffold. From a function running under the
copy's label, `await ctx.call(ordersCopy.refresh, {})` publishes the active
snapshot. Read a row with `ctx.get(ordersCopy.rows(key))`. A labelled copy is
[protected](https://docs.bijection.com/database/protected-tables.md). Its whole-table selection uses
`.atMost(n)` with an application-chosen bound.
`ctx.call(ordersCopy.status, {})` gives the revision, source position,
`observedAt`, row count and last error.

A [virtual table](https://docs.bijection.com/sql/application-api.md) acquires SQL answers on demand.
Its `copy: true` option consents to a bounded local copy if a derived
`serve` plan requires a population.

Only the copy's own functions write its table. An invalid acquisition leaves
the previous publication readable. A newer refresh supersedes an unfinished
one. The complete snapshot must fit the transaction's storage limits, and
each row has a 24 KiB limit. The acquisition can have its own tighter
bounds. Use compute and Datasets for bulk materialization.

For an erasable copy, provision its `suppressionKey` before its first
refresh or erase. An erase closes the key's retained rows and keeps a
reviewed MAC suppression, also for a key that no snapshot has landed yet.
When the copy declares `upstream.erase`, the erase mutation submits the
source key to that operation.


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