Skip to content

Commit

Permalink
Merge pull request #159 from dbt-labs/qmalcolm--142-null-value-coales…
Browse files Browse the repository at this point in the history
…cing-options

Add null value coalescing options to `MetricInputMeasure` protocol
  • Loading branch information
QMalcolm authored Sep 28, 2023
2 parents d3c26df + 98c13ca commit b0da545
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230926-182305.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Add options to protocol for null value coalescing
time: 2023-09-26T18:23:05.191433-07:00
custom:
Author: QMalcolm
Issue: "142"
2 changes: 2 additions & 0 deletions dbt_semantic_interfaces/implementations/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class PydanticMetricInputMeasure(PydanticCustomInputParser, HashableBaseModel):
name: str
filter: Optional[PydanticWhereFilter]
alias: Optional[str]
join_to_timespine: bool = False
fill_nulls_with: Optional[int] = None

@classmethod
def _from_yaml_value(cls, input: PydanticParseableValueType) -> PydanticMetricInputMeasure:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,15 @@
"alias": {
"type": "string"
},
"fill_nulls_with": {
"type": "integer"
},
"filter": {
"type": "string"
},
"join_to_timespine": {
"type": "boolean"
},
"name": {
"type": "string"
}
Expand Down
2 changes: 2 additions & 0 deletions dbt_semantic_interfaces/parsing/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
"name": {"type": "string"},
"filter": {"type": "string"},
"alias": {"type": "string"},
"join_to_timespine": {"type": "boolean"},
"fill_nulls_with": {"type": "integer"},
},
"additionalProperties": False,
},
Expand Down
12 changes: 12 additions & 0 deletions dbt_semantic_interfaces/protocols/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ def post_aggregation_measure_reference(self) -> MeasureReference:
"""Property accessor to get the MeasureReference with the aliased name, if appropriate."""
...

@property
@abstractmethod
def join_to_timespine(self) -> bool:
"""If the measure should be joined to the timespine."""
pass

@property
@abstractmethod
def fill_nulls_with(self) -> Optional[int]:
"""What null values should be filled with if set."""
pass


class MetricTimeWindow(Protocol):
"""Describes the window of time the metric should be accumulated over, e.g., '1 day', '2 weeks', etc."""
Expand Down
4 changes: 4 additions & 0 deletions tests/parsing/test_metric_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def test_legacy_metric_input_measure_object_parsing() -> None:
measure:
name: legacy_measure_from_object
filter: "{{ dimension('some_bool') }}"
join_to_timespine: true
fill_nulls_with: 1
"""
)
file = YamlConfigFile(filepath="inline_for_test", contents=yaml_contents)
Expand All @@ -65,6 +67,8 @@ def test_legacy_metric_input_measure_object_parsing() -> None:
assert metric.type_params.measure == PydanticMetricInputMeasure(
name="legacy_measure_from_object",
filter=PydanticWhereFilter(where_sql_template="""{{ dimension('some_bool') }}"""),
join_to_timespine=True,
fill_nulls_with=1,
)


Expand Down

0 comments on commit b0da545

Please sign in to comment.