Repository navigation
Conversation
This was referenced Oct 3, 2026
zzylol
marked this pull request as draft
October 3, 2026 19:29
Contributor
Author
|
Parked as draft: PR priorities changed (see #528). Order is now (A) finish #511 operator sharing, (B) the #572 crate/module reorganization, (C) #509 end-to-end stages. This PR sits on the old 🤖 Generated with Claude Code |
Contributor
Author
|
Ported onto the current stack in #599 |
zzylol
added a commit
that referenced
this pull request
Oct 4, 2026
Port of the parked #565: SQL LN and a complete, unordered `SUM(column) OVER ()` window (SQLWindowSum) run natively, so the original Q2 SQL of #509 Example 2 executes and matches its recognized entropy form. Partitioned, ordered and finite frames stay refused. planner_layering_example2 records Example 2's status: the three queries lower to Cardinality / FrequencyEntropy / FrequencyL2 (the design's integer Q3 does not), the time filter is a scan predicate, plan_stages plans the workload with UnivMon offered to each statistic, and the exact candidates execute (without the time filter: the runtime has no now() yet). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem: the exact candidate for #509 Example 2 Q2 cannot run natively
#509 §Pass 1: Local candidate generation gives
Entropy(x)three local candidates: "Exact entropy, a specialized entropy summary, UnivMon". #509 §Stages and their decisions requires each stage to output "every semantically equivalent and legal candidate", and §3 Plan selection rejects a candidate "that needs a capability the deployment lacks". So the original exact Q2 graph must stay a real, executable candidate next to the rewrite from #564.#564 keeps the original Q2 graph as an alternative. But native binding cannot run it. Q2 (#509 §Example 2) is:
Before this PR, two pieces of this graph have no native implementation:
SUM(COUNT(*)) OVER ()NonASAPOp::SQLWindowFunc { func: Sum, partition_by: [], order_by: [], frame: UNBOUNDED PRECEDING … UNBOUNDED FOLLOWING }bind_operationfalls tovalue operation has no native implementationLN(p)ScalarExpr::FunctionCall { name: "ln", .. }validaterejects it. Only SQLsqrt, thepromql_-prefixed functions (e.g.promql_ln) and map functions are acceptedSo in native execution only the rewritten frequency graph from #564 runs, and there is no way to check that it gives the same answer as the SQL it replaced.
Scope covered here. Native execution of the exact Q2 graph: SQL
LN, andSUM(column) OVER ()over the complete, unordered relation.Left out. Partitioned, ordered and finite window frames (still refused). Raw analytical cost lowering for this window. This SQL window is not the streaming summary window of #509 §Pass 2 (sliding / tumbling / EH); that is #566.
Proposed method
All changes are in the native physical layer (
asap-physical-operators), stage 2 physical operator implementation and stage 4 execution.SQLWindowSum.Operator::sql_window_sum(input, column, name)checks thatcolumnis a plainInt64orFloat64field. The output schema is the input schema plus one nullable fieldnameof the same type. Input metadata is kept because the input schema is cloned.aggregate::execute). It collects all input rows, computes one total with the existingreduce_one(.., Reduction::Sum(column), ..), and appends that total to every row. Row order and row count are unchanged. Empty or all-NULLinput gives aNULLtotal (SUM semantics). Each output row is charged toWorkspace, so a memory limit fails cleanly withError::MemoryLimit.Cooperativecheckpoints are taken per row.bind_operationmapsNonASAPOpKind::SQLWindowFunctoSQLWindowSumonly when:funcisSum;argsis exactly one column;partition_byis notwithoutand has no keys;order_byis empty; the frame start isPreceding(Null)and the end isFollowing(Null)(both unbounded). Anything else returnsnative SQL window SUM requires the complete unordered relation.UncheckedOperator → OperatorrebuildsSQLWindowSum, taking the output name from the last output field. So a serialized operator round-trips through the same constructor checks.LN. The expression evaluator handleslnwith the same path assqrt:NULL → NULL,Int64/Float64→Float64(value.ln()), anything else isSQL math function requires a numeric argument.validateacceptslnwith oneInt64/Float64/Nullargument.Key code interfaces
crates/asap-physical-operators/src/operators/aggregate/mod.rs:crates/asap-physical-operators/src/operators/mod.rs(privateKind, display name"SQLWindowSum"):crates/asap-physical-operators/src/physical_planner/mod.rs, new arm inbind_operation:crates/asap-physical-operators/src/expressions/planner.rs:evaluateandvalidateacceptFunctionCall { name: "ln", args: [x] }(case-insensitive).Usage (from
crates/asap-physical-operators/tests/physical_semantics.rs):Fields
Operator::sql_window_suminputSchemaRefcolumnusizeInt64orFloat64field, elseSQL window SUM requires a numeric column.nameStringoutput_name, or by recovery from the last output field.Result<Operator, Error>inputs = [input]andoutput = input fields + (name, same dtype, nullable = true).Kind::SQLWindowSumcolumnusizeSQLWindowFuncbinding conditionsfuncWindowFuncKind::Sumargs[Column(c)]partition_bywithout, no keysorder_byframeSome, startPreceding(Scalar(Null)), endFollowing(Scalar(Null))output_namename.lnscalar functionNULLNULLInt64(v)/Float64(v)Float64(v.ln())SQL math function requires a numeric argumentExamples
End-to-end: original Q2 vs. #564 rewrite (
crates/integration-tests/tests/sql_frequency_entropy.rs). Tableflows(src_ip Utf8, keep Bool). Query:The test executes both the original lowered graph and the rewritten graph on the same rows (each case adds one
("discard", false)row) and requires equal results:src_ipvaluesNULLNULLa, a-0.0-0.0a, a, b, bln 2ln 2a, a, a, b-0.75·ln 0.75 − 0.25·ln 0.251e-12For
a, a, b, bthe original graph runs as: group count{a: 2, b: 2}→SQLWindowSumappendstotal = 4to both rows →p = 0.5→-SUM(0.5·ln 0.5 · 2) = ln 2.Operator semantics (
physical_semantics.rs,complete_sql_sum_window_preserves_rows_and_nulls, run after a serde round trip):v(nullableInt64)[NULL][NULL, NULL][1], [NULL], [3][1, 4], [NULL, 4], [3, 4]Binding: accepted vs refused (
native_sql_sum_window_rejects_other_frames):SUM(x) OVER ()SQLWindowSumSUM(src_ip) OVER (PARTITION BY src_ip)SUM(src_ip) OVER (ORDER BY src_ip)SUM(src_ip) OVER (ROWS BETWEEN 1 PRECEDING AND CURRENT ROW)Other tests:
blocking_resources.rs,complete_window_sum_enforces_workspace_budget: 64 rows with a 12,000-byte budget fail withError::MemoryLimit, and retained bytes return to 0 after drop.physical_semantics.rs,sql_ln_executes_numeric_and_null_arguments:ln(2)onInt64andFloat64givesLN_2;ln(NULL)givesNULL.Out of scope
docs/develop_docs/planner-layering-status.mdgains a "Native entropy fallback follow-up acceptance" section, anddocs/develop_docs/README.mdnow links it.Stack and validation
Stacked on #564 (
stack/509-19-sql-frequency-entropy). Head:stack/509-20-sql-entropy-fallback. Next: #566.Validation (from the current PR body):
🤖 Generated with Claude Code