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

[CT-2821] Support dbt-semantic-interfaces~=0.1.0rc1 #8085

Merged
merged 5 commits into from
Jul 13, 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-20230712-165219.yaml
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230712-172037.yaml
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 6 additions & 0 deletions core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/contracts/graph/semantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class MeasureAggregationParameters(dbtClassMixin):
class NonAdditiveDimension(dbtClassMixin):
name: str
window_choice: AggregationType
window_grouples: List[str]
window_groupings: List[str]


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/contracts/graph/unparsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/schema_yaml_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
39 changes: 38 additions & 1 deletion tests/unit/test_semantic_layer_nodes_satisfy_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -18,8 +24,13 @@
MetricInputMeasure as DSIMetricInputMeasure,
MetricTypeParams as DSIMetricTypeParams,
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,
Expand Down Expand Up @@ -68,6 +79,16 @@ class RuntimeCheckableMetricTypeParams(DSIMetricTypeParams, Protocol):
pass


@runtime_checkable
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",
Expand Down Expand Up @@ -146,6 +167,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)
Expand All @@ -159,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)