Repository navigation
fix(sql-parser): accept global aggregates without GROUP BY #826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -847,11 +847,7 @@ impl SQLPatternParser { | |
| } | ||
| } | ||
|
|
||
| if group_bys.is_empty() { | ||
| None | ||
| } else { | ||
| Some(group_bys) | ||
| } | ||
| Some(group_bys) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [correctness] Global SUM/COUNT can match a label-keyed CMS via capability fallback ( Global aggregates now reach Scenario: the planner plans Suggested fix: require
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Fixed in c9bc666. Non-top-k global aggregates now require an exact query configuration instead of capability fallback, so a grouped CMS cannot be selected for an unlabeled scalar query. Added
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [correctness] Global COUNT also matches top-k CountMinSketchWithHeap configs (
Scenario:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Fixed by the same c9bc666 guard: a non-top-k global COUNT cannot capability-match a keyed heap configuration. Exact configurations remain eligible, and existing top-k capability-fallback tests still pass.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [correctness] Subquery path skips the unexpected-SELECT-fields check ( Inner subqueries without GROUP BY now parse, but the subquery branch never runs the DISTINCT/HAVING/QUALIFY check that the flat path applies. Scenario:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Deferred intentionally: this PR changes parsing only, while nested-query matching and execution remain unsupported. c9bc666 adds a matcher regression asserting
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [efficiency] Global SUM/COUNT plans a full CMS + DeltaSetAggregator for one scalar ( With zero aggregated labels, the planner allocates a multi-population CountMinSketch (width x depth) plus a key tracker for a population that is always one empty key. When
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Acknowledged and deferred. This PR is scoped to parser acceptance and safe execution of exact global configurations; choosing a cheaper single-population physical plan is a planner optimization and should be addressed separately. |
||
| } | ||
| _ => None, | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,7 +127,7 @@ cases: | |
|
|
||
| - name: sum | ||
| query: SELECT SUM(value) FROM data WHERE time BETWEEN DATEADD(s, -1, NOW()) AND NOW() | ||
| expected: unsupported | ||
| expected: supported | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [test-coverage] Newly supported cases don't check result values (applies to all ~30 flipped cases; runner at The runner only checks that an execution context gets built. Nothing ingests data and asserts that global SUM/COUNT/MIN/MAX/QUANTILE/COUNT(DISTINCT) combines all series. If the empty-grouping path returned one row per series or an empty result, every case would still pass. The parser tests only assert
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Fixed in c9bc666 with |
||
| - name: sum-by-job | ||
| query: SELECT job, SUM(value) FROM data WHERE time BETWEEN DATEADD(s, -1, NOW()) AND NOW() GROUP BY job | ||
| expected: supported | ||
|
|
@@ -136,7 +136,7 @@ cases: | |
| expected: supported | ||
| - name: count | ||
| query: SELECT COUNT(value) FROM data WHERE time BETWEEN DATEADD(s, -1, NOW()) AND NOW() | ||
| expected: unsupported | ||
| expected: supported | ||
| - name: count-by-job | ||
| query: SELECT job, COUNT(value) FROM data WHERE time BETWEEN DATEADD(s, -1, NOW()) AND NOW() GROUP BY job | ||
| expected: supported | ||
|
|
@@ -152,13 +152,13 @@ cases: | |
| expected: supported | ||
| - name: sum-sum-over-time | ||
| query: SELECT SUM(value) FROM data WHERE time BETWEEN DATEADD(s, -300, NOW()) AND NOW() | ||
| expected: unsupported | ||
| expected: supported | ||
| - name: sum-without-job-sum-over-time | ||
| query: SELECT instance, SUM(value) FROM data WHERE time BETWEEN DATEADD(s, -300, NOW()) AND NOW() GROUP BY instance | ||
| expected: supported | ||
| - name: sum-count-over-time | ||
| query: SELECT COUNT(value) FROM data WHERE time BETWEEN DATEADD(s, -300, NOW()) AND NOW() | ||
| expected: unsupported | ||
| expected: supported | ||
| - name: sum-by-job-count-over-time | ||
| query: SELECT job, COUNT(value) FROM data WHERE time BETWEEN DATEADD(s, -300, NOW()) AND NOW() GROUP BY job | ||
| expected: supported | ||
|
|
@@ -170,7 +170,7 @@ cases: | |
| expected: supported | ||
| - name: min-min-over-time | ||
| query: SELECT MIN(value) FROM data WHERE time BETWEEN DATEADD(s, -300, NOW()) AND NOW() | ||
| expected: unsupported | ||
| expected: supported | ||
| - name: min-by-job-min-over-time | ||
| query: SELECT job, MIN(value) FROM data WHERE time BETWEEN DATEADD(s, -300, NOW()) AND NOW() GROUP BY job | ||
| expected: supported | ||
|
|
@@ -182,7 +182,7 @@ cases: | |
| expected: supported | ||
| - name: max-max-over-time | ||
| query: SELECT MAX(value) FROM data WHERE time BETWEEN DATEADD(s, -300, NOW()) AND NOW() | ||
| expected: unsupported | ||
| expected: supported | ||
| - name: max-by-job-max-over-time | ||
| query: SELECT job, MAX(value) FROM data WHERE time BETWEEN DATEADD(s, -300, NOW()) AND NOW() GROUP BY job | ||
| expected: supported | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[test-coverage] No negative-path test for nested global aggregates
This test only shows that parsing keeps both layers. Nothing asserts that the matcher/planner then rejects the shape with
NestedQueryUnsupported, so loosening then > 1check inquery_info_to_patternwould let these flow into execution with time_infoUNUSEDand no test would fail. The "may reject" comment also leaves the expected outcome unstated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in c9bc666.
test_nested_global_aggregates_remain_unsupported_by_matchernow parses the nested global aggregate and assertsQueryError::NestedQueryUnsupported, making the accepted parser shape and rejected matcher shape explicit.