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 0.2.latest] Support for null value coalescing #161

Merged
merged 4 commits into from
Oct 2, 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/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 @@ -46,6 +46,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
Loading