Skip to content

PromQL support: Add functions for working with tags#93234

Merged
vitlibar merged 8 commits intoClickHouse:masterfrom
vitlibar:add-functions-working-with-tags
Jan 16, 2026
Merged

PromQL support: Add functions for working with tags#93234
vitlibar merged 8 commits intoClickHouse:masterfrom
vitlibar:add-functions-working-with-tags

Conversation

@vitlibar
Copy link
Member

@vitlibar vitlibar commented Dec 30, 2025

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: Add functions for working with tags (labels):

  • Add new functions: timeSeriesTagsToGroup(), timeSeriesExtractTag(), timeSeriesCopyTags(), timeSeriesRemoveTags(), timeSeriesJoinTags(), timeSeriesReplaceTag()
  • Rename functions timeSeriesTagsGroupToTags() to timeSeriesGroupToTags(), timeSeriesIdToTagsGroup() to timeSeriesIdToGroup()

Part of #89356

@vitlibar vitlibar requested review from azat and Copilot and removed request for azat December 30, 2025 16:20
@clickhouse-gh
Copy link
Contributor

clickhouse-gh bot commented Dec 30, 2025

Workflow [PR], commit [2feef4e]

Summary:

job_name test_name status info comment
Integration tests (amd_asan, targeted) error

@clickhouse-gh clickhouse-gh bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Dec 30, 2025
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

This PR adds comprehensive support for working with time series tags in PromQL by introducing new functions and refactoring existing ones. The changes include:

  • Adding new tag manipulation functions: timeSeriesTagsToGroup(), timeSeriesExtractTag(), timeSeriesCopyTag(), timeSeriesCopyTags(), timeSeriesRemoveTags(), timeSeriesJoinTags(), timeSeriesReplaceTag(), timeSeriesRemoveTag(), timeSeriesRemoveAllTagsExcept()
  • Renaming functions for consistency: timeSeriesTagsGroupToTags()timeSeriesGroupToTags(), timeSeriesIdToTagsGroup()timeSeriesIdToGroup()
  • Refactoring the ContextTimeSeriesTagsCollector class to support group-based operations
  • Extracting common helper functions into TimeSeriesTagsFunctionHelpers

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/queries/0_stateless/03709_time_series_tags_functions.sql Test file exercising all new time series tag manipulation functions
tests/queries/0_stateless/03709_time_series_tags_functions.reference Expected output for the test cases
src/Interpreters/ContextTimeSeriesTagsCollector.h Major refactoring: introduced Group type, renamed functions, added new tag manipulation methods
src/Interpreters/ContextTimeSeriesTagsCollector.cpp Implementation of tag manipulation logic including remove, copy, join, and replace operations
src/Interpreters/Context.h Changed return type from reference to shared_ptr for thread safety
src/Interpreters/Context.cpp Updated implementation to match new return type
src/Functions/TimeSeries/timeSeriesTagsToGroup.cpp New function to convert tags to a group identifier
src/Functions/TimeSeries/timeSeriesStoreTags.cpp Refactored to use helper functions and support nullable IDs
src/Functions/TimeSeries/timeSeriesReplaceTag.cpp New function implementing PromQL label_replace() logic
src/Functions/TimeSeries/timeSeriesRemoveTags.cpp New function to remove multiple tags from a group
src/Functions/TimeSeries/timeSeriesRemoveTag.cpp New function to remove a single tag from a group
src/Functions/TimeSeries/timeSeriesRemoveAllTagsExcept.cpp New function to keep only specified tags
src/Functions/TimeSeries/timeSeriesJoinTags.cpp New function implementing PromQL label_join() logic
src/Functions/TimeSeries/timeSeriesIdToTags.cpp Refactored to use helper functions and new collector API
src/Functions/TimeSeries/timeSeriesIdToGroup.cpp New function replacing timeSeriesIdToTagsGroup with alias for backward compatibility
src/Functions/TimeSeries/timeSeriesGroupToTags.cpp New function replacing timeSeriesTagsGroupToTags with alias for backward compatibility
src/Functions/TimeSeries/timeSeriesExtractTag.cpp New function to extract a single tag value from a group
src/Functions/TimeSeries/timeSeriesCopyTags.cpp New function to copy multiple tags between groups
src/Functions/TimeSeries/timeSeriesCopyTag.cpp New function to copy a single tag between groups
src/Functions/TimeSeries/TimeSeriesTagsFunctionHelpers.h Header for common helper functions used across time series functions
src/Functions/TimeSeries/TimeSeriesTagsFunctionHelpers.cpp Implementation of argument validation, extraction, and column creation helpers
Comments suppressed due to low confidence (1)

src/Interpreters/ContextTimeSeriesTagsCollector.cpp:1

  • The logic is inverted. When null_map[i] is true (indicating a NULL value), the ID should be reset to IDType{}. The condition should be if (null_map[i]).
#include <Interpreters/ContextTimeSeriesTagsCollector.h>

@vitlibar vitlibar force-pushed the add-functions-working-with-tags branch 2 times, most recently from 3fcac07 to 634313c Compare December 30, 2025 23:18
@vitlibar vitlibar requested a review from Copilot December 30, 2025 23:24
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

Copilot reviewed 25 out of 25 changed files in this pull request and generated 4 comments.

@vitlibar vitlibar force-pushed the add-functions-working-with-tags branch from 634313c to d194b80 Compare December 30, 2025 23:48
@vitlibar vitlibar requested a review from Copilot December 30, 2025 23:48
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

Copilot reviewed 25 out of 25 changed files in this pull request and generated 6 comments.

@vitlibar vitlibar force-pushed the add-functions-working-with-tags branch 2 times, most recently from 95a64ad to d9561bc Compare December 31, 2025 00:20
@vitlibar vitlibar marked this pull request as ready for review December 31, 2025 00:34
@vitlibar vitlibar force-pushed the add-functions-working-with-tags branch from d9561bc to 239bca3 Compare January 1, 2026 10:04
@vitlibar
Copy link
Member Author

vitlibar commented Jan 5, 2026

@GrigoryPervakov please take a look at this PR, it improves the functions for working with time series tags added in #75036

@vitlibar vitlibar force-pushed the add-functions-working-with-tags branch from 239bca3 to 2ef66ce Compare January 5, 2026 20:24
@JTCunning JTCunning added the comp-promql Issues related to the PromQL support and TimeSeries table engine. label Jan 12, 2026
Copy link
Member

@GrigoryPervakov GrigoryPervakov left a comment

Choose a reason for hiding this comment

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

LGTM, we also agreed that some new functions, like timeSeriesReplaceTag, need a link to the Prometheus docs

@vitlibar vitlibar enabled auto-merge January 14, 2026 21:20
@vitlibar vitlibar added this pull request to the merge queue Jan 16, 2026
Merged via the queue into ClickHouse:master with commit 98416ad Jan 16, 2026
257 of 260 checks passed
@vitlibar vitlibar deleted the add-functions-working-with-tags branch January 16, 2026 22:58
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jan 16, 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.

5 participants