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

Consolidated meta config to use the same models #361

Merged
merged 16 commits into from
Nov 12, 2024
Merged
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
Next Next commit
Add meta to measures, entities, and dimensions
DevonFulcher committed Oct 23, 2024
commit f6fea48430784bb072d5d6f77e0ae742b4413bbd
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20241023-113450.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Support meta for dimensions, entities, and measures
time: 2024-10-23T11:34:50.577294-05:00
custom:
Author: DevonFulcher
Issue: None
18 changes: 17 additions & 1 deletion dbt_semantic_interfaces/implementations/elements/dimension.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
from __future__ import annotations

from typing import Optional
from typing import Any, Dict, Optional

from pydantic import Field
from typing_extensions import override

from dbt_semantic_interfaces.implementations.base import (
HashableBaseModel,
ModelWithMetadataParsing,
)
from dbt_semantic_interfaces.implementations.metadata import PydanticMetadata
from dbt_semantic_interfaces.protocols.dimension import DimensionConfig
from dbt_semantic_interfaces.protocols.protocol_hint import ProtocolHint
from dbt_semantic_interfaces.references import (
DimensionReference,
TimeDimensionReference,
@@ -37,6 +42,16 @@ class PydanticDimensionTypeParams(HashableBaseModel):
validity_params: Optional[PydanticDimensionValidityParams] = None


class PydanticDimensionConfig(HashableBaseModel, ProtocolHint[DimensionConfig]):
"""PydanticDimension config."""

@override
def _implements_protocol(self) -> DimensionConfig: # noqa: D
return self

meta: Dict[str, Any] = Field(default_factory=dict)


class PydanticDimension(HashableBaseModel, ModelWithMetadataParsing):
"""Describes a dimension."""

@@ -48,6 +63,7 @@ class PydanticDimension(HashableBaseModel, ModelWithMetadataParsing):
expr: Optional[str] = None
metadata: Optional[PydanticMetadata]
label: Optional[str] = None
config: Optional[PydanticDimensionConfig]

@property
def reference(self) -> DimensionReference: # noqa: D
18 changes: 17 additions & 1 deletion dbt_semantic_interfaces/implementations/elements/entity.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
from __future__ import annotations

from typing import Optional
from typing import Any, Dict, Optional

from pydantic import Field
from typing_extensions import override

from dbt_semantic_interfaces.implementations.base import (
HashableBaseModel,
ModelWithMetadataParsing,
)
from dbt_semantic_interfaces.implementations.metadata import PydanticMetadata
from dbt_semantic_interfaces.protocols.entity import EntityConfig
from dbt_semantic_interfaces.protocols.protocol_hint import ProtocolHint
from dbt_semantic_interfaces.references import EntityReference
from dbt_semantic_interfaces.type_enums import EntityType


class PydanticEntityConfig(HashableBaseModel, ProtocolHint[EntityConfig]):
"""PydanticEntity config."""

@override
def _implements_protocol(self) -> EntityConfig: # noqa: D
return self

meta: Dict[str, Any] = Field(default_factory=dict)


class PydanticEntity(HashableBaseModel, ModelWithMetadataParsing):
"""Describes a entity."""

@@ -21,6 +36,7 @@ class PydanticEntity(HashableBaseModel, ModelWithMetadataParsing):
expr: Optional[str] = None
metadata: Optional[PydanticMetadata] = None
label: Optional[str] = None
config: Optional[PydanticEntityConfig]

@property
def reference(self) -> EntityReference: # noqa: D
17 changes: 16 additions & 1 deletion dbt_semantic_interfaces/implementations/elements/measure.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from __future__ import annotations

from typing import List, Optional
from typing import Any, Dict, List, Optional

from typing_extensions import override

from dbt_semantic_interfaces.implementations.base import (
HashableBaseModel,
ModelWithMetadataParsing,
)
from dbt_semantic_interfaces.implementations.metadata import PydanticMetadata
from dbt_semantic_interfaces.protocols.measure import MeasureConfig
from dbt_semantic_interfaces.protocols.protocol_hint import ProtocolHint
from dbt_semantic_interfaces.references import MeasureReference
from dbt_semantic_interfaces.type_enums import AggregationType
from dsi_pydantic_shim import Field
@@ -33,6 +37,16 @@ class PydanticMeasureAggregationParameters(HashableBaseModel):
use_approximate_percentile: bool = False


class PydanticMeasureConfig(HashableBaseModel, ProtocolHint[MeasureConfig]):
"""PydanticMeasure config."""

@override
def _implements_protocol(self) -> MeasureConfig: # noqa: D
return self

meta: Dict[str, Any] = Field(default_factory=dict)


class PydanticMeasure(HashableBaseModel, ModelWithMetadataParsing):
"""Describes a measure."""

@@ -46,6 +60,7 @@ class PydanticMeasure(HashableBaseModel, ModelWithMetadataParsing):
non_additive_dimension: Optional[PydanticNonAdditiveDimensionParameters] = None
agg_time_dimension: Optional[str] = None
label: Optional[str] = None
config: Optional[PydanticMeasureConfig] = None

@property
def reference(self) -> MeasureReference: # noqa: D
Original file line number Diff line number Diff line change
@@ -135,6 +135,19 @@
],
"type": "object"
},
"dimension_config_schema": {
"$id": "dimension_config_schema",
"additionalProperties": false,
"properties": {
"meta": {
"propertyNames": {
"type": "string"
},
"type": "object"
}
},
"type": "object"
},
"dimension_schema": {
"$id": "dimension_schema",
"additionalProperties": false,
@@ -151,6 +164,9 @@
}
],
"properties": {
"config": {
"$ref": "#/definitions/dimension_config_schema"
},
"description": {
"type": "string"
},
@@ -227,10 +243,26 @@
],
"type": "object"
},
"entity_config_schema": {
"$id": "entity_config_schema",
"additionalProperties": false,
"properties": {
"meta": {
"propertyNames": {
"type": "string"
},
"type": "object"
}
},
"type": "object"
},
"entity_schema": {
"$id": "entity_schema",
"additionalProperties": false,
"properties": {
"config": {
"$ref": "#/definitions/entity_config_schema"
},
"entity": {
"type": "string"
},
@@ -337,6 +369,19 @@
"type"
]
},
"measure_config_schema": {
"$id": "measure_config_schema",
"additionalProperties": false,
"properties": {
"meta": {
"propertyNames": {
"type": "string"
},
"type": "object"
}
},
"type": "object"
},
"measure_schema": {
"$id": "measure_schema",
"additionalProperties": false,
@@ -370,6 +415,9 @@
"pattern": "(?!.*__).*^[a-z][a-z0-9_]*[a-z0-9]$",
"type": "string"
},
"config": {
"$ref": "#/definitions/measure_config_schema"
},
"create_metric": {
"type": "boolean"
},
34 changes: 34 additions & 0 deletions dbt_semantic_interfaces/parsing/schemas.py
Original file line number Diff line number Diff line change
@@ -161,6 +161,16 @@
"additionalProperties": False,
}


