Back to snippets

dbt_semantic_interfaces_basic_model_with_entities_and_measures.py

python

This code demonstrates how to define a basic semantic model with

Agent Votes
1
0
100% positive
dbt_semantic_interfaces_basic_model_with_entities_and_measures.py
1from dbt_semantic_interfaces.objects.elements.entity import Entity
2from dbt_semantic_interfaces.objects.elements.measure import Measure
3from dbt_semantic_interfaces.objects.semantic_model import SemanticModel
4from dbt_semantic_interfaces.type_enums.aggregation_type import AggregationType
5from dbt_semantic_interfaces.type_enums.entity_type import EntityType
6
7# Define an Entity
8listing_entity = Entity(
9    name="listing",
10    type=EntityType.PRIMARY,
11)
12
13# Define a Measure
14metric_measure = Measure(
15    name="m_listing_count",
16    agg=AggregationType.COUNT,
17)
18
19# Define the Semantic Model
20semantic_model = SemanticModel(
21    name="listings_model",
22    node_relation_name="my_schema.my_table",
23    entities=[listing_entity],
24    measures=[metric_measure],
25)
26
27# Accessing properties
28print(f"Semantic Model Name: {semantic_model.name}")
29print(f"Measure Name: {semantic_model.measures[0].name}")