上文介绍了dbt语义层及语义模型作用和意义,以及语义模型的组成部分。并没有涉及语义模型规范,本文继续介绍语义模型规范,以及如何配置语义模型。
dbt语义模型
语义模型是MetricFlow中数据定义的基础,它增强了dbt语义层:
-
将语义模型视为语义图中由实体连接的节点。
-
MetricFlow使用YAML配置文件创建查询指标的图。
-
每个语义模型对应于DAG中的dbt模型,需要对每个语义模型进行唯一的YAML配置。
-
可以从单个dbt模型(SQL或Python)创建多个语义模型,只要为每个语义模型提供一个唯一的名称。
-
在dbt项目目录下的YAML文件中配置语义模型。
-
定义好语义模型,通过metric定义进行组织。
语义模型规范
semantic_models:
- name: the_name_of_the_semantic_model ## Required
description: same as always ## Optional
model: ref('some_model') ## Required
defaults: ## Required
agg_time_dimension: dimension_name ## Required if the model contains measures
entities: ## Required
- see more information in entities
measures: ## Optional
- see more information in the measures section
dimensions: ## Required
- see more information in the dimensions section
primary_entity: >-
if the semantic model has no primary entity, then this property