Skip to content

[WIP] Implement SELECT from TimeSeries - #106010

Closed
vitlibar wants to merge 5 commits into
ClickHouse:masterfrom
vitlibar:select-from-time-series
Closed

vitlibar wants to merge 5 commits into
ClickHouse:masterfrom
vitlibar:select-from-time-series

Conversation

@vitlibar

@vitlibar vitlibar commented May 27, 2026 •

Copy link
Copy Markdown
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):

Implement SELECT from TimeSeries


Workflow [PR]
Sync PR [sync-upstream/pr/106010]

@vitlibar vitlibar added the comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... label May 27, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [63940ef]

Summary: ❌

job_name test_name status info comment
Style check FAIL
cpp FAIL cidb
Fast test FAIL
04267_time_series_selector_match_tags FAIL cidb
Build (arm_tidy) FAIL
Build ClickHouse FAIL cidb
Code Review DROPPED
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED
Build (amd_binary) DROPPED

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label May 27, 2026

auto join = make_intrusive<ASTTableJoin>();
join->kind = JoinKind::Left;
join->strictness = JoinStrictness::Semi;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This generated query selects time_series from the right subquery, but SEMI LEFT JOIN only preserves the left-side columns and uses the right side only as an existence filter. For a query like SELECT metric_name, time_series FROM prometheus, the plan either cannot resolve time_series from __samples_grouped, or it drops series that have a tags row but no samples row. Please use a normal left join against the grouped samples subquery and materialize an empty time_series value for missing matches.


auto samples_table_id = storage.getTargetTableID(ViewTarget::Samples, context);
if (!need_tags)
return makeBareSamplesSelect(samples_table_id);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Driving the time_series-only path from samples changes the TimeSeries row contract. TimeSeriesSink writes a tags row even when the inserted time_series array is empty, but it writes no samples rows in that case, so SELECT time_series FROM prometheus will omit those series entirely. The read path should still drive from tags and left-join the grouped samples, even when no tag columns are requested.

/// the samples-side branches.
ASTPtr makeTimeSeriesAggregate()
{
auto group_array = makeASTFunction("groupArray",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

groupArray(tuple(timestamp, value)) does not preserve the time-series aggregate semantics used elsewhere in this subsystem. Once the samples table is read in multiple blocks or after merges, the array order is not guaranteed, and duplicate timestamps are not normalized the way timeSeriesGroupArray does. Please build time_series with timeSeriesGroupArray(timestamp, value) or otherwise enforce the same timestamp ordering and duplicate handling.

{
String pattern = matcher.label_value;
if (!pattern.starts_with('^'))
pattern.insert(0, "^");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PromQL regex matchers are anchored as a whole expression, but adding ^ and $ directly changes the meaning of patterns with alternation. For example, {job=~"api|web"} should match only api or web, while this compiles to ^api|web$, which also matches values like api-v1 and db-web. Wrap the original regex when anchoring, for example ^(?:<regex>)$, and add a test with an alternation matcher.

@nikitamikhaylov nikitamikhaylov self-assigned this May 27, 2026
JTCunning added a commit to JTCunning/ClickHouse that referenced this pull request Jul 1, 2026
… 1.0

Replace the flat per-sample schema (name, value, labels, timestamp, ...)
with a per-series schema aligned to the TimeSeries engine's own columns:
metric_name, metric_family, help, type, unit, tags Array(Tuple(String,
String)), and time_series Array(Tuple(DateTime64(3), Float64)). One row is
one series and its points live in the time_series array.

The output format groups rows by metric_family, emits # HELP/# TYPE/# UNIT
once per family, and conforms to OpenMetrics 1.0: the version=1.0.0 content
type, the type vocabulary (untyped -> unknown), the counter _total sample
contract, and the unit suffix rule. The input format buffers to # EOF,
groups samples by (metric_name, tags) into a time_series array, and derives
metric_family from declared families and the sample-name suffix rules.

The time_series value type is required to be Float64 on both input and
output, matching the engine column. Rewrites the stateless 04003 test and
the Prometheus/OpenMetrics export integration test for the new schema; the
SELECT * FROM ts round-trip is staged but skipped pending ClickHouse#106010.
@vitlibar
vitlibar force-pushed the select-from-time-series branch from 3110fe6 to eb9ce7f Compare July 13, 2026 13:56
@vitlibar
vitlibar force-pushed the select-from-time-series branch 2 times, most recently from 42b1f6f to 28877fe Compare August 17, 2026 21:12
Move the `StorageTimeSeries` check into `storage_requires_filter_collection`,
which the `StorageMerge` branch also uses via `hasChildTable`. Now filter
collection triggers not only when a TimeSeries table is queried directly,
but also when it is read through a `Merge` table, so a `WHERE` above the
`Merge` is captured and forwarded down to the TimeSeries inner table reads.
@vitlibar

Copy link
Copy Markdown
Member Author

I'll split the work to a couple of PRs:

  1. Implement SELECT query from TimeSeries (part 1) #115622

@clickhouse-gh

clickhouse-gh Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

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 closed this Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants