Skip to content

Commit

Permalink
Update custom granularity spec (#340)
Browse files Browse the repository at this point in the history
### Description
Rename `custom_granularity_columns` -> `custom_granularities` and add
`column_name` property. This matches the newly-approved spec that will
be added to core.
This would be a breaking change, but since this isn't used anywhere yet,
nothing will break.
<!---
Describe the Pull Request here. Add any references and info to help
reviewers
  understand your changes. Include any tradeoffs you considered.
-->

### Checklist

- [x] I have read [the contributing
guide](https://github.com/dbt-labs/dbt-semantic-interfaces/blob/main/CONTRIBUTING.md)
and understand what's expected of me
- [x] I have signed the
[CLA](https://docs.getdbt.com/docs/contributor-license-agreements)
- [x] This PR includes tests, or tests are not required/relevant for
this PR
- [ ] I have run `changie new` to [create a changelog
entry](https://github.com/dbt-labs/dbt-semantic-interfaces/blob/main/CONTRIBUTING.md#adding-a-changelog-entry)
  • Loading branch information
courtneyholcomb authored Aug 29, 2024
1 parent 8b13be4 commit 3c4caef
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
5 changes: 3 additions & 2 deletions dbt_semantic_interfaces/implementations/time_spine.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Sequence
from typing import Optional, Sequence

from typing_extensions import override

Expand Down Expand Up @@ -32,6 +32,7 @@ def _implements_protocol(self) -> TimeSpineCustomGranularityColumn:
return self

name: str
column_name: Optional[str] = None


class PydanticTimeSpine(HashableBaseModel, ProtocolHint[TimeSpine]): # noqa: D101
Expand All @@ -41,4 +42,4 @@ def _implements_protocol(self) -> TimeSpine:

node_relation: PydanticNodeRelation
primary_column: PydanticTimeSpinePrimaryColumn
custom_granularity_columns: Sequence[PydanticTimeSpineCustomGranularityColumn] = []
custom_granularities: Sequence[PydanticTimeSpineCustomGranularityColumn] = []
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
"$id": "custom_granularity_column_schema",
"additionalProperties": false,
"properties": {
"column_name": {
"type": "string"
},
"name": {
"type": "string"
}
Expand Down Expand Up @@ -826,7 +829,7 @@
"$id": "time_spine_schema",
"additionalProperties": false,
"properties": {
"custom_granularity_columns": {
"custom_granularities": {
"items": {
"$ref": "#/definitions/custom_granularity_column_schema"
},
Expand Down
3 changes: 2 additions & 1 deletion dbt_semantic_interfaces/parsing/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@
"type": "object",
"properties": {
"name": {"type": "string"},
"column_name": {"type": "string"},
},
"additionalProperties": False,
"required": ["name"],
Expand All @@ -374,7 +375,7 @@
"properties": {
"node_relation": {"$ref": "node_relation_schema"},
"primary_column": {"$ref": "time_spine_primary_column_schema"},
"custom_granularity_columns": {
"custom_granularities": {
"type": "array",
"items": {"$ref": "custom_granularity_column_schema"},
},
Expand Down
10 changes: 8 additions & 2 deletions dbt_semantic_interfaces/protocols/time_spine.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from abc import abstractmethod
from typing import Protocol, Sequence
from typing import Optional, Protocol, Sequence

from dbt_semantic_interfaces.implementations.node_relation import NodeRelation
from dbt_semantic_interfaces.type_enums import TimeGranularity
Expand All @@ -28,7 +28,7 @@ def primary_column(self) -> TimeSpinePrimaryColumn:

@property
@abstractmethod
def custom_granularity_columns(self) -> Sequence[TimeSpineCustomGranularityColumn]:
def custom_granularities(self) -> Sequence[TimeSpineCustomGranularityColumn]:
"""The columns in the time spine table that map to custom granularities."""
pass

Expand Down Expand Up @@ -57,3 +57,9 @@ class TimeSpineCustomGranularityColumn(Protocol):
def name(self) -> str:
"""The column name."""
pass

@property
@abstractmethod
def column_name(self) -> Optional[str]:
"""The column name."""
pass
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "dbt-semantic-interfaces"
version = "0.7.1.dev1"
version = "0.7.1.dev2"
description = 'The shared semantic layer definitions that dbt-core and MetricFlow use'
readme = "README.md"
requires-python = ">=3.8"
Expand Down
4 changes: 2 additions & 2 deletions tests/example_project_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
PydanticTimeSpine(
node_relation=PydanticNodeRelation(alias="day_time_spine", schema_name="stuff"),
primary_column=PydanticTimeSpinePrimaryColumn(name="ds_day", time_granularity=TimeGranularity.DAY),
custom_granularity_columns=[
custom_granularities=[
PydanticTimeSpineCustomGranularityColumn(name="retail_year"),
PydanticTimeSpineCustomGranularityColumn(name="martian_week"),
PydanticTimeSpineCustomGranularityColumn(name="martian_week", column_name="meep_meep_wk"),
],
)
],
Expand Down
8 changes: 4 additions & 4 deletions tests/validations/test_time_spines.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def test_valid_time_spines() -> None: # noqa: D
PydanticTimeSpine(
node_relation=PydanticNodeRelation(alias="time_spine", schema_name="my_fav_schema"),
primary_column=PydanticTimeSpinePrimaryColumn(name="ds", time_granularity=TimeGranularity.DAY),
custom_granularity_columns=[
custom_granularities=[
PydanticTimeSpineCustomGranularityColumn(name="retail_year"),
PydanticTimeSpineCustomGranularityColumn(name="martian_week"),
PydanticTimeSpineCustomGranularityColumn(name="martian_week", column_name="meep_meep_wk"),
],
),
PydanticTimeSpine(
Expand Down Expand Up @@ -127,9 +127,9 @@ def test_duplicate_time_spine_granularity() -> None: # noqa: D
PydanticTimeSpine(
node_relation=PydanticNodeRelation(alias="time_spine", schema_name="my_fav_schema"),
primary_column=PydanticTimeSpinePrimaryColumn(name="ds", time_granularity=TimeGranularity.SECOND),
custom_granularity_columns=[
custom_granularities=[
PydanticTimeSpineCustomGranularityColumn(name="retail_year"),
PydanticTimeSpineCustomGranularityColumn(name="martian_week"),
PydanticTimeSpineCustomGranularityColumn(name="martian_week", column_name="meep_meep_wk"),
],
),
PydanticTimeSpine(
Expand Down

0 comments on commit 3c4caef

Please sign in to comment.