Snowflake Semantic Views
Sync Snowflake Semantic Views into Anfra to build apps without maintaining a duplicated definition.
Upcoming
This integration is in development and not available yet.
If your metrics already live in Snowflake Semantic Views, you don't need to redefine them in AML. anfra syncs their dimensions, facts and measures into data models that keep only a pointer to each definition. When a query runs, anfra wraps each metric in AGG() and Snowflake computes it from the definition it holds.
Metrics are defined once in Snowflake, and every anfra app, dashboard and agent answer uses them as-is.
How it works
Each Snowflake Semantic View syncs into anfra as a data model. At query time, anfra sends SQL with AGG() back to Snowflake, which computes the metrics.
- Snowflake
- Semantic view — Dimensions, facts and metrics defined in Snowflake
- anfra
- Model — Generated .model.aml: dimensions, and measures wrapped in AGG()
- Dataset — You add the model to a dataset to query it
- Apps & agents — Data apps, dashboards and agent answers built on the dataset
- semantic-view → model (anfra sl pull)
- model → dataset (add to)
- dataset → data-apps (query)
- dataset → semantic-view (SQL with AGG(), computed by Snowflake)
Say you have this semantic view in Snowflake:
CREATE SEMANTIC VIEW analytics.public.orders_semantic_view
TABLES (
orders AS analytics.public.orders PRIMARY KEY (order_id)
)
FACTS (
orders.order_value AS order_value
)
DIMENSIONS (
orders.order_month AS DATE_TRUNC('MONTH', order_date)
COMMENT = 'First day of the order month'
)
METRICS (
orders.total_revenue AS SUM(orders.order_value)
COMMENT = 'Gross revenue before discounts'
);Step 1: Connect Snowflake
Add a Snowflake connection to .anfra/data_sources.yml and note its name.
Step 2: Add the models
anfra sl add --data-source <your-datasource-name> \
--schema PUBLIC \
--table ORDERS| Flag | Description |
|---|---|
--data-source | The Snowflake connection to create models from. Required. |
--schema | Only add from schemas whose names start with this prefix. Case-sensitive. |
--table | Only add objects whose names start with this prefix. Case-sensitive. |
Without --schema and --table, anfra adds every table, view and semantic view, up to 1,000 objects. Objects past that limit are skipped without a warning, so use the prefixes on large warehouses.
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_semantic_view {
type: 'table'
data_source_name: 'snowflake'
table_name: '"ANALYTICS"."PUBLIC"."ORDERS_SEMANTIC_VIEW"'
dimension order_value {
label: 'Order Value'
type: 'number'
definition: @sql {{ #SOURCE.order_value }};;
}
dimension order_month {
label: 'Order Month'
type: 'date'
description: 'First day of the order month'
definition: @sql {{ #SOURCE.order_month }};;
}
measure total_revenue {
label: 'Total Revenue'
type: 'number'
description: 'Gross revenue before discounts'
definition: @sql AGG({{ #SOURCE.total_revenue }});;
}
}To query the model, add it to a dataset.
Here's what each part of the semantic view mapped to in the generated model:
| Snowflake | anfra |
|---|---|
| Dimension | dimension |
| Fact | dimension, never aggregated |
| Metric | measure wrapped in AGG(), computed by Snowflake |
COMMENT | description |
On top of the synced fields, you can define your own measures and metrics, such as a ratio of two Snowflake metrics.
Updating models
After the semantic view changes, run:
anfra sl update --data-source <your-datasource-name>This updates every model. To update only some, name them: anfra sl update orders_semantic_view --data-source <your-datasource-name>. It tries to keep the fields and edits you added. Review the diff before you commit.
Lineage
anfra sl add records each semantic view in the Semantic Catalog as the upstream of its model. Trace a field with anfra lineage, or show it in a data app with Anfra.lineage():
anfra lineage --targets '[{"parent":"orders_semantic_view","child":"total_revenue"}]'Lineage stops at the semantic view. It doesn't trace the base tables behind it.
Capabilities
| Capability | Support | Details |
|---|---|---|
| Sync from Snowflake | Supported | Dimensions, facts, metrics and comments, with anfra sl add and anfra sl update. |
| Write back to Snowflake | Not supported | Changes in anfra are not written back to Snowflake. |
| Relationship in dataset | Not supported | Snowflake rejects joins on a semantic view, so a synced model can't have relationships to other models. |
| Synonyms | Not supported | Synonyms defined on the semantic view are not synced. |