Skip to content

Commit 0d5d374

Browse files
committed
Assorted naming and type fixes.
* Use nouns for fields - `fill_nulls_with` -> `null_fill_value` * Update the type for the metric null fill value to allow for floats. * Rename MetricInput.as_reference -> MetricInput.metric_reference * `timespine` -> `time_spine` in variable names since it's 2 words.
1 parent a00ee84 commit 0d5d374

File tree

6 files changed

+32
-32
lines changed

6 files changed

+32
-32
lines changed

dbt_semantic_interfaces/implementations/metric.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ class PydanticMetricInputMeasure(PydanticCustomInputParser, HashableBaseModel):
2828
"""
2929

3030
name: str
31-
filter: Optional[PydanticWhereFilterIntersection]
32-
alias: Optional[str]
33-
join_to_timespine: bool = False
34-
fill_nulls_with: Optional[int] = None
31+
filter: Optional[PydanticWhereFilterIntersection] = None
32+
alias: Optional[str] = None
33+
time_spine_join: bool = False
34+
null_fill_value: Optional[float] = None
3535

3636
@classmethod
3737
def _from_yaml_value(cls, input: PydanticParseableValueType) -> PydanticMetricInputMeasure:
@@ -124,7 +124,7 @@ class PydanticMetricInput(HashableBaseModel):
124124
offset_to_grain: Optional[TimeGranularity]
125125

126126
@property
127-
def as_reference(self) -> MetricReference:
127+
def metric_reference(self) -> MetricReference:
128128
"""Property accessor to get the MetricReference associated with this metric input."""
129129
return MetricReference(element_name=self.name)
130130

dbt_semantic_interfaces/parsing/generated_json_schemas/default_explicit_schema.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
"expr": {
212212
"type": [
213213
"string",
214-
"integer",
214+
"number",
215215
"boolean"
216216
]
217217
},
@@ -244,17 +244,17 @@
244244
"alias": {
245245
"type": "string"
246246
},
247-
"fill_nulls_with": {
248-
"type": "integer"
249-
},
250247
"filter": {
251248
"$ref": "#/definitions/filter_schema"
252249
},
253-
"join_to_timespine": {
254-
"type": "boolean"
255-
},
256250
"name": {
257251
"type": "string"
252+
},
253+
"null_fill_value": {
254+
"type": "number"
255+
},
256+
"time_spine_join": {
257+
"type": "boolean"
258258
}
259259
},
260260
"type": "object"

dbt_semantic_interfaces/parsing/schemas.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
"name": {"type": "string"},
6161
"filter": {"$ref": "filter_schema"},
6262
"alias": {"type": "string"},
63-
"join_to_timespine": {"type": "boolean"},
64-
"fill_nulls_with": {"type": "integer"},
63+
"time_spine_join": {"type": "boolean"},
64+
"null_fill_value": {"type": "number"},
6565
},
6666
"additionalProperties": False,
6767
},
@@ -177,7 +177,7 @@
177177
"type": "string",
178178
"pattern": TRANSFORM_OBJECT_NAME_PATTERN,
179179
},
180-
"expr": {"type": ["string", "integer", "boolean"]},
180+
"expr": {"type": ["string", "number", "boolean"]},
181181
"agg_params": {"$ref": "aggregation_type_params_schema"},
182182
"create_metric": {"type": "boolean"},
183183
"create_metric_display_name": {"type": "string"},

dbt_semantic_interfaces/protocols/metric.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ def post_aggregation_measure_reference(self) -> MeasureReference:
4646

4747
@property
4848
@abstractmethod
49-
def join_to_timespine(self) -> bool:
50-
"""If the measure should be joined to the timespine."""
49+
def time_spine_join(self) -> bool:
50+
"""If the measure should be joined to the time spine."""
5151
pass
5252

5353
@property
5454
@abstractmethod
55-
def fill_nulls_with(self) -> Optional[int]:
55+
def null_fill_value(self) -> Optional[float]:
5656
"""What null values should be filled with if set."""
5757
pass
5858

@@ -102,7 +102,7 @@ def offset_to_grain(self) -> Optional[TimeGranularity]: # noqa: D
102102

103103
@property
104104
@abstractmethod
105-
def as_reference(self) -> MetricReference:
105+
def metric_reference(self) -> MetricReference:
106106
"""Property accessor to get the MetricReference associated with this metric input."""
107107
...
108108

dbt_semantic_interfaces/references.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ class ElementReference(SerializableDataclass):
1212
element_name: str
1313

1414

15-
@dataclass(frozen=True)
15+
@dataclass(frozen=True, order=True)
1616
class LinkableElementReference(ElementReference):
1717
"""Used when we need to refer to a dimension or entity, but other attributes are unknown."""
1818

1919
pass
2020

2121

22-
@dataclass(frozen=True)
22+
@dataclass(frozen=True, order=True)
2323
class MeasureReference(ElementReference):
2424
"""Used when we need to refer to a measure.
2525
@@ -29,7 +29,7 @@ class MeasureReference(ElementReference):
2929
pass
3030

