Skip to content

Commit

Permalink
Assorted naming and type fixes.
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
plypaul committed Oct 24, 2023
1 parent a00ee84 commit 0d5d374
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
10 changes: 5 additions & 5 deletions dbt_semantic_interfaces/implementations/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class PydanticMetricInputMeasure(PydanticCustomInputParser, HashableBaseModel):
"""

name: str
filter: Optional[PydanticWhereFilterIntersection]
alias: Optional[str]
join_to_timespine: bool = False
fill_nulls_with: Optional[int] = None
filter: Optional[PydanticWhereFilterIntersection] = None
alias: Optional[str] = None
time_spine_join: bool = False
null_fill_value: Optional[float] = None

@classmethod
def _from_yaml_value(cls, input: PydanticParseableValueType) -> PydanticMetricInputMeasure:
Expand Down Expand Up @@ -124,7 +124,7 @@ class PydanticMetricInput(HashableBaseModel):
offset_to_grain: Optional[TimeGranularity]

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
"expr": {
"type": [
"string",
"integer",
"number",
"boolean"
]
},
Expand Down Expand Up @@ -244,17 +244,17 @@
"alias": {
"type": "string"
},
"fill_nulls_with": {
"type": "integer"
},
"filter": {
"$ref": "#/definitions/filter_schema"
},
"join_to_timespine": {
"type": "boolean"
},
"name": {
"type": "string"
},
"null_fill_value": {
"type": "number"
},
"time_spine_join": {
"type": "boolean"
}
},
"type": "object"
Expand Down
6 changes: 3 additions & 3 deletions dbt_semantic_interfaces/parsing/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
"name": {"type": "string"},
"filter": {"$ref": "filter_schema"},
"alias": {"type": "string"},
"join_to_timespine": {"type": "boolean"},
"fill_nulls_with": {"type": "integer"},
"time_spine_join": {"type": "boolean"},
"null_fill_value": {"type": "number"},
},
"additionalProperties": False,
},
Expand Down Expand Up @@ -177,7 +177,7 @@
"type": "string",
"pattern": TRANSFORM_OBJECT_NAME_PATTERN,
},
"expr": {"type": ["string", "integer", "boolean"]},
"expr": {"type": ["string", "number", "boolean"]},
"agg_params": {"$ref": "aggregation_type_params_schema"},
"create_metric": {"type": "boolean"},
"create_metric_display_name": {"type": "string"},
Expand Down
8 changes: 4 additions & 4 deletions dbt_semantic_interfaces/protocols/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ def post_aggregation_measure_reference(self) -> MeasureReference:

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

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

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

@property
@abstractmethod
def as_reference(self) -> MetricReference:
def metric_reference(self) -> MetricReference:
"""Property accessor to get the MetricReference associated with this metric input."""
...

Expand Down
18 changes: 9 additions & 9 deletions dbt_semantic_interfaces/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class ElementReference(SerializableDataclass):
element_name: str


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

pass


@dataclass(frozen=True)
@dataclass(frozen=True, order=True)
class MeasureReference(ElementReference):
"""Used when we need to refer to a measure.
Expand All @@ -29,7 +29,7 @@ class MeasureReference(ElementReference):
pass


@dataclass(frozen=True)
@dataclass(frozen=True, order=True)
class DimensionReference(LinkableElementReference): # noqa: D
pass

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


@dataclass(frozen=True)
@dataclass(frozen=True, order=True)
class EntityReference(LinkableElementReference): # noqa: D
pass


@dataclass(frozen=True)
@dataclass(frozen=True, order=True)
class TimeDimensionReference(DimensionReference): # noqa: D
pass

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


@dataclass(frozen=True)
@dataclass(frozen=True, order=True)
class MetricReference(ElementReference): # noqa: D
pass

Expand All @@ -66,14 +66,14 @@ class ModelReference(SerializableDataclass):
pass


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

semantic_model_name: str


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


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

Expand Down
8 changes: 4 additions & 4 deletions tests/parsing/test_metric_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,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
time_spine_join: true
null_fill_value: 1
"""
)
file = YamlConfigFile(filepath="inline_for_test", contents=yaml_contents)
Expand All @@ -70,8 +70,8 @@ def test_legacy_metric_input_measure_object_parsing() -> None:
filter=PydanticWhereFilterIntersection(
where_filters=[PydanticWhereFilter(where_sql_template="""{{ dimension('some_bool') }}""")]
),
join_to_timespine=True,
fill_nulls_with=1,
time_spine_join=True,
null_fill_value=1,
)


Expand Down

0 comments on commit 0d5d374

Please sign in to comment.