Per-identity expression for the unit_values CTE SELECT.
(self)
| 83 | ) |
| 84 | |
| 85 | def unit_select(self) -> str: |
| 86 | """Per-identity expression for the unit_values CTE SELECT.""" |
| 87 | cond = self._condition() |
| 88 | agg = self.spec.aggregation |
| 89 | if agg == MetricAggregation.OCCURRENCE: |
| 90 | return f"countIf({cond}) > 0 AS {self._alias}" |
| 91 | if agg == MetricAggregation.COUNT: |
| 92 | return f"countIf({cond}) AS {self._alias}" |
| 93 | if agg == MetricAggregation.SUM: |
| 94 | return f"sumIf({_FLOAT_VALUE}, {cond}) AS {self._alias}" |
| 95 | if agg == MetricAggregation.MEAN: |
| 96 | return ( |
| 97 | f"if(countIf({cond}) > 0, avgIf({_FLOAT_VALUE}, {cond}), 0)" |
| 98 | f" AS {self._alias}" |
| 99 | ) |
| 100 | raise ValueError(f"Unsupported metric aggregation: {agg}") |
| 101 | |
| 102 | def outer_select(self) -> str: |
| 103 | """Sufficient-stat aggregates for the final SELECT.""" |