Skip to content

Basic support for the PromQL dialect#75036

Merged
nikitamikhaylov merged 14 commits intoClickHouse:masterfrom
vitlibar:add-promql-parser
Aug 23, 2025
Merged

Basic support for the PromQL dialect#75036
nikitamikhaylov merged 14 commits intoClickHouse:masterfrom
vitlibar:add-promql-parser

Conversation

@vitlibar
Copy link
Member

@vitlibar vitlibar commented Jan 26, 2025

Changelog category (leave one):

  • New Feature

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

Basic support for the PromQL dialect is added. To use it, set dialect='promql' in clickhouse-client, point it to the TimeSeries table using the setting promql_table_name='X' and execute queries like rate(ClickHouseProfileEvents_ReadCompressedBytes[1m])[5m:1m].
In addition you can wrap the PromQL query with SQL: SELECT * FROM prometheusQuery('up', ...);.
So far only functions rate, delta and increase are supported. No unary/binary operators. No HTTP API.

@robot-ch-test-poll2 robot-ch-test-poll2 added the submodule changed At least one submodule changed in this PR. label Jan 26, 2025
@alexey-milovidov alexey-milovidov mentioned this pull request Jan 26, 2025
76 tasks
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-feature Pull request with new product feature label Jan 26, 2025
@robot-ch-test-poll4
Copy link
Contributor

robot-ch-test-poll4 commented Jan 26, 2025

This is an automated comment for commit d0715d6 with description of existing statuses. It's updated for the latest CI running

❌ Click here to open a full report in a separate page

Check nameDescriptionStatus
BuildsThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS❌ failure
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests❌ failure
Successful checks
Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
BuzzHouse (asan)There's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
BuzzHouse (debug)There's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
BuzzHouse (msan)There's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
BuzzHouse (tsan)There's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
BuzzHouse (ubsan)There's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
ClickBenchRuns ClickBench with instant-attach table✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integration tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success

@vitlibar vitlibar force-pushed the add-promql-parser branch 4 times, most recently from 1261a10 to d0715d6 Compare January 26, 2025 23:31
@UnamedRus
Copy link
Contributor

This does feel somewhat unusual, as ClickHouse have 2 additional dialects (with others in mind), and they act as first level citizen(Kusto/PRQL). Any other reasons to wrap it in function?

@vitlibar
Copy link
Member Author

This does feel somewhat unusual, as ClickHouse have 2 additional dialects (with others in mind), and they act as first level citizen(Kusto/PRQL). Any other reasons to wrap it in function?

Yes, PromQL support in ClickHouse can be implemented as a dialect too. Though it requires specifying a TimeSeries table to use but that can be implemented via another setting.

Comment on lines +205 to +207
METRIC_NAME : [a-z_:] [a-z0-9_:]*;
LABEL_NAME : [a-z_] [a-z0-9_]*;

Copy link
Contributor

Choose a reason for hiding this comment

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

Since v3, all valid utf-8 chars are allowed https://prometheus.io/blog/2024/11/14/prometheus-3-0/#utf-8-support

@srikanthccv
Copy link
Contributor

@vitlibar curious if/how range vectors and resets will be handled.

@UnamedRus
Copy link
Contributor

Hm, PromQL doesn't have concept of table, right.

In that case, can it be just one more "endpoint", and PromQL will act like postgresql/mysql interfaces of ClickHouse. (with difference that it's not only protocol but also language)

May be, it even make sense to have "default" prometheus query endpoint, which will point to data from metrics/async_metrics/events _log tables. (but this req some adoption of them under TimeSeries schema, so it's like separate feature for now)

@clickhouse-gh
Copy link
Contributor

clickhouse-gh bot commented Apr 1, 2025

Dear @vitlibar, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message.

1 similar comment
@clickhouse-gh
Copy link
Contributor

clickhouse-gh bot commented Jun 3, 2025

Dear @vitlibar, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message.

@vitlibar vitlibar force-pushed the add-promql-parser branch from d0715d6 to eed38fc Compare June 20, 2025 13:10
@vitlibar vitlibar force-pushed the add-promql-parser branch from eed38fc to 0c74981 Compare July 1, 2025 10:02
@clickhouse-gh
Copy link
Contributor

clickhouse-gh bot commented Jul 1, 2025

Workflow [PR], commit [fafb184]

Summary:

job_name test_name status info comment
Stateless tests (amd_debug, distributed plan, s3 storage, parallel) failure
02443_detach_attach_partition FAIL

@vitlibar vitlibar force-pushed the add-promql-parser branch from 0c74981 to 3ec3134 Compare July 8, 2025 09:15
@vitlibar vitlibar marked this pull request as ready for review July 8, 2025 09:15
@vitlibar vitlibar changed the title [WIP] Add promql parser Add promql parser Jul 8, 2025
@vitlibar vitlibar force-pushed the add-promql-parser branch 2 times, most recently from 4f033ed to 838954f Compare July 10, 2025 01:41
@vitlibar vitlibar force-pushed the add-promql-parser branch 5 times, most recently from 9967d57 to 6da7128 Compare July 17, 2025 15:03
@vitlibar vitlibar force-pushed the add-promql-parser branch 3 times, most recently from ed23964 to 296aba1 Compare August 13, 2025 18:38
@vitlibar
Copy link
Member Author

This PR is ready for review, @GrigoryPervakov please take a look.

}

/// The argument can be nullable.
if (const auto * nullable_column = checkAndGetColumn<ColumnNullable>(&column_tags_array))
Copy link
Member

Choose a reason for hiding this comment

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

Can you add an example here?
Map/Array cannot be Nullable, and I can't find an example when this code works

Copy link
Member Author

Choose a reason for hiding this comment

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

I corrected this code in my new PR #93234. Map/Array can't be nullable, but instead of Map or Array just literal NULL can be passed to this argument.

Copy link
Member

Choose a reason for hiding this comment

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

Let's add some tests for these functions, maybe smth like this could be useful to ensure it is consistent

SELECT
  timeSeriesIdToTags(stored_id) = timeSeriesTagsGroupToTags(timeSeriesIdToTagsGroup(stored_id))
FROM (
  SELECT timeSeriesStoreTags(id , tags, '__name__', metric_name) as stored_id 
  FROM <some timeseries tags table>
) ORDER BY group

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a test named 03779_time_series_tags_functions.sql in my new PR #93234 to test such functions.

@nikitamikhaylov nikitamikhaylov changed the title Add promql parser Basic support for the PromQL dialect Aug 23, 2025
@nikitamikhaylov
Copy link
Member

Flaky test 02443_detach_attach_partition: #54748

@nikitamikhaylov nikitamikhaylov added this pull request to the merge queue Aug 23, 2025
Merged via the queue into ClickHouse:master with commit e59fe89 Aug 23, 2025
121 of 122 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 Aug 23, 2025
@JTCunning JTCunning added the comp-promql Issues related to the PromQL support and TimeSeries table engine. label Jan 12, 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-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants