fix(promql): count observations with unit sketch weights - #406
Merged
Conversation
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.
PromQL counts must not vary with sample values. This fixes both count lowering paths and extends the existing frequency-update rule to CMS/CountSketch counts.
Before this PR:
count(up)lowered to value cardinality; three series with{1,1,1}expressed a distinct result of 1.count_over_timealready lowered to Count, but its CMS/CountSketch plans carried the sample-value column as a weight, allowing value sums and signed CMS updates.After this PR:
count(up)lowers to Count (three vector elements in either{1,1,1}or{1,1,0}), and count sketches carry an explicit item plus constant+1weight with aUnitCountproof. Ten observations contribute ten updates regardless of whether values are 1, 0, 3, or negative. SQL distinct counting and the existing rejection of unproven signed value-weighted CMS remain unchanged.Verification: Regression tests failed on the original code for both defects. Added query-text → summary-selection → executable-DAG coverage; corrected existing tests that asserted the erroneous cardinality mapping. All 611 tests passed with
cargo +1.98.0 test -p asap-frontend-promql -p asap-aware-mapping --locked. Focused all-target Clippy (-D warnings), workspace formatting, andgit diff --checkpassed. Workspace-wide SQL/integration tests are left to CI.Reported fixtures: Added numerical planner-contract tests for
count(up)on{1,1,1}and{1,1,0}(both 3), ten scrapes of 1/0/3 (each 10), all-negative/mixed-sign series, and CMS update totals for signed/zero values. All five count-planning tests pass, as do focused Clippy and formatting checks. Re-running against the pre-fix implementation makes the new target-count and CMS-total regressions fail. The fixture interpreter covers selected observations and emitted aggregate/update contracts; it is not a backend or sketch-library runtime.Scope: Planner semantics and executable contracts. Production-process execution was not run; ASAPQuery needs to adopt the fixed revision and replace its hand-built count/HLL oracles as part of ProjectASAP/ASAPQuery-backend#503 and ProjectASAP/ASAPQuery-backend#489. This PR does not claim the broader PromQL rollout is E2E-complete.
Addresses #405.