Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BACKPORT][CT-2888] Backport #8247 to 1.6.latest #8251

Merged
merged 7 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Dependencies-20230728-135227.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Dependencies
body: Support dbt-semantic-interfaces 0.2.0
time: 2023-07-28T13:52:27.207241-07:00
custom:
Author: QMalcolm
PR: "8250"
10 changes: 10 additions & 0 deletions core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from dbt.node_types import ModelLanguage, NodeType, AccessType
from dbt_semantic_interfaces.call_parameter_sets import FilterCallParameterSets
from dbt_semantic_interfaces.references import (
EntityReference,
MeasureReference,
LinkableElementReference,
SemanticModelReference,
Expand Down Expand Up @@ -1498,6 +1499,7 @@ class SemanticModel(GraphNode):
refs: List[RefArgs] = field(default_factory=list)
created_at: float = field(default_factory=lambda: time.time())
config: SemanticModelConfig = field(default_factory=SemanticModelConfig)
primary_entity: Optional[str] = None

@property
def entity_references(self) -> List[LinkableElementReference]:
Expand Down Expand Up @@ -1580,6 +1582,14 @@ def checked_agg_time_dimension_for_measure(
)
return TimeDimensionReference(element_name=agg_time_dimension_name)

@property
def primary_entity_reference(self) -> Optional[EntityReference]:
return (
EntityReference(element_name=self.primary_entity)
if self.primary_entity is not None
else None
)


# ====================================
# Patches
Expand Down
1 change: 1 addition & 0 deletions core/dbt/contracts/graph/unparsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ class UnparsedSemanticModel(dbtClassMixin):
entities: List[UnparsedEntity] = field(default_factory=list)
measures: List[UnparsedMeasure] = field(default_factory=list)
dimensions: List[UnparsedDimension] = field(default_factory=list)
primary_entity: Optional[str] = None


def normalize_date(d: Optional[datetime.date]) -> Optional[datetime.datetime]:
Expand Down
1 change: 1 addition & 0 deletions core/dbt/parser/schema_yaml_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ def parse_semantic_model(self, unparsed: UnparsedSemanticModel):
measures=self._get_measures(unparsed.measures),
dimensions=self._get_dimensions(unparsed.dimensions),
defaults=unparsed.defaults,
primary_entity=unparsed.primary_entity,
)

ctx = generate_parse_semantic_models(
Expand Down
3 changes: 1 addition & 2 deletions core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@
"hologram~=0.0.16", # includes transitive dependencies on python-dateutil and jsonschema
"minimal-snowplow-tracker~=0.0.2",
# DSI is under active development, so we're pinning to specific dev versions for now.
# TODO: Before RC/final release, update to use ~= pinning.
"dbt-semantic-interfaces~=0.1.0rc1",
"dbt-semantic-interfaces~=0.2.0",
# ----
# Expect compatibility with all new versions of these packages, so lower bounds only.
"packaging>20.9",
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/duplicates/test_duplicate_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
type_params:
measure:
name: "years_tenure"
filter: "{{dimension('loves_dbt')}} is true"
filter: "{{ Dimension('people_entity__loves_dbt') }} is true"
"""


Expand Down
10 changes: 5 additions & 5 deletions tests/functional/metrics/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
type_params:
measure:
name: "years_tenure"
filter: "{{dimension('loves_dbt')}} is true"
filter: "{{ Dimension('id__loves_dbt') }} is true"

- name: average_tenure
label: "Average tenure"
Expand Down Expand Up @@ -115,7 +115,7 @@
type_params:
measure:
name: years_tenure
filter: "{{dimension('loves_dbt')}} is true"
filter: "{{ Dimension('id__loves_dbt') }} is true"

- name: collective_window
label: "Collective window"
Expand All @@ -124,7 +124,7 @@
type_params:
measure:
name: years_tenure
filter: "{{dimension('loves_dbt')}} is true"
filter: "{{ Dimension('id__loves_dbt') }} is true"
window: 14 days

- name: average_tenure
Expand Down Expand Up @@ -452,7 +452,7 @@
type_params:
measure:
name: years_tenure
filter: "{{dimension('loves_dbt')}} is true"
filter: "{{ Dimension('id__loves_dbt') }} is true"

"""

Expand All @@ -479,7 +479,7 @@
type_params:
measure:
name: years_tenure
filter: "{{dimension('loves_dbt')}} is true"
filter: "{{ Dimension('id__loves_dbt') }} is true"

"""

Expand Down
8 changes: 4 additions & 4 deletions tests/functional/partial_parsing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
type_params:
measure:
name: customers
filter: "{{dimension('loves_dbt')}} is true"
filter: "{{ Dimension('id__loves_dbt') }} is true"
+meta:
is_okr: True
tags:
Expand Down Expand Up @@ -472,7 +472,7 @@
type_params:
measure:
name: years_tenure
filter: "{{dimension('loves_dbt')}} is true"
filter: "{{ Dimension('id__loves_dbt') }} is true"

"""

Expand Down Expand Up @@ -619,7 +619,7 @@
type_params:
measure:
name: years_tenure
filter: "{{dimension('loves_dbt')}} is true"
filter: "{{ Dimension('id__loves_dbt') }} is true"

"""

Expand Down Expand Up @@ -1008,7 +1008,7 @@
type_params:
measure:
name: years_tenure
filter: "{{dimension('loves_dbt')}} is true"
filter: "{{ Dimension('id__loves_dbt') }} is true"

"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
- name: user
type: foreign
expr: user_id
- name: id
type: primary

metrics:
- name: records_with_revenue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_metric_node_satisfies_protocol():

def test_where_filter_satisfies_protocol():
where_filter = WhereFilter(
where_sql_template="{{ dimension('dimension_name') }} AND {{ time_dimension('time_dimension_name', 'month') }} AND {{ entity('entity_name') }}"
where_sql_template="{{ Dimension('enity_name__dimension_name') }} AND {{ TimeDimension('entity_name__time_dimension_name', 'month') }} AND {{ Entity('entity_name') }}"
)
assert isinstance(where_filter, RuntimeCheckableWhereFilter)

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_yaml_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ def test__metrics(self):
dct = {
"name": "test{{ metric_name_end }}",
"description": "{{ docs('my_doc') }}",
"filter": "{{ dimension('my_dim') }} = false",
"filter": "{{ Dimension('my_entity__my_dim') }} = false",
}
# We expect the expression and description will not be rendered, but
# other fields will be
expected = {
"name": "test_metric",
"description": "{{ docs('my_doc') }}",
"filter": "{{ dimension('my_dim') }} = false",
"filter": "{{ Dimension('my_entity__my_dim') }} = false",
}
dct = renderer.render_data(dct)
self.assertEqual(dct, expected)