PromQL: Add functions label_replace and label_join#104564
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds PromQL label manipulation support by implementing label_replace() and label_join() in the PrometheusQueryToSQL converter, backed by existing ClickHouse time-series tag functions, and extends the replacement-pattern handling to better match Prometheus behavior.
Changes:
- Implement PromQL
label_replace/label_joinconversion to SQL viatimeSeriesReplaceTag/timeSeriesJoinTags. - Extend replacement-pattern parsing for
timeSeriesReplaceTag(multi-digit refs, braced refs, literal$, etc.) and allow emptysrc_tagto match PromQL semantics. - Add/extend stateless and integration tests covering label manipulation and replacement edge cases.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/queries/0_stateless/03779_time_series_tags_functions.sql | Adds stateless SQL coverage for replacement-pattern edge cases. |
| tests/queries/0_stateless/03779_time_series_tags_functions.reference | Updates expected output for the new stateless test block. |
| tests/integration/test_prometheus_protocols/test_evaluation.py | Adds integration tests for PromQL label_replace and label_join behavior and errors. |
| src/Storages/TimeSeries/PrometheusQueryToSQL/applyLabelManipulationFunction.h | Declares helpers for recognizing/applying label manipulation functions. |
| src/Storages/TimeSeries/PrometheusQueryToSQL/applyLabelManipulationFunction.cpp | Implements label_replace / label_join conversion and duplicate-labelset protection. |
| src/Storages/TimeSeries/PrometheusQueryToSQL/applyFunctionScalar.cpp | Adjusts scalar aggregation behavior for instant (start_time == end_time) evaluation. |
| src/Storages/TimeSeries/PrometheusQueryToSQL/applyFunction.cpp | Wires label manipulation functions into the function dispatch path. |
| src/Interpreters/ContextTimeSeriesTagsCollector.cpp | Updates replacement-pattern parsing logic to more closely follow Prometheus semantics. |
| src/Functions/TimeSeries/timeSeriesReplaceTag.cpp | Allows empty src_tag to support PromQL tricks like constant label insertion. |
a7dc5ca to
6cf9805
Compare
6cf9805 to
b43963b
Compare
b43963b to
fc1c72d
Compare
|
@groeneai Investigate CI failures |
|
@vitlibar — investigated CI failures on 1.
|
|
The |
fc1c72d to
6e023ff
Compare
72177cb to
43c2d3a
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/Storages/TimeSeries/PrometheusQueryToSQL/applyLabelManipulationFunction.cpp:279
- This unconditionally clears
metric_name_droppedwhen writing to__name__, but the tag functions dropdest_tagif the computed destination value is empty. Cases like joining only missing source labels into__name__therefore leave the actual group without__name__while downstream code treats it as present; avoid forcing the flag tofalseunless the produced value cannot be empty.
if (dest_label == kMetricName)
res.metric_name_dropped = false;
LLVM Coverage ReportChanged lines: 71.30% (164/230) | lost baseline coverage: 13 line(s) · Uncovered code |
ba4ced7

Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
PromQL: Add functions
label_replaceandlabel_joinVersion info
26.5.1.817