Skip to content

feat(sil): structural free variables (free GROUP BY, free window) as weighted choices - #1561

Draft
zzylol wants to merge 3 commits into
feat/exclusive-alternativesfrom
feat/structural-free-variables
Draft

zzylol wants to merge 3 commits into
feat/exclusive-alternativesfrom
feat/structural-free-variables

Conversation

@zzylol

@zzylol zzylol commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: dashboards make the grouping keys and the window structural free variables (GROUP BY $group over {region}, {region, service}, ...; window over {5m, 1h, 6h}). feat(planner): exclusive alternatives (Σp costing, SIL weighted choices) and a streamed copy per reader #1558's weighted choice could express a window, but not a free GROUP BY: the keys appear in SELECT and GROUP BY (two choices would combine as a product) and a key list holds commas.
  • Change: equal choices in one query are one free variable (same alternative everywhere); an alternative in parentheses stands for its contents.
  • Effect: SELECT {host: 0.7, (host, user): 0.3}, sum(bytes) ... GROUP BY {host: 0.7, (host, user): 0.3} lowers to 2 exclusive alternatives (not 4 mismatched ones), and planned jointly costs less than each alternative planned alone (structural_free_variables_are_cheaper_planned_jointly).

Review guide

Behavior: before → after

INTENT d EVERY 60s;
q6: SELECT {region: 0.5, (region, service): 0.3, (service, endpoint): 0.2}, sum(bytes) AS b FROM flows
    WHERE ts > $now - {INTERVAL '5 minutes': 0.6, INTERVAL '1 hour': 0.3, INTERVAL '6 hours': 0.1}
    GROUP BY {region: 0.5, (region, service): 0.3, (service, endpoint): 0.2} REQUIRE EXACT;
  • Before: 27 alternatives, most selecting keys they do not group by ((region, service) substituted with its parentheses).
  • After: 9 alternatives q6#0..q6#8 (3 groupings × 3 windows), one exclusive group, e.g. q6#0 = SELECT region, sum(bytes) AS b ... WHERE ts > now() - INTERVAL '5 minutes' GROUP BY region at 0.3. Serves the eval's free-variable suite column and M8.

Interfaces

None in Rust (SIL grammar only): equal choice text in one query = one free variable; (a, b) as an alternative = a, b. Documented in crates/frontend-sil/src/lib.rs and parse.rs.

Algorithm changes

Choice expansion (alternatives_of). Before: product over every {...} occurrence. After: occurrences grouped into distinct choices (equal alternative texts and probabilities; equal texts with different probabilities refused); product over distinct choices; each combination substitutes every occurrence with its choice's pick. Complexity: O(occurrences × distinct) to group, output size unchanged (≤ 1,000).

Decisions and open questions

  • Decided (2026-12-03): no named-variable declaration (FREE $g IN {...}); repeating the same text is the smallest syntax consistent with SIL's "no client parameters".

Verification

Scope Result Notes
cargo test -p asap-frontend-sil 35 pass new: free GROUP BY written twice; free window × free aggregate product; same items with different probabilities refused
asap-planner --test planner sil_intents 26 pass new: free GROUP BY and free window lower to one exclusive group and are cheaper planned jointly than alone
clippy -D warnings frontend-sil clean

Follow-ups

  • Deferred: free grouping that drops all keys (ungrouped alternative); named free variables shared across queries.

🤖 Generated with Claude Code

https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi

@zzylol zzylol added enhancement New feature or request parser External or internal query parser behavior labels Dec 3, 2026
@zzylol
zzylol force-pushed the feat/structural-free-variables branch from 868c9f0 to 5850b77 Compare December 4, 2026 02:52
zzylol added a commit that referenced this pull request Dec 4, 2026
zzylol and others added 3 commits December 4, 2026 03:31
…s choices (failing)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
… variable

A free GROUP BY is the same weighted choice written in the select list
and in GROUP BY: equal choices in one query take one alternative
everywhere (the same items with other probabilities are refused), and
an alternative in parentheses stands for its contents, so a key list
may hold commas. A free window range is a choice over INTERVALs. Both
lower to exclusive alternatives; covering is the planner's ordinary
sharing (rollup from the finer grouping, one pane chain).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request parser External or internal query parser behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant