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 #597 |
zzylol
added a commit
that referenced
this pull request
Oct 4, 2026
…ntities Port of the parked runtime PRs for #509 Example 2 onto asap-executor: - native UnivMon build and Cardinality / FrequencyL2 / FrequencyEntropy readouts (the old stack's 14c8ac8, a prerequisite missing here); - #557: a UnivMon build accepts Utf8, Int64 and Bool identities as type-tagged keys; heap key bytes count toward state memory; - #559: exact FrequencyL2 / FrequencyEntropy reducers (bits, NULL skipped, 0 for an empty population, memory-accounted, cooperative); - #563: exact Cardinality reducer over typed tuples. The legacy raw-cost adapter lists the three intents as hash aggregates. 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
Distinct(x)candidate of #509 Example 2 cannot execute#509 §Pass 1 (local candidate generation) gives
Distinct(x)an exact candidate:Distinct(x)#509 §Example 2 Q1 is that computation:
Pass 2 keeps the independent candidates next to the shared UnivMon, and #509 §Physical operator implementation must convert every node to a physical operator. So the exact distinct plan must run.
Before this PR, the SQL frontend already lowers Q1 to
AggIntent::Cardinality, but the two physical paths refuse it:#559 added the exact L2 and entropy reducers. Distinct is the third Example 2 statistic still without one.
Scope. This PR covers the
Distinct(x)exact row of the #509 §Pass 1 table: native execution ofCardinalityand raw cost eligibility. It does not change sketch sizing, accuracy certificates, filtered-measure support, entropy recognition or window planning.Proposed method
Physical runtime and raw costing only.
bind_operationmapsAggIntent::Cardinality { cols, .. }toReduction::Cardinality(cols). Ifcolsis empty, it uses the sample-value column (ColumnRef::SampleValue), the same convention as other intents with no column.Operator::aggregaterejects an empty column list ("distinct aggregate requires at least one identity column"). Each listed column must be plain. The output is non-nullableInt64.reduce_one:NULL(SQLCOUNT(DISTINCT a, b)semantics);group_key(row, columns), which yields one type-tagged byte string per column (Vec<Vec<u8>>), so tuple boundaries are kept, Int64 values above 2^53 stay distinct, and-0.0/0.0and NaN payloads each collapse to one identity;BTreeSet;Int64(len). Empty input givesInt64(0).key_bytes(&key)in aWorkspaceon theRunContext. Over budget fails withError::MemoryLimit, and the reservation is released afterward. Every row passeswork.checkpoint().supports_hash_aggregatenow listsCardinality, so raw plans lower toPhysicalOperator::HashAggregate.crates/integration-tests/tests/physical_common/mod.rsasexecute_raw_rows, shared by the L2 and distinct SQL tests.Key code interfaces
crates/asap-physical-operators/src/operators/aggregate/mod.rsExisting IR intent now bound natively (
crates/types/src/pre_asap/agg_intent.rs, unchanged):Binding (
crates/asap-physical-operators/src/physical_planner/mod.rs):Raw costing (
crates/asap-aware-mapping/src/query_physical_lowering.rs):supports_hash_aggregateacceptsAggIntent::Cardinality { .. }.Test helper (
crates/integration-tests/tests/physical_common/mod.rs):Fields
Reduction::Cardinality(Vec<usize>)Vec<usize>Int64count per group,0for an empty population.AggIntent::Cardinality(as used by binding)colsVec<usize>Reduction::Cardinality. Empty →[SampleValue column].accuracyAccuracyTargetexecute_raw_rowsrootcompile_post_asap_dag; the firstScannode gives the source name and schema.rowsMemorySourcefor that source.retained_bytes() == 0after execution.Examples
End to end (
crates/integration-tests/tests/sql_cardinality.rs::sql_distinct_executes_through_raw_scan_and_native_binding).lower_sql→compile_post_asap_dag→bind_with_data_sourceswith a raw in-memory connector → execute:(src_ip, keep)0(NULL, true)0(a,true),(a,true),(b,true),(discard,false),(NULL,true)2The
WHERE keeppredicate removesdiscard; NULL is skipped.Typed tuples (
crates/asap-physical-operators/tests/physical_semantics.rs::exact_cardinality_binds_and_executes_typed_tuples). APostAsapDAGNodewithCardinality { cols, accuracy: Exact }is compiled withcompile_node. Rows(key: Int64, tag: Utf8):cols[0]2^53and2^53+1are distinct; NULL row skipped[0, 1](2^53,a),(2^53,b),(2^53+1,a); NULL-containing tuple skippedFor both, empty input and an all-NULL row return
Int64(0).Grouping and float identities (
exact_cardinality_grouping_normalizes_float_identities).0.0,-0.0,NaN,NaNwith a different payloadNULLMemory (
tests/blocking_resources.rs::frequency_dictionary_enforces_memory_budget). With 64 distinct Int64 rows under a 12,000-byte budget,Cardinality(vec![0])fails withError::MemoryLimit(likeFrequencyL2/FrequencyEntropy;Countsucceeds), andretained_bytes()returns to 0.Accepted vs rejected
Reduction::CardinalityOperator::aggregatecolsinAggIntent::CardinalityfilterswithSome)The status note
docs/develop_docs/planner-layering-status.mdgains §"Exact distinct follow-up acceptance".Out of scope
Stack and validation
Stacked on #562 · Next: #564 · Reference/tracker: #528
Validation: binding regression fails on the parent and passes after implementation; native semantic/resource tests; SQL distinct and L2 wire execution; raw physical-lowering tests; formatting and affected all-target Clippy with warnings denied.
🤖 Generated with Claude Code