Repository navigation
Fix PromQL operations on instant vectors without tags - #111872
Conversation
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.
|
Workflow [PR], commit [753582f] Summary: ✅
AI ReviewSummaryThis PR fixes PromQL operations on tag-less instant vectors by making every Final VerdictStatus: ✅ Approve |
Cover the StoreMethod::SCALAR_GRID conversion paths in toVectorGrid and applyLabelManipulationFunction, which the instant query tests don't reach.
|
Added the requested coverage in 753582f: two range-query tests ( |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 23/29 (79.31%) · Uncovered code |
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.
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.
Related: #57545
Changelog category (leave one):
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 withon(), which failed with a type error.Description
Binary operators between instant vectors without any tags failed with an error:
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), ...)(viatimeSeriesReplaceTag), binary operators with an emptyon()(viatimeSeriesThrowDuplicateSeriesIf), and combinations of date functions such ashour(vector(time())) + minute(vector(time())).Root cause: the group #0 constant (meaning "a group with no tags") was generated as a plain literal
0intoVectorGrid,applyLabelManipulationFunctionandtransformGroupASTForBinaryOperator. ClickHouse infers typeUInt8for such a literal, while alltimeSeries*functions working with groups requireUInt64. The aggregation path (transformGroupASTForAggregationOperator) already generatesCAST(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 intransformGroupASTForBinaryOperatorto 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_tagsintests/integration/test_prometheus_protocols/test_evaluation.pywith 8 cases covering arithmetic/set binary operators, emptyon(),topk,label_replaceand date-function combinations over tag-less vectors.Version info
26.8.1.509(included in26.8and later)