Skip to content

Commit

Permalink
Add default_grain field to metric spec
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Jun 27, 2024
1 parent 25ede8b commit 5bc498f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions dbt_semantic_interfaces/implementations/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class PydanticMetric(HashableBaseModel, ModelWithMetadataParsing):
metadata: Optional[PydanticMetadata]
label: Optional[str] = None
config: Optional[PydanticMetricConfig]
default_grain: TimeGranularity = TimeGranularity.DAY

@property
def input_measures(self) -> Sequence[PydanticMetricInputMeasure]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,32 @@
"config": {
"$ref": "#/definitions/metric_config_schema"
},
"default_grain": {
"enum": [
"NANOSECOND",
"MICROSECOND",
"MILLISECOND",
"SECOND",
"MINUTE",
"HOUR",
"DAY",
"WEEK",
"MONTH",
"QUARTER",
"YEAR",
"nanosecond",
"microsecond",
"millisecond",
"second",
"minute",
"hour",
"day",
"week",
"month",
"quarter",
"year"
]
},
"description": {
"type": "string"
},
Expand Down
1 change: 1 addition & 0 deletions dbt_semantic_interfaces/parsing/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@
"description": {"type": "string"},
"label": {"type": "string"},
"config": {"$ref": "metric_config_schema"},
"default_grain": {"enum": time_granularity_values},
},
"additionalProperties": False,
"required": ["name", "type", "type_params"],
Expand Down
11 changes: 11 additions & 0 deletions dbt_semantic_interfaces/protocols/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,14 @@ def config(self) -> Optional[MetricConfig]: # noqa: D
def label(self) -> Optional[str]:
"""Returns a string representing a human readable label for the metric."""
pass

@property
@abstractmethod
def default_grain(self) -> TimeGranularity:
"""Default grain used for the metric.
This will be used in a couple of circumstances:
- as the default grain for metric_time if no grain is specified
- as the window function order by when reaggregating cumulative metrics for non-default grains
"""
pass
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ metric:
name: "trailing_2_months_revenue"
description: "trailing_2_months_revenue"
type: cumulative
default_grain: month
type_params:
measure:
name: txn_revenue
Expand Down

0 comments on commit 5bc498f

Please sign in to comment.