Skip to content

PromQL: support literals#96739

Merged
nikitamikhaylov merged 7 commits intoClickHouse:masterfrom
vitlibar:promql-support-literals
Feb 20, 2026
Merged

PromQL: support literals#96739
nikitamikhaylov merged 7 commits intoClickHouse:masterfrom
vitlibar:promql-support-literals

Conversation

@vitlibar
Copy link
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

PromQL: support literals

Part of #89356

@clickhouse-gh
Copy link
Contributor

clickhouse-gh bot commented Feb 12, 2026

Workflow [PR], commit [f172a3a]

Summary:

job_name test_name status info comment
Stress test (amd_debug) failure
Segmentation fault (STID: 2468-4b95) FAIL cidb, issue ISSUE EXISTS

@clickhouse-gh clickhouse-gh bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Feb 12, 2026
@vitlibar vitlibar force-pushed the promql-support-literals branch from c466a2c to adb6d66 Compare February 12, 2026 12:11
writeString("\"value\":[", response);

// Write timestamp
if (result_block.has(TimeSeriesColumnNames::Timestamp))
Copy link
Member Author

@vitlibar vitlibar Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to send Inf and NaN via HTTP API like this, so I've created a separate function for writing scalars here.

@vitlibar vitlibar requested a review from Copilot February 12, 2026 12:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@vitlibar vitlibar force-pushed the promql-support-literals branch from adb6d66 to 930a535 Compare February 12, 2026 12:34
@vitlibar vitlibar added the comp-promql Issues related to the PromQL support and TimeSeries table engine. label Feb 12, 2026
@vitlibar
Copy link
Member Author

Ready for review

@vitlibar
Copy link
Member Author

vitlibar commented Feb 20, 2026

I'll fix the test (it conflicted with #97063)

@nikitamikhaylov
Copy link
Member

^^ The latest commit fixes only a unit test and all the unit tests checks passed.

@nikitamikhaylov nikitamikhaylov added this pull request to the merge queue Feb 20, 2026
Merged via the queue into ClickHouse:master with commit 08b5125 Feb 20, 2026
123 of 146 checks passed
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-promql Issues related to the PromQL support and TimeSeries table engine. pr-not-for-changelog This PR should not be mentioned in the changelog 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.

4 participants