Repository navigation
feat(query): aggregate and window answers independent of input order (#547, PR 1/3) - #642
Merged
Merged
Conversation
…547) PR 1 of #547 (rules on the executor): one accumulator module shared by both engines, so no aggregate or window answer follows the plan's row order. - aggregate.rs: exact sums (i128 integers saturated once; floats in a fixed-point accumulator rounded once), value_order (one total order of values), Agg / Running accumulators deciding errors at finish - windows: partitions by Value Ord, sort by :order-by then the other :find-named variables then input position; peers share rank and the running value at the last peer - PRS-082: a window in an aggregate query may read only plain :find variables - functions.rs built-ins become an enum; value_lt, value_cmp, apply_builtin_aggregate, WindowOps, AggState removed Plan: docs/superpowers/plans/2026-10-20-547-aggregate-window.md Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PtCdzbJMSS1V8qEPaJ4jXz
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR 1 of 3 for #547 (part of #473): aggregate and window rules on the executor. Spec:
docs/superpowers/specs/2026-10-20-aggregate-window-engine-design.md(#640). Plan:docs/superpowers/plans/2026-10-20-547-aggregate-window.md.No aggregate or window answer depends on the order rows reach it any more.
Changes
src/query/datalog/aggregate.rs, shared by both engines (PRs 2–3 will use it):value_order: one total order of values. Numbers compare exactly across Integer and Float, and NaN comes after every other number. After the numbers come strings, booleans, refs, keywords, andnillast.i128and saturate once. Floats add into a fixed-point accumulator and round once, half-even.AggandRunning: the accumulators for aggregates and windows. Type errors (INT-041, INT-043, INT-044) and dropped groups are decided once all rows are in, so the answer is the same whatever order the rows arrive in.BTreeMap<Vec<Value>, Vec<Agg>>; groups finish in key order.Value'sOrd, so all NaN keys share one partition;:order-by, then the other:find-named variables, then input position;rankand the running value at the last peer, as in SQL.:findvariables.functions.rs: the built-in functions become an enum.AggState,WindowOps,apply_builtin_aggregate,value_lt,value_cmp,is_knownandis_window_compatibleare removed.Changed existing tests
tests/window_functions_test.rs::mixed_aggregate_and_window_in_same_findandparser.rs::parse_mixed_aggregate_and_window_allowedused exactly the query PRS-082 now rejects (a window reading a variable that is not grouped). Both now use a grouping variable. New tests check the rejection.Tests
aggregate/tests.rs), 8 integration tests (tests/aggregate_window_rules_test.rs), and 8 aggregate/window queries added to the plan-independence matrix.test-oracleis green.--all-features) is clean, and so is the wasmbrowserbuild.Not in this PR
avgamong the aggregates, butavgis window-only (PRS-027), soAgghas noavg. The plan records this deviation.Codex review (read-only, on the commit) found no issues.
🤖 Generated with Claude Code
https://claude.ai/code/session_01PtCdzbJMSS1V8qEPaJ4jXz