Conversation
This was referenced Oct 4, 2026
zzylol
force-pushed
the
stack/509-w7b-1-frequency-runtime
branch
from
October 4, 2026 18:25
502e276 to
bceb13e
Compare
zzylol
force-pushed
the
stack/509-w7b-2-sql-frequency-recognition
branch
from
October 4, 2026 18:25
f047e41 to
66bc1a6
Compare
This was referenced Oct 4, 2026
Draft
Port of the parked #562 and #564 for #509 Example 2. The SQL frontend names `SQRT(SUM(c*c))` over Float64 grouped unit counts as FrequencyL2, and `-SUM(p*LN(p))` with `p = COUNT(*)*1.0 / SUM(COUNT(*)) OVER ()` as FrequencyEntropy converted to nats. An exact population count guards SQL's empty-input NULL. Integer products, nullable keys, filters, HAVING, other log bases and partial windows are refused. The rules are the old Pass 1 SemanticEquivalentRewriteStrategy rules, run by lower_sql at the query root so the Stage 1 pipeline sees the intents; the exact candidate is the native exact reducer. The executor gains SQL sqrt (from #562). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pass 1 takes the declared metric types since #593. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zzylol
force-pushed
the
stack/509-w7b-2-sql-frequency-recognition
branch
from
October 5, 2026 06:21
66bc1a6 to
e211fba
Compare
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.
Rebased on main d4869a7 (DF 54).
Wave 1 chain: #594 → #593 → #592 → #591 → #595 → #596 → #597 → #598 → #599 (on #589)
Why
#509 Example 2 writes two of its three statistics as SQL idioms:
and says "The SQL frontend does not yet recognize the Q2 and Q3 forms as
EntropyandL2. TODO: add this recognition to the per-language frontends." Without anEntropy/L2intent, Pass 1 has nothing to attach the exact, summary and UnivMon candidates to, and Pass 2 cannot share a UnivMon with Q1.The parked #562 (L2) and #564 (entropy) added these rules as a Pass 1
SemanticEquivalentRewriteStrategyin the oldasap-aware-mapping. This PR ports them. Part of #509 / #580 (W8).What
Before (Q2, lowered):
After:
Q3 becomes the same shape with
FrequencyL2and no unit change. Stage 1 then offers PassThrough (the exact reducer from #597) and summary alternatives, including UnivMon, for each intent.How
crates/frontend-sql/src/frequency.rs: follow projections only; require a single-key unfilteredCOUNT(*)over a non-nullable Bool/Int64/Utf8 key, no HAVING; for L2,SQRT(SUM(c*c))with a product already typed Float64; for entropy,LN,p = COUNT(*)[*1.0] / SUM(COUNT(*)) OVER ()over the complete unordered frame. The result converts bits to nats, keeps SQL's-0.0, and uses an exact population count for SQL's empty-input NULL, so an approximate estimate never decides NULL. The schema must equal the original.plan_stagesdoes not run: Stage 1 only enumerates realizations of single-measure aggregates. Following the design doc's TODO ("per-language frontends"),lower_sql_dialectnow applies the rule at the query root. So the original relational DAG is no longer kept as a separate candidate. The exact alternative is the native exact reducer, and the tests show that it agrees with the original SQL.sqrt(from feat(planner): recognize floating SQL frequency L2 idioms #562). The executor's expression compiler acceptssqrton Int64/Float64/NULL.Refused, as before: the uncast integer product (which is the design's literal Q3, because SQL Int64 overflow is observable), nullable keys, HAVING, scaled probabilities,
LOG2, and partitioned or ordered windows.Tests
Ported from #562/#564:
frontend-sql/tests/frequency_{l2,entropy}.rs(recognition, refusals, accuracy propagation, exact population guard) andintegration-tests/tests/sql_frequency_{l2,entropy}.rs(original and recognized L2 agree; entropy in nats,-0.0, NULL on empty input). The legacy-search inventory tests becomestage1_offers_exact_and_summary_l2_alternativesoverenumerate_local_logical_candidates. Without thelower_sqlcall, the recognition and entropy execution tests fail.Gate: fmt and clippy (
-D warnings) pass.cargo test --workspace: 1,538 passed, 10 ignored (#589: 1,517 / 10).Ports #562, #564. Stacked on #597. Next: #599.
🤖 Generated with Claude Code