From 5fc0718c1bcccd5ac391761381abdb2dfd76eb8c Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Wed, 12 Jul 2023 16:44:14 -0700 Subject: [PATCH 1/5] Bump version support for `dbt-semantic-interfaces` to `~=0.1.0rc1` --- core/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/setup.py b/core/setup.py index ea8332a6102..b0ff02330f1 100644 --- a/core/setup.py +++ b/core/setup.py @@ -78,7 +78,7 @@ "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.0.dev10", + "dbt-semantic-interfaces~=0.1.0rc1", # ---- # Expect compatibility with all new versions of these packages, so lower bounds only. "packaging>20.9", From 6037367b12af6d401b919153426219f3d61efcf4 Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Wed, 12 Jul 2023 16:45:15 -0700 Subject: [PATCH 2/5] Add tests for asserting WhereFilter satisfies protocol --- .../test_semantic_layer_nodes_satisfy_protocols.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/unit/test_semantic_layer_nodes_satisfy_protocols.py b/tests/unit/test_semantic_layer_nodes_satisfy_protocols.py index 46a250c5b75..1c284ede431 100644 --- a/tests/unit/test_semantic_layer_nodes_satisfy_protocols.py +++ b/tests/unit/test_semantic_layer_nodes_satisfy_protocols.py @@ -18,6 +18,7 @@ MetricInputMeasure as DSIMetricInputMeasure, MetricTypeParams as DSIMetricTypeParams, SemanticModel as DSISemanticModel, + WhereFilter as DSIWhereFilter, ) from dbt_semantic_interfaces.type_enums import ( DimensionType, @@ -68,6 +69,11 @@ class RuntimeCheckableMetricTypeParams(DSIMetricTypeParams, Protocol): pass +@runtime_checkable +class RuntimeCheckableWhereFilter(DSIWhereFilter, Protocol): + pass + + def test_semantic_model_node_satisfies_protocol(): test_semantic_model = SemanticModel( name="test_semantic_model", @@ -146,6 +152,13 @@ def test_metric_node_satisfies_protocol(): assert isinstance(metric, RuntimeCheckableMetric) +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') }}" + ) + assert isinstance(where_filter, RuntimeCheckableWhereFilter) + + def test_metric_input(): metric_input = MetricInput(name="a_metric_input") assert isinstance(metric_input, RuntimeCheckableMetricInput) From 2d23765b440b133c97b3f9dc38a783da2af3259e Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Wed, 12 Jul 2023 16:50:07 -0700 Subject: [PATCH 3/5] Add `call_parameter_sets` to `WhereFilter` class to satisfy protocol --- core/dbt/contracts/graph/nodes.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/dbt/contracts/graph/nodes.py b/core/dbt/contracts/graph/nodes.py index 18a692c7018..d3c2eda110f 100644 --- a/core/dbt/contracts/graph/nodes.py +++ b/core/dbt/contracts/graph/nodes.py @@ -48,6 +48,7 @@ from dbt.events.contextvars import set_log_contextvars from dbt.flags import get_flags from dbt.node_types import ModelLanguage, NodeType, AccessType +from dbt_semantic_interfaces.call_parameter_sets import FilterCallParameterSets from dbt_semantic_interfaces.references import ( MeasureReference, LinkableElementReference, @@ -56,6 +57,7 @@ ) from dbt_semantic_interfaces.references import MetricReference as DSIMetricReference from dbt_semantic_interfaces.type_enums import MetricType, TimeGranularity +from dbt_semantic_interfaces.parsing.where_filter_parser import WhereFilterParser from .model_config import ( NodeConfig, @@ -1315,6 +1317,10 @@ def group(self): class WhereFilter(dbtClassMixin): where_sql_template: str + @property + def call_parameter_sets(self) -> FilterCallParameterSets: + return WhereFilterParser.parse_call_parameter_sets(self.where_sql_template) + @dataclass class MetricInputMeasure(dbtClassMixin): From 89818952f7eb1a16c23517adc8d9007462001c7b Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Wed, 12 Jul 2023 16:52:46 -0700 Subject: [PATCH 4/5] Changie doc for moving to DSI 0.1.0rc1 --- .changes/unreleased/Dependencies-20230712-165219.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Dependencies-20230712-165219.yaml diff --git a/.changes/unreleased/Dependencies-20230712-165219.yaml b/.changes/unreleased/Dependencies-20230712-165219.yaml new file mode 100644 index 00000000000..7714a9a4ef7 --- /dev/null +++ b/.changes/unreleased/Dependencies-20230712-165219.yaml @@ -0,0 +1,6 @@ +kind: Dependencies +body: Bump `dbt-semantic-interfaces` to `~=0.1.0rc1` +time: 2023-07-12T16:52:19.748953-07:00 +custom: + Author: QMalcolm + PR: "8082" From 6b33cc8f3d5aa47e6d3e929b882736a862e9344f Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Thu, 13 Jul 2023 03:15:10 -0700 Subject: [PATCH 5/5] [CT-2822] Fix `NonAdditiveDimension` Implementation (#8089) * Add test to ensure `NonAdditiveDimension` implementation satisfies protocol * Fix typo in `NonAdditiveDimension`: `window_grouples` -> `window_groupings` * Add changie doc for typo fix in NonAdditiveDimension --- .../unreleased/Fixes-20230712-172037.yaml | 6 +++++ core/dbt/contracts/graph/semantic_models.py | 2 +- core/dbt/contracts/graph/unparsed.py | 2 +- core/dbt/parser/schema_yaml_readers.py | 2 +- ..._semantic_layer_nodes_satisfy_protocols.py | 26 ++++++++++++++++++- 5 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 .changes/unreleased/Fixes-20230712-172037.yaml diff --git a/.changes/unreleased/Fixes-20230712-172037.yaml b/.changes/unreleased/Fixes-20230712-172037.yaml new file mode 100644 index 00000000000..1f31a85899e --- /dev/null +++ b/.changes/unreleased/Fixes-20230712-172037.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fix typo in `NonAdditiveDimension` implementation +time: 2023-07-12T17:20:37.089887-07:00 +custom: + Author: QMalcolm + Issue: "8088" diff --git a/core/dbt/contracts/graph/semantic_models.py b/core/dbt/contracts/graph/semantic_models.py index 3ccf705ed85..2bb75382c46 100644 --- a/core/dbt/contracts/graph/semantic_models.py +++ b/core/dbt/contracts/graph/semantic_models.py @@ -128,7 +128,7 @@ class MeasureAggregationParameters(dbtClassMixin): class NonAdditiveDimension(dbtClassMixin): name: str window_choice: AggregationType - window_grouples: List[str] + window_groupings: List[str] @dataclass diff --git a/core/dbt/contracts/graph/unparsed.py b/core/dbt/contracts/graph/unparsed.py index 6c0f79e3499..babbca64a21 100644 --- a/core/dbt/contracts/graph/unparsed.py +++ b/core/dbt/contracts/graph/unparsed.py @@ -689,7 +689,7 @@ class UnparsedEntity(dbtClassMixin): class UnparsedNonAdditiveDimension(dbtClassMixin): name: str window_choice: str # AggregationType enum - window_grouples: List[str] + window_groupings: List[str] @dataclass diff --git a/core/dbt/parser/schema_yaml_readers.py b/core/dbt/parser/schema_yaml_readers.py index 78d62c45c52..8f7b1519fb6 100644 --- a/core/dbt/parser/schema_yaml_readers.py +++ b/core/dbt/parser/schema_yaml_readers.py @@ -486,7 +486,7 @@ def _get_non_additive_dimension( return NonAdditiveDimension( name=unparsed.name, window_choice=AggregationType(unparsed.window_choice), - window_grouples=unparsed.window_grouples, + window_groupings=unparsed.window_groupings, ) else: return None diff --git a/tests/unit/test_semantic_layer_nodes_satisfy_protocols.py b/tests/unit/test_semantic_layer_nodes_satisfy_protocols.py index 1c284ede431..4d7618b39b9 100644 --- a/tests/unit/test_semantic_layer_nodes_satisfy_protocols.py +++ b/tests/unit/test_semantic_layer_nodes_satisfy_protocols.py @@ -7,7 +7,13 @@ SemanticModel, WhereFilter, ) -from dbt.contracts.graph.semantic_models import Dimension, DimensionTypeParams, Entity, Measure +from dbt.contracts.graph.semantic_models import ( + Dimension, + DimensionTypeParams, + Entity, + Measure, + NonAdditiveDimension, +) from dbt.node_types import NodeType from dbt_semantic_interfaces.protocols import ( Dimension as DSIDimension, @@ -20,7 +26,11 @@ SemanticModel as DSISemanticModel, WhereFilter as DSIWhereFilter, ) +from dbt_semantic_interfaces.protocols.measure import ( + NonAdditiveDimensionParameters as DSINonAdditiveDimensionParameters, +) from dbt_semantic_interfaces.type_enums import ( + AggregationType, DimensionType, EntityType, MetricType, @@ -74,6 +84,11 @@ class RuntimeCheckableWhereFilter(DSIWhereFilter, Protocol): pass +@runtime_checkable +class RuntimeCheckableNonAdditiveDimension(DSINonAdditiveDimensionParameters, Protocol): + pass + + def test_semantic_model_node_satisfies_protocol(): test_semantic_model = SemanticModel( name="test_semantic_model", @@ -172,3 +187,12 @@ def test_metric_input_measure(): def test_metric_type_params_satisfies_protocol(): type_params = MetricTypeParams() assert isinstance(type_params, RuntimeCheckableMetricTypeParams) + + +def test_non_additive_dimension_satisfies_protocol(): + non_additive_dimension = NonAdditiveDimension( + name="dimension_name", + window_choice=AggregationType.MIN, + window_groupings=["entity_name"], + ) + assert isinstance(non_additive_dimension, RuntimeCheckableNonAdditiveDimension)