-
Notifications
You must be signed in to change notification settings - Fork 14
/
metric.py
109 lines (83 loc) · 3.52 KB
/
metric.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from __future__ import annotations
from abc import abstractmethod
from typing import List, Optional, Protocol
from dbt_semantic_interfaces.implementations.filters.where_filter import WhereFilter
from dbt_semantic_interfaces.references import MeasureReference, MetricReference
from dbt_semantic_interfaces.type_enums.metric_type import MetricType
from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity
class MetricInputMeasure(Protocol):
"""Provides a pointer to a measure along with metric-specific processing directives.
If an alias is set, this will be used as the string name reference for this measure after the aggregation
phase in the SQL plan.
"""
name: str
filter: Optional[WhereFilter]
alias: Optional[str]
@property
@abstractmethod
def measure_reference(self) -> MeasureReference:
"""Property accessor to get the MeasureReference associated with this metric input measure."""
...
@property
@abstractmethod
def post_aggregation_measure_reference(self) -> MeasureReference:
"""Property accessor to get the MeasureReference with the aliased name, if appropriate."""
...
class MetricTimeWindow(Protocol):
"""Describes the window of time the metric should be accumulated over, e.g., '1 day', '2 weeks', etc."""
count: int
granularity: TimeGranularity
class MetricInput(Protocol):
"""Provides a pointer to a metric along with the additional properties used on that metric."""
name: str
filter: Optional[WhereFilter]
alias: Optional[str]
offset_window: Optional[MetricTimeWindow]
offset_to_grain: Optional[TimeGranularity]
@property
@abstractmethod
def as_reference(self) -> MetricReference:
"""Property accessor to get the MetricReference associated with this metric input."""
...
class MetricTypeParams(Protocol):
"""Type params add additional context to certain metric types (the context depends on the metric type)."""
measure: Optional[MetricInputMeasure]
measures: Optional[List[MetricInputMeasure]]
numerator: Optional[MetricInputMeasure]
denominator: Optional[MetricInputMeasure]
expr: Optional[str]
window: Optional[MetricTimeWindow]
grain_to_date: Optional[TimeGranularity]
metrics: Optional[List[MetricInput]]
@property
@abstractmethod
def numerator_measure_reference(self) -> Optional[MeasureReference]:
"""Return the measure reference, if any, associated with the metric input measure defined as the numerator."""
...
@property
@abstractmethod
def denominator_measure_reference(self) -> Optional[MeasureReference]:
"""Return the measure reference, if any, associated with the metric input measure defined as the denominator."""
...
class Metric(Protocol):
"""Describes a metric."""
name: str
description: Optional[str]
type: MetricType
type_params: MetricTypeParams
filter: Optional[WhereFilter]
@property
@abstractmethod
def input_measures(self: Metric) -> List[MetricInputMeasure]:
"""Return the complete list of input measure configurations for this metric."""
...
@property
@abstractmethod
def measure_references(self) -> List[MeasureReference]:
"""Return the measure references associated with all input measure configurations for this metric."""
...
@property
@abstractmethod
def input_metrics(self) -> List[MetricInput]:
"""Return the associated input metrics for this metric."""
...