Guides
Generate DAR for Dataform
This guide is for Dataform users who want to generate SQLX files from DAR documents. DAR describes the reporting layer on a Daana DAB: dimensions, facts, bridges, references and serve models. Start with the DAR documents and a BigQuery connection profile for a deployed Daana DAB, or use --preview without a live connection. On BigQuery, the production route is daana dar generate: it writes BigQuery SQLX files, and Dataform creates and refreshes the resulting tables and views in your project.
DAR requires Daana DAB. Deploy that DAB before generating a package against live metadata. The generated SQLX reads Daana's DAB tables and views; it cannot run on a data warehouse that Daana did not build. Dataform executes DAR on that DAB and does not replace it.
The workflow has three steps: check the DAR documents, generate the SQLX files, and run the generated actions in Dataform. daana dar generate reads metadata when requested, but does not deploy a DAR revision or write reporting data. To create the same outputs directly on a deployed DAB without Dataform, for example on a local DuckDB file, see Apply DAR on a deployed DAB.
Project layout
The bookstore project uses the layout daana init creates. Daana finds the DAB model through daana.yaml and its DAB workflow, so the model stays in one place. DAR documents live in dar/, and generated SQLX goes to a separate Dataform definitions directory:
bookstore/
daana.yaml
connections.yaml
dab/
model.yaml
workflow.yaml
mappings/
dar/
workspace.yaml
order_line.yaml
definitions/
dar/ # generated SQLX
A model.yaml beside the DAR documents, or in a parent directory, takes precedence over daana.yaml. An existing Dataform repository can also live elsewhere; choose its output directory with --out.
dar/order_line.yaml is the bookstore's daily revenue declaration: a dimension on order_line, a fact with one row per order line at its order's date, and daily revenue by order date and currency. The apply guide shows the full document.
Bind an authored project
With sibling dab/ and dar/ folders, add dar: {spec: dar/} to domains in daana.yaml. Keep the DAB workflow declaration and connection profile there. The workflow's model reference names the model file relative to the workflow. With --project, Daana uses the model that the workflow names, even when another model.yaml is nearby.
Check the DAR documents and lint their descriptions and style with JSON output, then write a preview to the directory named by --out:
daana dar check --project /work/shop/daana.yaml --format json
daana dar lint --project /work/shop/daana.yaml --format json
daana dar generate --project /work/shop/daana.yaml --preview --out /tmp/shop-preview
These commands work outside the project directory. The project declaration tells Daana where to find the DAR documents and which DAB model to use, but it does not select a catalog source. Pass --preview, --resolved-manifest, or the target database's connection flags explicitly.
An explicit connection must match the profile and connections file selected by the project. Workspace dataset aliases/constants retain their existing owner beside the selected spec. Without an output path in the command or configuration, project mode writes to definitions/dar under the project declaration's directory. Paths set in the command or configuration follow the usual CLI rules.
A preview can use new attributes in the local model before they are deployed to the DAB. A resolved manifest must cover the whole model. It does not show that the files match the deployed DAB.
The deployed a0 session remains authoritative for warehouse attributes/type keys, so newly authored fields need DAB deployment before live generation. Commands without --project still look for a nearby model.
Generate against deployed DAB metadata
Daana reads the deployed DAB's metadata to generate SQLX for that DAB. Check the DAR documents, then generate SQLX with the bookstore_bq connection profile:
daana dar check dar/
daana dar generate --connection bookstore_bq
Input defaults to dar/, and output to definitions/dar/. Both are relative to your current directory. bookstore_bq is the BigQuery profile name in connections.yaml. The profile must point at an a0-enabled deployed Daana DAB. Generation replays that warehouse a0 ledger for columns and attribute type_key values. A Daana installation that has no a0 ledger cannot supply this catalog. This command does not upgrade that installation or add a legacy metadata bridge. The local model only identifies the DAB model.
For the bookstore declaration, generation writes one SQLX file per output:
definitions/dar/dim__order_line.sqlx
definitions/dar/dim__order_line__latest.sqlx
definitions/dar/fct__order_line.sqlx
definitions/dar/fct__order_line_daily_revenue.sqlx
Without a workspace.yaml, the daily revenue file starts with a Dataform configuration for a table in daana_dar. Inspect the partition and clustering settings at the start of fct__order_line_daily_revenue.sqlx:
config {
type: "table",
schema: "daana_dar",
name: "fct__order_line_daily_revenue",
bigquery: {
partitionBy: "order_date",
clusterBy: ["order_date", "order_line_amount_currency"]
}
}
The configuration partitions the table by order_date and clusters it by order_date and order_line_amount_currency. The file's query sums order_line_amount_amount from ${ref("daana_dar", "fct__order_line")} by CAST(fact_ts AS DATE) and currency.
For separate model and Dataform repositories, use --connections to name the connections file and --out to write SQLX to the Dataform repository:
daana dar generate dar/ \
--connections connections.yaml \
--connection bookstore_bq \
--out ../bookstore-dataform/definitions/dar
Daana validates the YAML during generation, so daana dar check is useful while writing documents but is not a prerequisite. Use daana dar lint dar/ to check descriptions and style.
Dataform workspace and dependencies
The file workspace.yaml holds project bindings and shared constants. Look at how this example assigns a BigQuery project and dataset to each layer alias:
backend: sqlx
targets:
dab_model: my-project.dab
intermediate: my-project.intermediate
data_mart: my-project.data_mart
Use your own project and dataset names. The generated actions use these layer aliases in their config.schema and ${ref()} calls. Your Dataform project must resolve those references, including declarations for existing DAB objects and any external reporting dependencies. Generation does not create those declarations or configure Dataform deployment and scheduling.
The model's materialization and incremental settings remain part of the generated SQLX: view/table/incremental action types, unique keys, partitions, clustering and checkpoint/lookback behavior. Generation selects BigQuery SQLX directly; there is no backend or dialect switch to configure.
Review the generated changes, then compile and run the actions through your existing Dataform workflow. Regenerate after changing the reporting YAML or the DAB catalog. Routine scheduled runs execute the released Dataform actions.
Offline generation and previews
A resolved manifest holds bindings captured from the intended Daana DAB. Daana checks those bindings against the local model, but offline generation cannot check whether the deployed DAB has changed. Generate SQLX offline with --resolved-manifest:
daana dar generate dar/ --resolved-manifest resolved_manifest.yaml
For local exploration, generate a preview from the local model without warehouse metadata, and write the files to the directory named by --out:
daana dar generate dar/ --preview --out /tmp/dar-preview
A preview uses the local model's columns and keys, which can differ from the deployed DAB. Generation requires one catalog source: --connection to an a0-enabled deployed DAB, a resolved manifest of captured bindings, or --preview. Only --connection replays a live a0 ledger. Neither preview output nor an offline manifest shows that the files match a live warehouse.
Offline generation and preview still use a Daana DAB model. Both work without a live connection, but the resulting DAR package needs the matching deployed Daana DAB and its data to run.
How DAR resolves a relationship
A DAR document relates its anchor entity to other entities, for example relationships: {customer: {changes: never}} in the bookstore's document anchored on order. DAR finds the model relationship between the anchor and the related entity, and walks it in one of two directions:
- Forwards, when the relationship's source is the anchor: at every cardinality.
- Backwards, when the relationship's target is the anchor: only when its cardinality is
ONE_TO_MANYorONE_TO_ONE. Each anchor then has at most one related entity, so the walk cannot fan out. In the bookstore,orderis the source ofis_placed_by, so theorderdocument walks it forwards. A model that states the relationship from the customer's side, ascustomerplacesorderdeclaredONE_TO_MANY, lets a document anchored onordercarry the customer's key by a backward walk.
Each relationship a document declares says whether the related entity can change for an anchor:
changes: never: the anchor keeps one related entity, such as the order a line was placed on. DAR reads the related key on the anchor's key, from the anchor's latest link inintm__rel_<anchor>, whatever the time of the fact that carries it. A fact dated before the link was loaded still gets the key; a row without a time, such as a lifecycle milestone not reached, gets none. The relationship must give each anchor at most one related entity, so DAR acceptschanges: neveron a forward walk only when the relationship's cardinality isMANY_TO_ONEorONE_TO_ONE. A backward walk already needsONE_TO_MANYorONE_TO_ONE. The bookstore declaresis_placed_byandis_part_ofMANY_TO_ONE.changes: tracked: the related entity can change. DAR reads the related key that holds at the fact's time, so a fact dated before the link was loaded gets no key.via: <role>: the document reaches the entity through another of its relationships, and each step is read as its own document declares it. In the bookstore,customer: {via: order}in theorder_linedocument reaches the customer through the order, whose document declarescustomer: {changes: never}. Compile the documents together, asdar apply dar/does. When the document anchored on the middle entity is not part of the compile, for example when you applydar/order_line.yamlalone, DAR does not know how that step changes and reads it at the fact's time. A change to the middle document's declaration gives the documents that step through it a new revision the next time they are compiled with it. The warehouse does not keep the documents, sodar applycannot recompile them without you: when you apply the middle document without a document that steps through it, and that document's views read the key differently than the middle document gives it, after a change or because it was last applied without the middle document, apply stops before it changes anything and names the document and the files it was last applied from. For example,dar apply dar/order.yamlafter changingcustomertochanges: trackedrefuses and namesorder_line.yaml;dar apply dar/applies both.dar applytakes one file or one directory and does not read subdirectories, so keep documents linked byviain the same directory. Apply never removes an anchor's views, so the same refusal comes whenorder_line.yamlis no longer indar/: restore it, or write a replacement document fororder_line, and apply it withorder.yaml.--dry-rundoes not connect to the warehouse, so it cannot show this refusal.
The columns wide adds come from a dimension, not from a relationship: join: pit reads the dimension version in effect at fact_ts whatever the relationship declares, and join: latest reads the current version.
DAR walks a relationship backwards only when the pair has no forward one. A forward relationship beside a backward one whose cardinality allows the walk is refused (see Both directions below). A self-referencing relationship is walked forwards only. Every part of a document that crosses a relationship resolves it the same way: related entities and their splits, via chains, bridges, assembly keys and roll-ups. The DAR document reference explains relationships, changes: never and via with examples from the bookstore documents.
A tracked relationship (changes: tracked) that DAR walks backwards follows the anchor's own rows, while no document anchored on the related entity relates the anchor without changes: tracked. For each anchor and effective timestamp it takes the related key of the latest-sent row, and the anchor keeps that key until a later row names another one. A ONE_TO_MANY relationship is loaded and read per target, so DAB's relationship view reads it the same way: when a FULL_LOG or INCREMENTAL source has customer A send the set {O1, O2} at 2025-01-01 and then its complete set {O2} at 2025-02-01, both show O1 with customer A. A FULL delivery without O1 closes it instead. When another customer's row takes the order at a later effective timestamp, both follow that later row. The other parts of a document that cross a relationship read it the same way on a backward walk as on a forward one. See A tracked backward walk follows the order's own rows.
dar check refuses a relationship whose entity is not in the model or, unless reached through via, is not related to the anchor in the model. It does not decide which way a relationship is walked, so the three cases below pass the check. dar generate resolves relationships and refuses a document whose relationship it cannot resolve, before it writes any file:
| Refusal | Cause | Fix |
|---|---|---|
| Backward walk not allowed | The model relates the pair only backwards, and the relationship's cardinality is MANY_TO_ONE, MANY_TO_MANY or undeclared | If each anchor has at most one related entity, declare ONE_TO_MANY or ONE_TO_ONE on the relationship in model.yaml. With --connection, deploy the model again before you generate. Otherwise, anchor the document on the relationship's source |
| Both directions | The model relates the pair forwards, and also backwards by a relationship whose cardinality allows the walk | Use a model with one relationship on the pair. Beside a forward relationship, a backward one whose cardinality does not allow the walk raises nothing, and DAR walks the forward one |
| Several relationships | The model has two or more forward relationships on the pair, or two or more backward ones and no forward one, whatever their cardinality | Use a model with one relationship on the pair. All relationships between two entities share one relationship table, and DAR cannot yet choose between them |
changes: never without one related entity | The document relates the entity with changes: never, DAR walks the relationship forwards, and its cardinality is ONE_TO_MANY, MANY_TO_MANY or undeclared | If each anchor has at most one related entity, declare MANY_TO_ONE or ONE_TO_ONE on the relationship in model.yaml. With --connection, deploy the model again before you generate. Otherwise, relate the entity with changes: tracked |
When the bookstore's customer document relates order, generation without a connection reports the backward walk over is_placed_by, which the bookstore model declares MANY_TO_ONE:
Error: dar compile: customer.yaml relates customer → order, but the model relates them only as order → customer (is_placed_by), whose cardinality is MANY_TO_ONE; DAR walks a relationship backwards only when its cardinality is ONE_TO_ONE or ONE_TO_MANY — declare one of them on is_placed_by in model.yaml if each customer has at most one order
A customer places many orders, so the fix is to anchor that document on order. With --connection, the message names the deployed model and ends with declare one of them on is_placed_by in model.yaml and redeploy, if each customer has at most one order. When the model relates the pair both ways, for example is_placed_by beside customer places order declared ONE_TO_MANY, the message names both relationships:
Error: dar compile: order.yaml relates order → customer, and the model relates them both forwards, by is_placed_by (order → customer), and backwards, by places (customer → order, ONE_TO_MANY); DAR cannot choose between them yet — use a model with one relationship on this pair
Daana never checks a declared cardinality against the data. See Daana trusts the declaration for what DAR shows when the data breaks it, and for a check that finds such data.
Preview a run and automate generation
The --dry-run flag checks generation without writing files. Use it with the bookstore_bq profile, and request a JSON summary with --format json:
daana dar generate --connection bookstore_bq --dry-run --format json
With --dry-run, Daana still validates the input and, with a connection, reads warehouse metadata. The JSON summary includes the catalog source, output path, file count, validation warning count and whether this was a dry-run.
Generate the SQLX files and request the same JSON summary without --dry-run:
daana dar generate --connection bookstore_bq --format json
Invalid input or failed metadata reads stop generation before files are written.
Output ownership and current checks support
Generation overwrites matching output filenames. Keep generated files separate from hand-written SQLX and change the source YAML rather than editing generated SQLX. Removed or renamed outputs can leave stale files; review and remove those files from the generated directory before releasing your Dataform project.
The SQLX backend does not yet support checks: written with over: output. daana dar generate rejects them rather than silently dropping them. daana dar apply runs them; see Output checks. Successful generation validates the model and produces files. To verify the data results, run the package against the intended target database. Tutorial chapter 7 lists the expected daily revenue rows for the bookstore data.