PromQL: Add set binary operators#105000
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for the PromQL set binary operators and, or, and unless to the PrometheusQueryToSQL converter. Each operator is translated into a multi-step SQL pipeline that joins the left/right vector grids on the appropriate group keys (respecting on(...)/ignoring(...)) and combines per-timestamp samples accordingly. Note that group_left/group_right modifiers are explicitly rejected for set operators, matching Prometheus semantics.
Changes:
- New files
applyBinaryOperatorAnd.{h,cpp},applyBinaryOperatorOr.{h,cpp},applyBinaryOperatorUnless.{h,cpp}implementing the three set operators, including a sharedcheckArgumentTypesForSetBinaryOperatorhelper. - Dispatch wiring in
applyBinaryOperator.cppfor the three new operator names; introduces a newJoinCountscolumn-name constant inTimeSeriesColumnNames.h. - Integration tests in
test_evaluation.py::test_set_binary_operatorscovering basic operators,on(...)/ignoring(...)matching, andgroup_left/group_rightrejection.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Storages/TimeSeries/TimeSeriesColumnNames.h | Adds JoinCounts column constant used by set-operator subqueries. |
| src/Storages/TimeSeries/PrometheusQueryToSQL/applyBinaryOperator.cpp | Dispatches and/or/unless to the new implementations. |
| src/Storages/TimeSeries/PrometheusQueryToSQL/applyBinaryOperatorAnd.{h,cpp} | Implements and (LEFT SEMI join on grouping keys) and the shared argument-type check. |
| src/Storages/TimeSeries/PrometheusQueryToSQL/applyBinaryOperatorUnless.{h,cpp} | Implements unless (LEFT ANY join, NULL-out matched timestamps). |
| src/Storages/TimeSeries/PrometheusQueryToSQL/applyBinaryOperatorOr.{h,cpp} | Implements or via 4-step pipeline combining left-priority samples with right-only samples via UNION ALL. |
| tests/integration/test_prometheus_protocols/test_evaluation.py | Adds test_set_binary_operators covering all three operators, matching modifiers, and grouping-modifier errors. |
a042d36 to
6764753
Compare
038efb5 to
4729ffa
Compare
4729ffa to
7e54fce
Compare
LLVM Coverage ReportChanged lines: 92.75% (256/276) · Uncovered code |
leshikus
left a comment
There was a problem hiding this comment.
Generally look good, though this is not my area of expertise. It seems checkArgumentTypesForSetBinaryOperator can be moved to setBinaryOperator.{h,cpp} instead of being at applyBinaryOperatorAnd.h

Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
PromQL: Add set binary operators
and,or,unlessThis was a part of #98948 (0c63be2) which wasn't merged
Version info
26.5.1.810