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

Update custom granularity spec #340

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
2 changes: 1 addition & 1 deletion dbt_semantic_interfaces/protocols/time_spine.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def primary_column(self) -> TimeSpinePrimaryColumn:

@property
@abstractmethod
def custom_granularity_columns(self) -> Sequence[TimeSpineCustomGranularityColumn]:
def custom_granularities(self) -> Sequence[TimeSpineCustomGranularityColumn]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to add column_name to the protocol defined on line 52?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops you're right!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

"""The columns in the time spine table that map to custom granularities."""
pass

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