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
{{ message }}
Repository navigation
sql: two-layer nested aggregation (subquery in FROM) is rejected #819
A two-layer SQL query (an aggregation over a subquery that aggregates the table) is rejected. The pattern parser accepts it, but SQLPatternMatcher::query_info_to_pattern returns QueryError::NestedQueryUnsupported for any query with more than one layer, and the planner rejects it with nested SQL queries are not supported (n=2).
SELECT job, SUM(v) FROM (
SELECT job, instance, SUM(value) AS v FROM data
WHEREtime BETWEEN DATEADD(s, -1, NOW()) AND NOW()
GROUP BY job, instance
) GROUP BY job
Equivalent PromQL: sum by (job) (sum by (job, instance) (data))
The PromQL path executes these through the native aggregation DAG; the SQL path has no equivalent.
More examples:
SQL outer layer over the subquery above
PromQL
SELECT job, QUANTILE(0.9, v) FROM (...) GROUP BY job
quantile by (job) (0.9, sum by (job, instance) (data))
SELECT job, AVG(v) FROM (...) GROUP BY job
avg by (job) (sum by (job, instance) (data))
SELECT L1, AVG(result) FROM (SELECT L1, L2, QUANTILE(0.95, value) AS result ... GROUP BY L1, L2) GROUP BY L1
avg by (L1) (quantile_over_time(0.95, cpu_usage[10s]))
Reproduce
cargo test -p query_engine_rust --test sql_compliance -- --nocapture; see one-stage-* in nested-aggregations.yaml.
Activity
feat(sql-parser): match two-layer nested aggregation queries
feat(planner): plan two-layer SQL queries as inner query plus query-t…
feat(query-engine): serve two-layer SQL queries via query-time aggreg…
feat(sql-parser): support two-layer nested aggregation queries (#892)