Loading...
Loading...
Compare original and translation side by side
[!NOTE] This skill contains guidance for the new dbt semantic layer YAML spec, valid for dbt 1.12.0 and above. If the user is using a different version of dbt, you can use the migration guide to help them migrate to the new spec and add new components to their semantic layer. Ask the user if they want to migrate to the new spec before proceeding.
[!NOTE] 本技能包含针对新版dbt语义层YAML规范的指导,适用于dbt 1.12.0及以上版本。如果用户使用的是其他版本的dbt,你可以使用迁移指南帮助他们迁移到新版规范,并在语义层中添加新组件。在继续操作前,请询问用户是否需要迁移到新版规范。
customerscustomerssemantic_model:enabled: trueagg_time_dimensionmodels:
- name: orders
semantic_model:
enabled: true # enable the semantic model
agg_time_dimension: ordered_at # set the primary time column (this is a column in the dbt model)semantic_model:enabled: trueagg_time_dimensionmodels:
- name: orders
semantic_model:
enabled: true # enable the semantic model
agg_time_dimension: ordered_at # set the primary time column (this is a column in the dbt model)_identity: \n\t type: primaryentity: type: foreignmodels:
- name: orders
semantic_model:
enabled: true # enable the semantic model
agg_time_dimension: ordered_at # set the primary time column (this is a column in the dbt model)
columns:
- name: order_id # this is the primary key column of the model
entity:
type: primary
name: order
- name: customer_id # this is a foreign key column of the model
entity:
type: foreign
name: customer_identity: \n\t type: primaryentity: type: foreignmodels:
- name: orders
semantic_model:
enabled: true # enable the semantic model
agg_time_dimension: ordered_at # set the primary time column (this is a column in the dbt model)
columns:
- name: order_id # this is the primary key column of the model
entity:
type: primary
name: order
- name: customer_id # this is a foreign key column of the model
entity:
type: foreign
name: customerdimension: type: timegranularitydimension: type: categoricalmodels:
- name: orders
semantic_model:
enabled: true # enable the semantic model
agg_time_dimension: ordered_at # set the primary time column (this is a column in the dbt model)
columns:
- name: order_id
entity:
type: primary
name: order
- name: customer_id
entity:
type: foreign
name: customer
- name: ordered_at
granularity: day # set the granularity of the time column
dimension:
type: time
- name: order_status
dimension:
type: categoricaldimension: type: timegranularitydimension: type: categoricalmodels:
- name: orders
semantic_model:
enabled: true # enable the semantic model
agg_time_dimension: ordered_at # set the primary time column (this is a column in the dbt model)
columns:
- name: order_id
entity:
type: primary
name: order
- name: customer_id
entity:
type: foreign
name: customer
- name: ordered_at
granularity: day # set the granularity of the time column
dimension:
type: time
- name: order_status
dimension:
type: categoricalsimplederivedcumulativeconversionratiomodels:
- name: orders
semantic_model:
enabled: true # enable the semantic model
agg_time_dimension: ordered_at # set the primary time column (this is a column in the dbt model)
columns:
- name: order_id
entity:
type: primary
name: order
- name: customer_id
entity:
type: foreign
name: customer
- name: ordered_at
granularity: day # set the granularity of the time column
dimension:
type: time
- name: order_status
dimension:
type: categorical
metrics:
- name: order_count
type: simple
agg: count
expr: 1
- name: total_revenue
type: simple
agg: sum
expr: amount
- name: average_order_value
type: simple
agg: average
expr: amountsimplederivedcumulativeconversionratiomodels:
- name: orders
semantic_model:
enabled: true # enable the semantic model
agg_time_dimension: ordered_at # set the primary time column (this is a column in the dbt model)
columns:
- name: order_id
entity:
type: primary
name: order
- name: customer_id
entity:
type: foreign
name: customer
- name: ordered_at
granularity: day # set the granularity of the time column
dimension:
type: time
- name: order_status
dimension:
type: categorical
metrics:
- name: order_count
type: simple
agg: count
expr: 1
- name: total_revenue
type: simple
agg: sum
expr: amount
- name: average_order_value
type: simple
agg: average
expr: amountdbt parsedbt sl validatemf validate-configsdbt parsedbt sl validatemf validate-configssemantic_model:semantic_model:derived_semantics derived_semantics:
dimensions:
- name: order_size_bucket
type: categorical
expr: case when amount > 100 then 'large' else 'small' end
label: "Order Size"
entities:
- name: order_customer_key
type: foreign
expr: "order_id || '-' || customer_id"derived_semantics derived_semantics:
dimensions:
- name: order_size_bucket
type: categorical
expr: case when amount > 100 then 'large' else 'small' end
label: "Order Size"
entities:
- name: order_customer_key
type: foreign
expr: "order_id || '-' || customer_id"metricsmodels.metricsmetricsmetricsmodels.metricsmetrics - name: revenue_per_order
type: derived
description: Average revenue per order
label: Revenue per Order
expr: total_revenue / total_orders
input_metrics:
- name: total_revenue
- name: total_orders
# With offset window
- name: revenue_growth
type: derived
expr: total_revenue - revenue_last_week
input_metrics:
- name: total_revenue
- name: total_revenue
alias: revenue_last_week
offset_window: 1 week
filter: "{{ Dimension('order__status') }} = 'completed'" - name: revenue_per_order
type: derived
description: Average revenue per order
label: Revenue per Order
expr: total_revenue / total_orders
input_metrics:
- name: total_revenue
- name: total_orders
# With offset window
- name: revenue_growth
type: derived
expr: total_revenue - revenue_last_week
input_metrics:
- name: total_revenue
- name: total_revenue
alias: revenue_last_week
offset_window: 1 week
filter: "{{ Dimension('order__status') }} = 'completed'" - name: cumulative_revenue
type: cumulative
description: Running total of revenue
label: Cumulative Revenue
input_metric: total_revenue
grain_to_date: week
period_agg: first
# With window
- name: trailing_7d_revenue
type: cumulative
input_metric: total_revenue
window: 7 days - name: cumulative_revenue
type: cumulative
description: Running total of revenue
label: Cumulative Revenue
input_metric: total_revenue
grain_to_date: week
period_agg: first
# With window
- name: trailing_7d_revenue
type: cumulative
input_metric: total_revenue
window: 7 days - name: conversion_rate
type: ratio
description: Orders divided by visits
label: Conversion Rate
numerator: total_orders
denominator: total_visits
# With filters
- name: premium_conversion_rate
type: ratio
numerator:
name: total_orders
filter: "{{ Dimension('order__customer_segment') }} = 'premium'"
alias: premium_orders
denominator: total_visits - name: conversion_rate
type: ratio
description: Orders divided by visits
label: Conversion Rate
numerator: total_orders
denominator: total_visits
# With filters
- name: premium_conversion_rate
type: ratio
numerator:
name: total_orders
filter: "{{ Dimension('order__customer_segment') }} = 'premium'"
alias: premium_orders
denominator: total_visits - name: signup_to_purchase
type: conversion
description: Rate of signups converting to purchase
label: Signup to Purchase
entity: customer
calculation: conversion_rate
base_metric: signups
conversion_metric: purchases
window: 7 days
constant_properties:
- base_property: signup_channel
conversion_property: purchase_channel - name: signup_to_purchase
type: conversion
description: Rate of signups converting to purchase
label: Signup to Purchase
entity: customer
calculation: conversion_rate
base_metric: signups
conversion_metric: purchases
window: 7 days
constant_properties:
- base_property: signup_channel
conversion_property: purchase_channelundefinedundefinedundefinedundefinedsemantic_model:enabled: trueagg_time_dimension:semantic_modelentity:dimension:granularity:metrics:metrics:semantic_model:enabled: trueagg_time_dimension:semantic_modelentity:dimension:granularity:metrics:metrics:entity: primarylabeldayentity: primarylabelday| Pitfall | Fix |
|---|---|
Missing | Every semantic model needs a default time dimension |
| Must be at column level |
| Defining a column as both an entity and a dimension | A column can only be one or the other |
Simple metrics in top-level | Top-level is only for cross-model metrics |
Using | Cumulative metrics can only have one |
Missing | Must list metrics used in |
| 陷阱 | 解决方法 |
|---|---|
缺少 | 每个语义模型都需要一个默认时间维度 |
| 必须在列级别设置 |
| 将列同时定义为实体和维度 | 一列只能是其中之一 |
简单指标放在顶级 | 顶级仅用于跨模型指标 |
同时使用 | 累积指标只能使用其中一个 |
派生指标缺少 | 必须列出 |