dbt
Generate anfra data models from the models in your dbt project, with their columns, descriptions and tests.
Upcoming
This integration is in development and not available yet.
If your warehouse tables are built and documented with dbt, you don't need to rewrite that work in AML. anfra reads your dbt project's manifest and generates a data model for each dbt model: its table, its columns as dimensions, and the descriptions you wrote in dbt.
dbt stays the source of truth for how tables are built and documented. anfra queries the tables dbt builds, and you add the measures and metrics on top.
How it works
anfra reads target/manifest.json, the file dbt writes when it compiles your project. Each dbt model becomes an AML model that points at the table or view dbt built. When a query runs, anfra compiles it to SQL on that table, like any other model.
Step 1: Add the dbt project as a context source
List the dbt project in .anfra/context_sources.yml, with the connection it builds into as data_source_name:
sources:
- name: dbt_main
type: dbt
local: { path: ../analytics-dbt }
data_source_name: warehouseMake sure that the dbt folder contains a target/manifest.json file.
Step 2: Add the models
anfra sl add --dbt-source dbt_main --model orders --model customers| Flag | Description |
|---|---|
--dbt-source | The dbt source to create models from. Required. |
--model | Only add dbt models whose name starts with this prefix. Case-sensitive. Repeat it to add several prefixes. |
Without --model, anfra adds every model in the dbt project.
sl add never overwrites a model. If a model for the same table already exists, it's skipped; use sl update instead.
Step 3: Review the generated AML models
Model orders {
type: 'table'
label: 'Orders'
description: 'One row per order.'
data_source_name: 'warehouse'
table_name: '"analytics"."marts"."orders"'
dimension order_id {
label: 'Order Id'
type: 'number'
description: 'Primary key.'
primary_key: true
definition: @sql {{ #SOURCE.order_id }};;
}
dimension customer_id {
label: 'Customer Id'
type: 'number'
definition: @sql {{ #SOURCE.customer_id }};;
}
dimension ordered_at {
label: 'Ordered At'
type: 'datetime'
description: 'When the customer placed the order.'
definition: @sql {{ #SOURCE.ordered_at }};;
}
dimension order_total {
label: 'Order Total'
type: 'number'
description: 'Order value after discounts, in USD.'
definition: @sql {{ #SOURCE.order_total }};;
}
}Here's what each part of the dbt project mapped to:
| dbt | anfra |
|---|---|
| Model | Model, with table_name from the model's relation |
| Column | dimension |
description | description |
Column type, from catalog.json | Dimension type. Without the catalog, anfra reads the types from the warehouse. |
unique and not_null tests on one column | primary_key: true |
dbt models have no measures, so add your own measures and metrics, such as sum(orders.order_total).
Updating models
After your dbt project changes, rebuild the manifest and run:
anfra sl update --dbt-source dbt_mainThis updates every model. To update only some, name them: anfra sl update orders customers --dbt-source dbt_main. It tries to keep the measures and edits you added. Review the diff before you commit.
Capabilities
| Capability | Support | Details |
|---|---|---|
| Add and update dbt models | Supported | Tables, columns, descriptions and column types, with anfra sl add and anfra sl update. |
| Primary keys | Supported | From unique and not_null tests. |
| Write back to dbt | Not supported | Changes in anfra are not written back to your dbt project. |
| dbt Semantic Layer (MetricFlow) | Not supported | Semantic models and metrics in the manifest are not added. |
| dbt Cloud | Not supported | The project must be on disk. anfra doesn't fetch the manifest from dbt Cloud. |