Repository navigation
Implement PromQL functions absent and count_values - #112795
Conversation
Implement absent by aggregating per-grid sample presence across all input series. Emit a synthetic value of 1 for empty grid points and infer labels from unambiguous equality matchers on a direct selector, while preserving Prometheus matcher-order and offset behavior. Implement count_values with an unroll, relabel, regroup, and repack pipeline. The value-dependent label becomes part of each grid point grouping key, with full by/without handling, destination-label replacement, sparse range results, empty vectors, and __name__ support. Add an internal float formatter matching Go fixed shortest-roundtrip representation so generated value labels preserve -0 and render NaN and infinities like Prometheus. Register both converters, add integration coverage, and update the prometheusQuery support documentation. Local runtime results and ordering were compared with Prometheus 3.5.0. The integration module collected 28 tests, but Docker was unavailable during module fixture setup, so no pytest test body ran locally. Related: ClickHouse#57545
Replace round with an equivalent expression built from floor and scalar arithmetic so the new count_values coverage applies directly to current master without depending on another open PromQL feature PR. The positive fixture values produce the same 0, 100, 700, and 1000 buckets. Verified the three updated queries against Prometheus 3.5.0 and the local ClickHouse TimeSeries test binary. Related: ClickHouse#57545
Document that absent label inference intentionally mirrors Prometheus historic monotonic has map: after the first accepted equality matcher, a later matcher can delete the inferred label but cannot unlock it for another equality matcher. Cover the three-matcher equality/regex/equality sequence and confirm that Prometheus 3.x accepts non-empty UTF-8 count_values destination labels outside the legacy label-name pattern. Both cases were compared directly with Prometheus 3.5.0 and the local ClickHouse TimeSeries test binary.
baa626a to
71adef5
Compare
|
Workflow [PR], commit [7685647] Summary: ✅
AI ReviewSummaryThis PR adds PromQL Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 305/348 (87.64%) · Uncovered code |
Document and test that Prometheus treats inferred empty label values as missing labels. Value-initialize the formatting buffers to fix the arm_tidy build.
|
Follow-up pushed in I kept the existing empty-value behavior because the review's requested expectation is inverted relative to Prometheus 3.5.0:
The follow-up adds that exact regression with |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 302/348 (86.78%) · Uncovered code |
Resolves two modify/delete conflicts caused by master's docs migration from docs/en/**/*.md to autogenerated Mintlify docs/reference/**/*.mdx: - docs/en/sql-reference/table-functions/prometheusQuery.md - docs/en/sql-reference/table-functions/prometheusQueryRange.md Both were deleted upstream in favor of their Mintlify successors (per docs/_migration/slug-map.csv): - docs/reference/functions/table-functions/prometheusQuery.mdx - docs/reference/functions/table-functions/prometheusQueryRange.mdx Ported this PR's doc changes (adding `absent` to the supported functions table and `count_values` to the supported aggregation operators, removing the "not yet supported" note) into the new .mdx files, matching the existing Mintlify formatting. All other conflicts (applyAggregationOperator.cpp, applyFunction.cpp, TableFunctionTimeSeries.cpp) auto-merged cleanly, combining this PR's absent/count_values dispatch entries and inline docs with master's independent changes (new Range functions, anchor renames) in the same file regions.
… namespace unwind Master's "Unwind the PQT abbreviation" PR (merged in commit 3e57eeb) removed the `using PQT = PrometheusQueryTree;` alias from ConverterDefs.h and renamed all `PQT::` usages elsewhere to `PrometheusQueryTree::`. This branch's own new files (applyAggregationOperatorCountValues.cpp/.h, applyFunctionAbsent.cpp/.h) still referenced the removed `PQT` alias, so they failed to compile after merging master, with clang reporting "use of undeclared identifier 'PQT'" plus cascading error-recovery diagnostics in applyFunctionAbsent.cpp ("no member named 'getExpression' in 'DB::PrometheusQueryTree::Node'" and a bogus `const int *` return type mismatch) — both artifacts of the same root cause, not independent bugs: `Offset::getExpression()` returns `const Node *` exactly as used once `PQT::Offset` correctly resolves to `PrometheusQueryTree::Offset`. CI report: ClickHouse#112795
The prometheusQuery/prometheusQueryRange .mdx pages regenerate their supported-syntax sections from TableFunctionTimeSeries.cpp, which already carries the absent/count_values updates.
count_values sets its destination label before the grouping modifier is applied. `by` implicitly keeps that label, while `without` removes only the labels listed by the user plus `__name__`. A destination label that is neither is therefore retained by `without`, whereas a `__name__` destination is not.
Pin all three shapes: `count_values("value", ...) without (shape)` keeps `value` and produces the same result as the `by (size)` form; `count_values("__name__", ...) by (size)` keeps `__name__`, so every distinct value stays its own bucket; `count_values("__name__", ...) without (shape)` drops `__name__`, so the buckets collapse into one count per remaining label set.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Object file sizes5 object files changed (+437.95 KiB total), 3 added.
737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units12 translation units recompiled, 17 s compile time in total, 9 of them have a recent master baseline. |
…-values Co-Authored-By: Claude Fable 5 <[email protected]>
|
@nikitamikhaylov , can you please check this one? It seems to be ready for review. |
checkArgumentTypes already requires arguments[0].type == ResultType::STRING, and the only AST node that produces that result type is StringLiteral (see PrometheusQueryTree.h and fromLiteral.cpp), so the node_type check here can never be false. Co-Authored-By: Claude Opus 5 <[email protected]>
PromQL Compliance ReportBaseline: S3 master
Uploaded compliance JSON for this PR commit Baseline updateThis run reports 78.29% vs master baseline 77.74% ( |
|
@valerypetrov @nikitamikhaylov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Related: #57545
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
PromQL: implemented
absentandcount_values, including range queries andby/withoutaggregation modifiers.Description
Implements two PromQL operations that previously returned a not-implemented error and require result construction beyond transforming a fixed per-series values array.
absent(v instant-vector)aggregates sample presence across all input series independently at every grid point and emits one synthetic sample with value 1 only where the input is empty. For a direct selector, includingoffsetand@modifiers, it performs Prometheus-compatible equality-matcher label inference while excluding__name__; complex expressions produce an unlabeled result. Label inference deliberately mirrors Prometheus's historic monotonichasmap: after the first accepted equality matcher for a label name, a later matcher can delete the inferred label but cannot unlock that name for another equality matcher. An empty exact-match value is canonicalized as label absence, matching Prometheuslabels.Builder::Set.count_values(label, v instant-vector)unrolls each series' grid values, sets or overwrites the requested value label, groups by label set, grid point, and formatted sample value, counts each bucket, and repacks sparse counts into nullable grid arrays. Bothby (...)andwithout (...)are supported, including removing the generated label or using__name__as the destination. Destination label names follow Prometheus 3.x UTF-8 validation—non-empty valid UTF-8—rather than the legacy ASCII label-name pattern.A new internal
timeSeriesPrometheusValueToStringfunction reproduces Go's fixed shortest-roundtrip formatting used by Prometheus, including-0,NaN,+Inf, and-Inf. The supported-function documentation forprometheusQueryandprometheusQueryRangeis updated accordingly.Verified against Prometheus 3.5.0 with direct response comparisons covering sparse range points, inferred labels (including equality/regex/equality ordering and empty exact-match values), grouping modifiers, empty inputs, metric-name and non-legacy UTF-8 destination labels, floating-point label strings, and result ordering.
Testing: added
test_function_absentandtest_aggregation_operator_count_valuesintegration coverage intests/integration/test_prometheus_protocols/test_evaluation.py. All six modified C++ translation units compile locally with zero warnings or errors. The focused queries were exercised against a localTimeSeriestable and compared with Prometheus 3.5.0. The clean-master integration module collects all 25 tests, including both additions, but no test body ran locally because the Docker daemon was unavailable and the module-scoped cluster fixture failed during setup; containerized integration execution is left to CI.Workflow [PR]
Sync PR [sync-upstream/pr/112795]
Version info
26.9.1.557(included in26.9and later)