Skip to content

Commit

Permalink
Merge pull request #158 from dbt-labs/qmalcolm--143-support-label-att…
Browse files Browse the repository at this point in the history
…ribute

Support `label` attribute
  • Loading branch information
QMalcolm authored Oct 6, 2023
2 parents b0da545 + ff2d7e5 commit b306a5b
Show file tree
Hide file tree
Showing 26 changed files with 896 additions and 96 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230926-173230.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Begin supporting `label` attr on top level objects and semantic model elements
time: 2023-09-26T17:32:30.099904-07:00
custom:
Author: QMalcolm
Issue: "143"
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class PydanticDimension(HashableBaseModel, ModelWithMetadataParsing):
type_params: Optional[PydanticDimensionTypeParams]
expr: Optional[str] = None
metadata: Optional[PydanticMetadata]
label: Optional[str] = None

@property
def reference(self) -> DimensionReference: # noqa: D
Expand Down
1 change: 1 addition & 0 deletions dbt_semantic_interfaces/implementations/elements/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class PydanticEntity(HashableBaseModel, ModelWithMetadataParsing):
role: Optional[str]
expr: Optional[str] = None
metadata: Optional[PydanticMetadata] = None
label: Optional[str] = None

@property
def reference(self) -> EntityReference: # noqa: D
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class PydanticMeasure(HashableBaseModel, ModelWithMetadataParsing):
metadata: Optional[PydanticMetadata]
non_additive_dimension: Optional[PydanticNonAdditiveDimensionParameters] = None
agg_time_dimension: Optional[str] = None
label: Optional[str] = None

@property
def reference(self) -> MeasureReference: # noqa: D
Expand Down
1 change: 1 addition & 0 deletions dbt_semantic_interfaces/implementations/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class PydanticMetric(HashableBaseModel, ModelWithMetadataParsing):
type_params: PydanticMetricTypeParams
filter: Optional[PydanticWhereFilter]
metadata: Optional[PydanticMetadata]
label: Optional[str] = None

@property
def input_measures(self) -> Sequence[PydanticMetricInputMeasure]:
Expand Down
1 change: 1 addition & 0 deletions dbt_semantic_interfaces/implementations/saved_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ def _implements_protocol(self) -> SavedQuery:

description: Optional[str] = None
metadata: Optional[PydanticMetadata] = None
label: Optional[str] = None
1 change: 1 addition & 0 deletions dbt_semantic_interfaces/implementations/semantic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def _implements_protocol(self) -> SemanticModel:
entities: Sequence[PydanticEntity] = []
measures: Sequence[PydanticMeasure] = []
dimensions: Sequence[PydanticDimension] = []
label: Optional[str] = None

