PromQL: support literals#96739
Conversation
|
Workflow [PR], commit [f172a3a] Summary: ⏳
|
c466a2c to
adb6d66
Compare
| writeString("\"value\":[", response); | ||
|
|
||
| // Write timestamp | ||
| if (result_block.has(TimeSeriesColumnNames::Timestamp)) |
There was a problem hiding this comment.
The second main change of this PR is here in PrometheusHTTPProtocolAPI: since after #95673 the result of the converter always has the same columns depending on the result type (SCALAR/STRING/INSTANT_VECTOR/RANGE_VECTOR), we don't really need to do checks like this. Also I moved some code in PrometheusHTTPProtocolAPI to optimize writing.
| { | ||
| if (value < 0) | ||
| response.write('-'); | ||
| writeString("Inf", response); |
There was a problem hiding this comment.
We need to send Inf and NaN via HTTP API like this, so I've created a separate function for writing scalars here.
There was a problem hiding this comment.
Pull request overview
Adds PromQL literal support end-to-end (parser → PromQL-to-SQL conversion → HTTP API JSON formatting), with new tests verifying scalar and string literal evaluation.
Changes:
- Add conversion for scalar and string literals into constant query pieces.
- Refactor Prometheus HTTP API response writer to handle scalar/string/vector/matrix via a unified path and improved JSON escaping.
- Add integration + parser tests for numeric, duration, and string literals.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/integration/test_prometheus_protocols/test_evaluation.py | Adds integration coverage for scalar/string/duration/hex/scientific literals. |
| src/Storages/TimeSeries/PrometheusQueryToSQL/fromSelector.cpp | Renames evaluation range getter usage to node_range_getter. |
| src/Storages/TimeSeries/PrometheusQueryToSQL/fromLiteral.h | Declares literal-to-SQL conversion entry points. |
| src/Storages/TimeSeries/PrometheusQueryToSQL/fromLiteral.cpp | Implements scalar and string literal conversion into SQLQueryPiece. |
| src/Storages/TimeSeries/PrometheusQueryToSQL/applyOffset.cpp | Switches to node_range_getter for time bounds/step handling. |
| src/Storages/TimeSeries/PrometheusQueryToSQL/applyFunctionOverRange.cpp | Switches to node_range_getter and renames locals accordingly. |
| src/Storages/TimeSeries/PrometheusQueryToSQL/ConverterContext.h | Renames context member to node_range_getter. |
| src/Storages/TimeSeries/PrometheusQueryToSQL/ConverterContext.cpp | Updates initialization for renamed getter. |
| src/Storages/TimeSeries/PrometheusQueryToSQL/Converter.cpp | Adds handling for Scalar and StringLiteral nodes. |
| src/Storages/TimeSeries/PrometheusHTTPProtocolAPI.h | Refactors query JSON writing API and adds FormatSettings member. |
| src/Storages/TimeSeries/PrometheusHTTPProtocolAPI.cpp | Implements unified JSON writer + scalar/string support; changes error handling and escaping. |
| src/Parsers/Prometheus/tests/gtest_PrometheusQueryTree.cpp | Adds parser tests for string literals/escapes/unicode. |
…e after changing columns.
adb6d66 to
930a535
Compare
|
Ready for review |
|
I'll fix the test (it conflicted with #97063) |
|
^^ The latest commit fixes only a unit test and all the unit tests checks passed. |
08b5125
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
PromQL: support literals
Part of #89356