3131

32-
@dataclass(frozen=True)
32+
@dataclass(frozen=True, order=True)
3333
class DimensionReference(LinkableElementReference): # noqa: D
3434
pass
3535

@@ -38,20 +38,20 @@ def time_dimension_reference(self) -> TimeDimensionReference: # noqa: D
3838
return TimeDimensionReference(element_name=self.element_name)
3939

4040

41-
@dataclass(frozen=True)
41+
@dataclass(frozen=True, order=True)
4242
class EntityReference(LinkableElementReference): # noqa: D
4343
pass
4444

4545

46-
@dataclass(frozen=True)
46+
@dataclass(frozen=True, order=True)
4747
class TimeDimensionReference(DimensionReference): # noqa: D
4848
pass
4949

5050
def dimension_reference(self) -> DimensionReference: # noqa: D
5151
return DimensionReference(element_name=self.element_name)
5252

5353

54-
@dataclass(frozen=True)
54+
@dataclass(frozen=True, order=True)
5555
class MetricReference(ElementReference): # noqa: D
5656
pass
5757

@@ -66,14 +66,14 @@ class ModelReference(SerializableDataclass):
6666
pass
6767

6868

69-
@dataclass(frozen=True)
69+
@dataclass(frozen=True, order=True)
7070
class SemanticModelReference(ModelReference):
7171
"""A reference to a semantic model definition in the model."""
7272

7373
semantic_model_name: str
7474

7575

76-
@dataclass(frozen=True)
76+
@dataclass(frozen=True, order=True)
7777
class SemanticModelElementReference(ModelReference):
7878
"""A reference to an element definition in a semantic model definition in the model.
7979
@@ -101,7 +101,7 @@ def is_from(self, ref: SemanticModelReference) -> bool:
101101
return self.semantic_model_name == ref.semantic_model_name
102102

103103

104-
@dataclass(frozen=True)
104+
@dataclass(frozen=True, order=True)
105105
class MetricModelReference(ModelReference):
106106
"""A reference to a metric definition in the model."""
107107

tests/parsing/test_metric_parsing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def test_legacy_metric_input_measure_object_parsing() -> None:
5555
measure:
5656
name: legacy_measure_from_object
5757
filter: "{{ dimension('some_bool') }}"
58-
join_to_timespine: true
59-
fill_nulls_with: 1
58+
time_spine_join: true
59+
null_fill_value: 1
6060
"""
6161
)
6262
file = YamlConfigFile(filepath="inline_for_test", contents=yaml_contents)
@@ -70,8 +70,8 @@ def test_legacy_metric_input_measure_object_parsing() -> None:
7070
filter=PydanticWhereFilterIntersection(
7171
where_filters=[PydanticWhereFilter(where_sql_template="""{{ dimension('some_bool') }}""")]
7272
),
73-
join_to_timespine=True,
74-
fill_nulls_with=1,
73+
time_spine_join=True,
74+
null_fill_value=1,
7575
)
7676

7777

0 commit comments

Comments
 (0)