NOTE: Feast-handled aggregations are not yet supported. This class provides a way to register user-defined aggregations. Attributes: column: str # Column name of the feature we are aggregating. function: str # Provided built in aggregations sum, max, min, count, mean, cou
| 13 | |
| 14 | @typechecked |
| 15 | class Aggregation: |
| 16 | """ |
| 17 | NOTE: Feast-handled aggregations are not yet supported. This class provides a way to register user-defined aggregations. |
| 18 | |
| 19 | Attributes: |
| 20 | column: str # Column name of the feature we are aggregating. |
| 21 | function: str # Provided built in aggregations sum, max, min, count, mean, count_distinct |
| 22 | time_window: timedelta # The time window for this aggregation. |
| 23 | slide_interval: timedelta # The sliding window for these aggregations |
| 24 | name: str # Optional override for the output feature name (defaults to {function}_{column}) |
| 25 | """ |
| 26 | |
| 27 | column: str |
| 28 | function: str |
| 29 | time_window: Optional[timedelta] |
| 30 | slide_interval: Optional[timedelta] |
| 31 | name: str |
| 32 | |
| 33 | def __init__( |
| 34 | self, |
| 35 | column: Optional[str] = "", |
| 36 | function: Optional[str] = "", |
| 37 | time_window: Optional[timedelta] = None, |
| 38 | slide_interval: Optional[timedelta] = None, |
| 39 | name: Optional[str] = None, |
| 40 | ): |
| 41 | self.column = column or "" |
| 42 | self.function = function or "" |
| 43 | self.time_window = time_window |
| 44 | if not slide_interval: |
| 45 | self.slide_interval = self.time_window |
| 46 | else: |
| 47 | self.slide_interval = slide_interval |
| 48 | self.name = name or "" |
| 49 | |
| 50 | def to_proto(self) -> AggregationProto: |
| 51 | window_duration = None |
| 52 | if self.time_window is not None: |
| 53 | window_duration = Duration() |
| 54 | window_duration.FromTimedelta(self.time_window) |
| 55 | |
| 56 | slide_interval_duration = None |
| 57 | if self.slide_interval is not None: |
| 58 | slide_interval_duration = Duration() |
| 59 | slide_interval_duration.FromTimedelta(self.slide_interval) |
| 60 | |
| 61 | return AggregationProto( |
| 62 | column=self.column, |
| 63 | function=self.function, |
| 64 | time_window=window_duration, |
| 65 | slide_interval=slide_interval_duration, |
| 66 | name=self.name, |
| 67 | ) |
| 68 | |
| 69 | @classmethod |
| 70 | def from_proto(cls, agg_proto: AggregationProto): |
| 71 | time_window = ( |
| 72 | timedelta(days=0) |
no outgoing calls