entity_config_schema = {
"$id": "entity_config_schema",
"type": "object",
"properties": {
"meta": {"type": "object", "propertyNames": {"type": "string"}},
},
"additionalProperties": False,
}

entity_schema = {
"$id": "entity_schema",
"type": "object",
@@ -174,6 +184,7 @@
"expr": {"type": ["string", "boolean"]},
"entity": {"type": "string"},
"label": {"type": "string"},
"config": {"$ref": "entity_config_schema"},
},
"additionalProperties": False,
"required": ["name", "type"],
@@ -226,6 +237,15 @@
"additionalProperties": False,
}

measure_config_schema = {
"$id": "measure_config_schema",
"type": "object",
"properties": {
"meta": {"type": "object", "propertyNames": {"type": "string"}},
},
"additionalProperties": False,
}

measure_schema = {
"$id": "measure_schema",
"type": "object",
@@ -248,11 +268,21 @@
},
"description": {"type": "string"},
"label": {"type": "string"},
"config": {"$ref": "measure_config_schema"},
},
"additionalProperties": False,
"required": ["name", "agg"],
}

dimension_config_schema = {
"$id": "dimension_config_schema",
"type": "object",
"properties": {
"meta": {"type": "object", "propertyNames": {"type": "string"}},
},
"additionalProperties": False,
}

dimension_schema = {
"$id": "dimension_schema",
"type": "object",
@@ -267,6 +297,7 @@
"expr": {"type": ["string", "boolean"]},
"type_params": {"$ref": "dimension_type_params_schema"},
"label": {"type": "string"},
"config": {"$ref": "dimension_config_schema"},
},
# dimension must have type_params if its a time dimension
"anyOf": [{"not": {"$ref": "#/definitions/is-time-dimension"}}, {"required": ["type_params"]}],
@@ -529,6 +560,9 @@
saved_query_query_params_schema["$id"]: saved_query_query_params_schema,
semantic_model_config_schema["$id"]: semantic_model_config_schema,
metric_config_schema["$id"]: metric_config_schema,
dimension_config_schema["$id"]: dimension_config_schema,
entity_config_schema["$id"]: entity_config_schema,
measure_config_schema["$id"]: measure_config_schema,
}

resources: List[Tuple[str, Resource]] = [(str(k), DRAFT7.create_resource(v)) for k, v in schema_store.items()]
17 changes: 16 additions & 1 deletion dbt_semantic_interfaces/protocols/dimension.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 Optional, Protocol
from typing import Any, Dict, Optional, Protocol

from dbt_semantic_interfaces.protocols.metadata import Metadata
from dbt_semantic_interfaces.references import (
@@ -46,6 +46,16 @@ def validity_params(self) -> Optional[DimensionValidityParams]: # noqa: D
pass


class DimensionConfig(Protocol): # noqa: D
"""The config property allows you to configure additional resources/metadata."""

@property
@abstractmethod
def meta(self) -> Dict[str, Any]:
"""The meta field can be used to set metadata for a resource."""
pass


class Dimension(Protocol):
"""Describes a dimension."""

@@ -107,3 +117,8 @@ def validity_params(self) -> Optional[DimensionValidityParams]:
def label(self) -> Optional[str]:
"""Returns a string representing a human readable label for the dimension."""
pass

@property
@abstractmethod
def config(self) -> Optional[DimensionConfig]: # noqa: D
pass
17 changes: 16 additions & 1 deletion dbt_semantic_interfaces/protocols/entity.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
from __future__ import annotations

from abc import abstractmethod
from typing import Optional, Protocol
from typing import Any, Dict, Optional, Protocol

from dbt_semantic_interfaces.references import EntityReference
from dbt_semantic_interfaces.type_enums import EntityType


class EntityConfig(Protocol): # noqa: D
"""The config property allows you to configure additional resources/metadata."""

@property
@abstractmethod
def meta(self) -> Dict[str, Any]:
"""The meta field can be used to set metadata for a resource."""
pass


class Entity(Protocol):
"""Describes a entity."""

@@ -60,3 +70,8 @@ def is_linkable_entity_type(self) -> bool:
def label(self) -> Optional[str]:
"""Returns a string representing a human readable label for the entity."""
pass

@property
@abstractmethod
def config(self) -> Optional[EntityConfig]: # noqa: D
pass
Loading