Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions crates/asap_types/src/capability_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,18 @@ pub fn compatible_agg_types(stat: Statistic) -> &'static [AggregationType] {
// signed-counter matrix). `CountSketchAccumulator` answers
// `Statistic::Topk` directly — see
// `precompute_operators/count_sketch_accumulator.rs:284`.
// Without CountSketch listed here, `topk(K, top_endpoint_qps)`
// capability-misses and the warm engine returns `status=error`.
// `CountSketchWithHeap` is the explicit heap-bearing variant
// that also satisfies Topk through the heap directly
// (parallel to `CountMinSketchWithHeap`); the analyzer's
// `topk(...)` candidate returns `FrequencyTopk(Any)` so
// either heap-bearing variant matches.
// Without CountSketch / CountSketchWithHeap listed here,
// `topk(K, top_endpoint_qps)` capability-misses and the
// warm engine returns `status=error`.
Statistic::Topk => &[
AggregationType::CountMinSketchWithHeap,
AggregationType::CountSketch,
AggregationType::CountSketchWithHeap,
],
}
}
Expand Down
28 changes: 28 additions & 0 deletions crates/promql_utilities/src/query_logics/logics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ pub fn does_precompute_operator_support_subpopulations(
// CountMinSketchWithHeap is only supported for Topk — does not support subpopulations
AggregationType::CountMinSketchWithHeap if matches!(statistic, Statistic::Topk) => false,

// CountSketch is the signed-counter equivalent of CMS — same
// subpopulation shape for Sum/Count statistics. The
// heap-bearing variant covers Topk like its CMS counterpart.
AggregationType::CountSketch => matches!(statistic, Statistic::Sum | Statistic::Count),
AggregationType::CountSketchWithHeap if matches!(statistic, Statistic::Topk) => false,

// Default: not supported
_ => panic!("Unexpected precompute operator: {}", precompute_operator),
}
Expand Down Expand Up @@ -186,6 +192,28 @@ mod tests {
Statistic::Sum,
AggregationType::CountMinSketch,
));

// Sibling CountSketch path — must not panic, matches
// CountMinSketch's Sum/Count subpopulation shape.
assert!(does_precompute_operator_support_subpopulations(
Statistic::Sum,
AggregationType::CountSketch,
));
assert!(does_precompute_operator_support_subpopulations(
Statistic::Count,
AggregationType::CountSketch,
));

// Heap-bearing variants on Topk — both return false (heap
// is per-policy, not subpopulation-keyed) and must not panic.
assert!(!does_precompute_operator_support_subpopulations(
Statistic::Topk,
AggregationType::CountMinSketchWithHeap,
));
assert!(!does_precompute_operator_support_subpopulations(
Statistic::Topk,
AggregationType::CountSketchWithHeap,
));
}

#[test]
Expand Down