diff --git a/.changes/unreleased/Breaking Changes-20241108-215906.yaml b/.changes/unreleased/Breaking Changes-20241108-215906.yaml new file mode 100644 index 00000000..bd9906ff --- /dev/null +++ b/.changes/unreleased/Breaking Changes-20241108-215906.yaml @@ -0,0 +1,6 @@ +kind: Breaking Changes +body: Adding support for custom grain in windows/grain_to_dates +time: 2024-11-08T21:59:06.162076-05:00 +custom: + Author: WilliamDee + Issue: None diff --git a/dbt_semantic_interfaces/implementations/metric.py b/dbt_semantic_interfaces/implementations/metric.py index 02933e5a..204337a7 100644 --- a/dbt_semantic_interfaces/implementations/metric.py +++ b/dbt_semantic_interfaces/implementations/metric.py @@ -71,7 +71,7 @@ class PydanticMetricTimeWindow(PydanticCustomInputParser, HashableBaseModel): """Describes the window of time the metric should be accumulated over, e.g., '1 day', '2 weeks', etc.""" count: int - granularity: TimeGranularity + granularity: str @classmethod def _from_yaml_value(cls, input: PydanticParseableValueType) -> PydanticMetricTimeWindow: @@ -80,21 +80,31 @@ def _from_yaml_value(cls, input: PydanticParseableValueType) -> PydanticMetricTi The MetricTimeWindow is always expected to be provided as a string in user-defined YAML configs. """ if isinstance(input, str): - return PydanticMetricTimeWindow.parse(input) + return PydanticMetricTimeWindow.parse(window=input.lower(), custom_granularity_names=(), strict=False) else: raise ValueError( f"MetricTimeWindow inputs from model configs are expected to always be of type string, but got " f"type {type(input)} with value: {input}" ) + @property + def is_standard_granularity(self) -> bool: + """Returns whether the window uses standard TimeGranularity.""" + return self.granularity.casefold() in {item.value.casefold() for item in TimeGranularity} + + @property + def window_string(self) -> str: + """Returns the string value of the time window.""" + return f"{self.count} {self.granularity}" + @staticmethod - def parse(window: str) -> PydanticMetricTimeWindow: + def parse(window: str, custom_granularity_names: Sequence[str], strict: bool = True) -> PydanticMetricTimeWindow: """Returns window values if parsing succeeds, None otherwise. - Output of the form: (