Skip to content

Fix PromQL operations on instant vectors without tags - #111872

Merged
nikitamikhaylov merged 2 commits into
ClickHouse:masterfrom
valerypetrov:promql/zero-group-uint64
Jul 31, 2026
Merged

nikitamikhaylov merged 2 commits into
ClickHouse:masterfrom
valerypetrov:promql/zero-group-uint64

Conversation

@valerypetrov

@valerypetrov valerypetrov commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Related: #57545

Changelog category (leave one):

  • Experimental Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

PromQL: fixed operations on instant vectors without tags, e.g. vector(1) + vector(2), topk(1, vector(1)), label_replace(vector(1), ...) and binary operators with on(), which failed with a type error.

Description

Binary operators between instant vectors without any tags failed with an error:

$ curl 'http://127.0.0.1:9093/api/v1/query?query=vector(1)%2Bvector(2)'
{"status":"error","errorType":"bad_data","error":"Argument #1 of function timeSeriesGroupToTags has wrong type UInt8, it must be UInt64"}

The same error affected every construct that materializes a tag-less vector into a vector grid and then feeds its group into a timeSeries* function: vector(1) and/or/unless vector(2), topk(1, vector(1)), label_replace(vector(1), ...) (via timeSeriesReplaceTag), binary operators with an empty on() (via timeSeriesThrowDuplicateSeriesIf), and combinations of date functions such as hour(vector(time())) + minute(vector(time())).

Root cause: the group #0 constant (meaning "a group with no tags") was generated as a plain literal 0 in toVectorGrid, applyLabelManipulationFunction and transformGroupASTForBinaryOperator. ClickHouse infers type UInt8 for such a literal, while all timeSeries* functions working with groups require UInt64. The aggregation path (transformGroupASTForAggregationOperator) already generates CAST(0, 'UInt64') for exactly this reason.

Fix: generate CAST(0, 'UInt64') in the remaining three places, following the existing pattern, and teach the group #0 short-circuit in transformGroupASTForBinaryOperator to recognize the CAST form in addition to the plain literal.

Verified against Prometheus 3.5.0: all the constructs above now return identical results. The PromQL compliance suite score is unchanged (no regressions; the suite does not cover binary operations between tag-less vectors, which is why this was not caught earlier).

Testing: new test_binary_operators_on_vectors_without_tags in tests/integration/test_prometheus_protocols/test_evaluation.py with 8 cases covering arithmetic/set binary operators, empty on(), topk, label_replace and date-function combinations over tag-less vectors.

Version info

  • Merged into: 26.8.1.509 (included in 26.8 and later)

Binary operators between instant vectors without any tags, e.g.
'vector(1) + vector(2)', as well as 'topk(1, vector(1))',
'label_replace(vector(1), ...)' and binary operators with 'on()'
failed with an error like 'Argument ClickHouse#1 of function
timeSeriesGroupToTags has wrong type UInt8, it must be UInt64'.

The group #0 constant (meaning a group with no tags) was generated
as a plain literal 0 in several places, and ClickHouse infers type
UInt8 for such a literal while all timeSeries* functions working
with groups require UInt64. Generate CAST(0, 'UInt64') instead,
the same way transformGroupASTForAggregationOperator already does,
and teach the group #0 short-circuit in
transformGroupASTForBinaryOperator to recognize the CAST form.
@nikitamikhaylov nikitamikhaylov added can be tested Allows running workflows for external contributors comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... labels Jul 25, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [753582f]

Summary: ✅


AI Review

Summary

This PR fixes PromQL operations on tag-less instant vectors by making every group #0 producer in the affected paths emit CAST(0, 'UInt64') instead of a plain literal, and by extending the regression tests to cover both instant-query and range-query (StoreMethod::SCALAR_GRID) cases. I reviewed the current PR head and the prior discussion, and I did not find any remaining correctness or coverage issues in the updated code.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-experimental Experimental Feature label Jul 25, 2026
Cover the StoreMethod::SCALAR_GRID conversion paths in toVectorGrid and
applyLabelManipulationFunction, which the instant query tests don't reach.
@valerypetrov

Copy link
Copy Markdown
Contributor Author

Added the requested coverage in 753582f: two range-query tests (vector(time()) + vector(1) and label_replace(vector(time()), ...)) that evaluate time-dependent tag-less vectors as scalar grids, exercising the StoreMethod::SCALAR_GRID branches changed in toVectorGrid and applyLabelManipulationFunction. Expectations verified against Prometheus 3.5.0.

@clickhouse-gh

clickhouse-gh Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.20% 86.20% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 78.40% 78.40% +0.00%

Changed lines: Changed C/C++ lines covered: 23/29 (79.31%) · Uncovered code

Full report · Diff report

valerypetrov added a commit to valerypetrov/ClickHouse that referenced this pull request Jul 25, 2026
Casting a tag-less vector to a vector grid generated the group #0
constant as a plain literal 0 which ClickHouse types as UInt8, while
timeSeries* functions require UInt64. The clamp() empty-result path for
non-constant bounds converts scalar-backed vectors through toVectorGrid,
so clamp(vector(5), time() * 0 + 1, -1) failed with
'Argument ClickHouse#1 of function timeSeriesGroupToTags has wrong type UInt8'.

Same fix as in ClickHouse#111872 (which covers the remaining converter sites);
the identical hunks will merge cleanly whichever PR lands first.
valerypetrov added a commit to valerypetrov/ClickHouse that referenced this pull request Jul 26, 2026
Apply the same UInt64 cast to the no-tags group constant emitted by
applyLabelManipulationFunction and transformGroupASTForBinaryOperator
(empty on()), and teach the group #0 short-circuit to recognize the
CAST form, so constructs like label_replace(vector(1), ...) work with
the functions added by this PR. Byte-identical to the fix in ClickHouse#111872.
@nikitamikhaylov nikitamikhaylov self-assigned this Jul 31, 2026
@nikitamikhaylov
nikitamikhaylov added this pull request to the merge queue Jul 31, 2026
Merged via the queue into ClickHouse:master with commit b1ac9ed Jul 31, 2026
178 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... pr-experimental Experimental Feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants