From ec7ef1ba5364c6e2a8b55b4bec32a521f8af9bfe Mon Sep 17 00:00:00 2001 From: Albert Lie Date: Thu, 17 Oct 2024 10:00:51 -0400 Subject: [PATCH 1/3] add an example of separating semantic model (pure yaml) from dbt model (yaml, sql, python) --- .../semantic-layer-3-build-semantic-models.md | 64 ++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/website/docs/best-practices/how-we-build-our-metrics/semantic-layer-3-build-semantic-models.md b/website/docs/best-practices/how-we-build-our-metrics/semantic-layer-3-build-semantic-models.md index 7990cf6752f..8b90bcef97a 100644 --- a/website/docs/best-practices/how-we-build-our-metrics/semantic-layer-3-build-semantic-models.md +++ b/website/docs/best-practices/how-we-build-our-metrics/semantic-layer-3-build-semantic-models.md @@ -241,7 +241,9 @@ measures: ## Reviewing our work -Our completed code will look like this, our first semantic model! +Our completed code will look like this, our first semantic model! Here are two examples showing different organizational approaches: + +### Co-located approach @@ -289,6 +291,66 @@ semantic_models: agg: sum ``` +### Parallel subfoldering approach + + + +```yml +semantic_models: + - name: orders + defaults: + agg_time_dimension: ordered_at + description: | + Order fact table. This table is at the order grain with one row per order. + + model: ref('stg_orders') + + entities: + - name: order_id + type: primary + - name: location + type: foreign + expr: location_id + - name: customer + type: foreign + expr: customer_id + + dimensions: + - name: ordered_at + expr: date_trunc('day', ordered_at) + # use date_trunc(ordered_at, DAY) if using BigQuery + type: time + type_params: + time_granularity: day + - name: is_large_order + type: categorical + expr: case when order_total > 50 then true else false end + + measures: + - name: order_total + description: The total revenue for each order. + agg: sum + - name: order_count + description: The count of individual orders. + expr: 1 + agg: sum + - name: tax_paid + description: The total tax paid on each order. + agg: sum +``` + +As you can see, the content of the semantic model is identical in both approaches. The key differences are: + +1. **File location**: + - Co-located approach: `models/marts/orders.yml` + - Parallel subfoldering approach: `models/semantic_models/sem_orders.yml` + +2. **File naming**: + - Co-located approach: Uses the same name as the corresponding mart (`orders.yml`) + - Parallel subfoldering approach: Prefixes the file with `sem_` (`sem_orders.yml`) + +Choose the approach that best fits your project structure and team preferences. The co-located approach is often simpler for new projects, while the parallel subfoldering approach can be clearer for large existing projects being migrated to use the Semantic Layer. + ## Next steps Let's review the basics of semantic models: From cde56a9256da9ae1ba3c7858b475382c6f6877df Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Fri, 18 Oct 2024 11:10:47 +0100 Subject: [PATCH 2/3] Update semantic-layer-3-build-semantic-models.md --- .../semantic-layer-3-build-semantic-models.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/website/docs/best-practices/how-we-build-our-metrics/semantic-layer-3-build-semantic-models.md b/website/docs/best-practices/how-we-build-our-metrics/semantic-layer-3-build-semantic-models.md index 8b90bcef97a..efb3c64ac62 100644 --- a/website/docs/best-practices/how-we-build-our-metrics/semantic-layer-3-build-semantic-models.md +++ b/website/docs/best-practices/how-we-build-our-metrics/semantic-layer-3-build-semantic-models.md @@ -291,7 +291,7 @@ semantic_models: agg: sum ``` -### Parallel subfoldering approach +### Parallel sub-folder approach @@ -341,15 +341,15 @@ semantic_models: As you can see, the content of the semantic model is identical in both approaches. The key differences are: -1. **File location**: +1. **File location** - Co-located approach: `models/marts/orders.yml` - - Parallel subfoldering approach: `models/semantic_models/sem_orders.yml` + - Parallel sub-folder approach: `models/semantic_models/sem_orders.yml` -2. **File naming**: +2. **File naming** - Co-located approach: Uses the same name as the corresponding mart (`orders.yml`) - - Parallel subfoldering approach: Prefixes the file with `sem_` (`sem_orders.yml`) + - Parallel sub-folder approach: Prefixes the file with `sem_` (`sem_orders.yml`) -Choose the approach that best fits your project structure and team preferences. The co-located approach is often simpler for new projects, while the parallel subfoldering approach can be clearer for large existing projects being migrated to use the Semantic Layer. +Choose the approach that best fits your project structure and team preferences. The co-located approach is often simpler for new projects, while the parallel sub-folder approach can be clearer for migrating large existing projects to the Semantic Layer. ## Next steps From eed19df7eb7a8f8c3f389457dbc6df4da35faa16 Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Fri, 18 Oct 2024 11:15:24 +0100 Subject: [PATCH 3/3] Update semantic-layer-3-build-semantic-models.md --- .../semantic-layer-3-build-semantic-models.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/website/docs/best-practices/how-we-build-our-metrics/semantic-layer-3-build-semantic-models.md b/website/docs/best-practices/how-we-build-our-metrics/semantic-layer-3-build-semantic-models.md index efb3c64ac62..da882dba6c5 100644 --- a/website/docs/best-practices/how-we-build-our-metrics/semantic-layer-3-build-semantic-models.md +++ b/website/docs/best-practices/how-we-build-our-metrics/semantic-layer-3-build-semantic-models.md @@ -243,7 +243,7 @@ measures: Our completed code will look like this, our first semantic model! Here are two examples showing different organizational approaches: -### Co-located approach + @@ -290,8 +290,9 @@ semantic_models: description: The total tax paid on each order. agg: sum ``` + -### Parallel sub-folder approach + @@ -338,6 +339,7 @@ semantic_models: description: The total tax paid on each order. agg: sum ``` + As you can see, the content of the semantic model is identical in both approaches. The key differences are: