From 70aaeace15737aa79a17031071671ec0f4ee3a62 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 29 Aug 2024 11:24:32 -0700 Subject: [PATCH 1/3] Rename custom_granularity_columns -> custom_granularities and add column_name property --- dbt_semantic_interfaces/implementations/time_spine.py | 5 +++-- .../generated_json_schemas/default_explicit_schema.json | 5 ++++- dbt_semantic_interfaces/parsing/schemas.py | 3 ++- dbt_semantic_interfaces/protocols/time_spine.py | 2 +- tests/example_project_configuration.py | 4 ++-- tests/validations/test_time_spines.py | 8 ++++---- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/dbt_semantic_interfaces/implementations/time_spine.py b/dbt_semantic_interfaces/implementations/time_spine.py index b1364f74..dd249ff2 100644 --- a/dbt_semantic_interfaces/implementations/time_spine.py +++ b/dbt_semantic_interfaces/implementations/time_spine.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Sequence +from typing import Optional, Sequence from typing_extensions import override @@ -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 @@ -41,4 +42,4 @@ def _implements_protocol(self) -> TimeSpine: node_relation: PydanticNodeRelation primary_column: PydanticTimeSpinePrimaryColumn - custom_granularity_columns: Sequence[PydanticTimeSpineCustomGranularityColumn] = [] + custom_granularities: Sequence[PydanticTimeSpineCustomGranularityColumn] = [] diff --git a/dbt_semantic_interfaces/parsing/generated_json_schemas/default_explicit_schema.json b/dbt_semantic_interfaces/parsing/generated_json_schemas/default_explicit_schema.json index a622c927..613bffd7 100644 --- a/dbt_semantic_interfaces/parsing/generated_json_schemas/default_explicit_schema.json +++ b/dbt_semantic_interfaces/parsing/generated_json_schemas/default_explicit_schema.json @@ -123,6 +123,9 @@ "$id": "custom_granularity_column_schema", "additionalProperties": false, "properties": { + "column_name": { + "type": "string" + }, "name": { "type": "string" } @@ -826,7 +829,7 @@ "$id": "time_spine_schema", "additionalProperties": false, "properties": { - "custom_granularity_columns": { + "custom_granularities": { "items": { "$ref": "#/definitions/custom_granularity_column_schema" }, diff --git a/dbt_semantic_interfaces/parsing/schemas.py b/dbt_semantic_interfaces/parsing/schemas.py index 82492931..66652535 100644 --- a/dbt_semantic_interfaces/parsing/schemas.py +++ b/dbt_semantic_interfaces/parsing/schemas.py @@ -363,6 +363,7 @@ "type": "object", "properties": { "name": {"type": "string"}, + "column_name": {"type": "string"}, }, "additionalProperties": False, "required": ["name"], @@ -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"}, }, diff --git a/dbt_semantic_interfaces/protocols/time_spine.py b/dbt_semantic_interfaces/protocols/time_spine.py index 9b1a0ce8..2760d0cf 100644 --- a/dbt_semantic_interfaces/protocols/time_spine.py +++ b/dbt_semantic_interfaces/protocols/time_spine.py @@ -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 diff --git a/tests/example_project_configuration.py b/tests/example_project_configuration.py index 98c27b69..71f407bf 100644 --- a/tests/example_project_configuration.py +++ b/tests/example_project_configuration.py @@ -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"), ], ) ], diff --git a/tests/validations/test_time_spines.py b/tests/validations/test_time_spines.py index 3084667d..6c9d229e 100644 --- a/tests/validations/test_time_spines.py +++ b/tests/validations/test_time_spines.py @@ -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( @@ -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( From 5bd0d7eef22556e1b6239432269e5f0e95f69f99 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 29 Aug 2024 11:25:01 -0700 Subject: [PATCH 2/3] Bump dev version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index bb691acd..b92555c6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" From 6ff01666f2171946630157727dc26c4e0184c75a Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 29 Aug 2024 11:38:14 -0700 Subject: [PATCH 3/3] Add column_name to protocol --- dbt_semantic_interfaces/protocols/time_spine.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dbt_semantic_interfaces/protocols/time_spine.py b/dbt_semantic_interfaces/protocols/time_spine.py index 2760d0cf..7f4db13f 100644 --- a/dbt_semantic_interfaces/protocols/time_spine.py +++ b/dbt_semantic_interfaces/protocols/time_spine.py @@ -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 @@ -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