A dbt macro that generates a Snowflake Semantic View from a dbt semantic model.
- Copy
generate_semantic_view.sqlinto yourmacros/directory. - Add
Snowflake-Labs/dbt_semantic_viewto yourpackages.ymland rundbt deps.
packages.yml:
...
- package: Snowflake-Labs/dbt_semantic_view
version: 1.0.3
...To use: create a dbt model and give it the name you want the semantic view in snowflake to have. Our team stores them in semantic_views/.
marts/example/semantic_views/example.sql:
{{ config(materialized='semantic_view') }}
-- depends_on: {{ ref('...') }}
-- depends_on: {{ ref('...') }}
-- depends_on: {{ ref('...') }}
-- depends_on: {{ ref('...') }}
{{ generate_semantic_view() }}Dependency resolution is a bit funky at this point - add a depends_on comment listing all included dbt models.
- The macro generates a semantic view of all semantic models - i.e., it works for a single semantic view per project.
It should be trivial to parameterize the macro to allow defining models to include,
which - when passing parameters using the
ref()statement - would have the added benefit of eliminating the need for thedepends_oncomments. - Not all metrics have been tested.
If you make an improved version, or have an interest in teaming up and turning this into a dbt package, please post in the comments here!