You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix aggregation parsing for complex expressions (#31)
- Replace greedy regex with sqlglot in Metric class to properly handle
expressions like SUM(x) / SUM(y) without mangling them
- Fix COUNT DISTINCT detection using isinstance(parsed.this, exp.Distinct)
- Add expression metric support in SQL generator for metrics with inline
aggregations (agg=None, type=None, sql=<expression>)
- Fix dependency analyzer to skip resolution for expression metrics with
inline aggregations
- Fix cumulative metrics to properly resolve references to other measures
and generate valid aliases
Add kitchen sink tests using patterns from rill-examples to catch edge cases.
window_expr=f"{agg_func}({base_col}) OVER (PARTITION BY {partition} ORDER BY {time_dim} ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS {m}"
2183
+
window_expr=f"{agg_func}({base_col}) OVER (PARTITION BY {partition} ORDER BY {time_dim} ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS {metric_alias}"
2149
2184
elifmetric.window:
2150
2185
# Parse window (e.g., "7 days")
2151
2186
window_parts=metric.window.split()
2152
2187
iflen(window_parts) ==2:
2153
2188
num, unit=window_parts
2154
2189
# For date-based windows, use RANGE
2155
-
window_expr=f"{agg_func}({base_col}) OVER (ORDER BY {time_dim} RANGE BETWEEN INTERVAL '{num}{unit}' PRECEDING AND CURRENT ROW) AS {m}"
2190
+
window_expr=f"{agg_func}({base_col}) OVER (ORDER BY {time_dim} RANGE BETWEEN INTERVAL '{num}{unit}' PRECEDING AND CURRENT ROW) AS {metric_alias}"
2156
2191
else:
2157
2192
# Fallback to rows
2158
-
window_expr=f"{agg_func}({base_col}) OVER (ORDER BY {time_dim} ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS {m}"
2193
+
window_expr=f"{agg_func}({base_col}) OVER (ORDER BY {time_dim} ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS {metric_alias}"
2159
2194
else:
2160
2195
# Running total (unbounded window)
2161
-
window_expr=f"{agg_func}({base_col}) OVER (ORDER BY {time_dim} ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS {m}"
2196
+
window_expr=f"{agg_func}({base_col}) OVER (ORDER BY {time_dim} ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS {metric_alias}"
0 commit comments