metadata: Optional[PydanticMetadata]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
"is_partition": {
"type": "boolean"
},
"label": {
"type": "string"
},
"name": {
"pattern": "(?!.*__).*^[a-z][a-z0-9_]*[a-z0-9]$",
"type": "string"
Expand Down Expand Up @@ -107,6 +110,9 @@
"boolean"
]
},
"label": {
"type": "string"
},
"name": {
"pattern": "(?!.*__).*^[a-z][a-z0-9_]*[a-z0-9]$",
"type": "string"
Expand Down Expand Up @@ -195,6 +201,9 @@
"boolean"
]
},
"label": {
"type": "string"
},
"name": {
"pattern": "(?!.*__).*^[a-z][a-z0-9_]*[a-z0-9]$",
"type": "string"
Expand Down Expand Up @@ -270,6 +279,9 @@
"filter": {
"type": "string"
},
"label": {
"type": "string"
},
"name": {
"pattern": "(?!.*__).*^[a-z][a-z0-9_]*[a-z0-9]$",
"type": "string"
Expand Down Expand Up @@ -410,6 +422,9 @@
},
"type": "array"
},
"label": {
"type": "string"
},
"metrics": {
"items": {
"type": "string"
Expand Down Expand Up @@ -465,6 +480,9 @@
},
"type": "array"
},
"label": {
"type": "string"
},
"measures": {
"items": {
"$ref": "#/definitions/measure_schema"
Expand Down
6 changes: 6 additions & 0 deletions dbt_semantic_interfaces/parsing/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"role": {"type": "string"},
"expr": {"type": ["string", "boolean"]},
"entity": {"type": "string"},
"label": {"type": "string"},
},
"additionalProperties": False,
"required": ["name", "type"],
Expand Down Expand Up @@ -173,6 +174,7 @@
"$ref": "non_additive_dimension_schema",
},
"description": {"type": "string"},
"label": {"type": "string"},
},
"additionalProperties": False,
"required": ["name", "agg"],
Expand All @@ -191,6 +193,7 @@
"is_partition": {"type": "boolean"},
"expr": {"type": ["string", "boolean"]},
"type_params": {"$ref": "dimension_type_params_schema"},
"label": {"type": "string"},
},
# dimension must have type_params if its a time dimension
"anyOf": [{"not": {"$ref": "#/definitions/is-time-dimension"}}, {"required": ["type_params"]}],
Expand All @@ -217,6 +220,7 @@
"type_params": {"$ref": "metric_type_params"},
"filter": {"type": "string"},
"description": {"type": "string"},
"label": {"type": "string"},
},
"additionalProperties": False,
"required": ["name", "type", "type_params"],
Expand Down Expand Up @@ -292,6 +296,7 @@
"type": "array",
"items": {"type": "string"},
},
"label": {"type": "string"},
},
"required": ["name", "metrics"],
"additionalProperties": False,
Expand All @@ -314,6 +319,7 @@
"measures": {"type": "array", "items": {"$ref": "measure_schema"}},
"dimensions": {"type": "array", "items": {"$ref": "dimension_schema"}},
"description": {"type": "string"},
"label": {"type": "string"},
},
"additionalProperties": False,
"required": ["name"],
Expand Down
6 changes: 6 additions & 0 deletions dbt_semantic_interfaces/protocols/dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,9 @@ def time_dimension_reference(self) -> Optional[TimeDimensionReference]:
def validity_params(self) -> Optional[DimensionValidityParams]:
"""Returns the DimensionValidityParams if they exist for the dimension implementation."""
...

@property
@abstractmethod
def label(self) -> Optional[str]:
"""Returns a string representing a human readable label for the dimension."""
pass
6 changes: 6 additions & 0 deletions dbt_semantic_interfaces/protocols/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ def is_linkable_entity_type(self) -> bool:
keys reserved for SCD Type II style data sources.
"""
...

@property
@abstractmethod
def label(self) -> Optional[str]:
"""Returns a string representing a human readable label for the entity."""
pass
6 changes: 6 additions & 0 deletions dbt_semantic_interfaces/protocols/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,9 @@ def agg_time_dimension(self) -> Optional[str]: # noqa: D
def reference(self) -> MeasureReference:
"""Returns a reference to this measure."""
...

@property
@abstractmethod
def label(self) -> Optional[str]:
"""Returns a string representing a human readable label for the measure."""
pass
6 changes: 6 additions & 0 deletions dbt_semantic_interfaces/protocols/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,9 @@ def input_metrics(self) -> Sequence[MetricInput]:
@abstractmethod
def metadata(self) -> Optional[Metadata]: # noqa: D
pass

@property
@abstractmethod
def label(self) -> Optional[str]:
"""Returns a string representing a human readable label for the metric."""
pass
6 changes: 6 additions & 0 deletions dbt_semantic_interfaces/protocols/saved_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ def group_bys(self) -> Sequence[str]: # noqa: D
@abstractmethod
def where(self) -> Sequence[WhereFilter]: # noqa: D
pass

@property
@abstractmethod
def label(self) -> Optional[str]:
"""Returns a string representing a human readable label for the saved query."""
pass
6 changes: 6 additions & 0 deletions dbt_semantic_interfaces/protocols/semantic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,11 @@ def primary_entity_reference(self) -> Optional[EntityReference]:
"""Reference object form of primary_entity."""
pass

@property
@abstractmethod
def label(self) -> Optional[str]:
"""Returns a string representing a human readable label for the semantic model."""
pass


SemanticModelT = TypeVar("SemanticModelT", bound=SemanticModel)
Loading

0 comments on commit b306a5b

Please sign in to comment.