MCPcopy Create free account
hub / github.com/Flagsmith/flagsmith / unit_select

Method unit_select

api/experimentation/results_query.py:85–100  ·  view source on GitHub ↗

Per-identity expression for the unit_values CTE SELECT.

(self)

Source from the content-addressed store, hash-verified

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."""

Calls 1

_conditionMethod · 0.95