Skip to content

Store promql_evaluation_time as a double, not a float - #120942

Merged
alexey-milovidov merged 8 commits into
ClickHouse:masterfrom
valerypetrov:fix/promql-evaluation-time-precision
Sep 27, 2026
Merged

alexey-milovidov merged 8 commits into
ClickHouse:masterfrom
valerypetrov:fix/promql-evaluation-time-precision

Conversation

@valerypetrov

@valerypetrov valerypetrov commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed promql_evaluation_time silently rounding the requested instant, which could make an instant query return a different sample. The setting also now accepts an integer Unix timestamp over the native protocol, which it previously refused.

Documentation entry for user-facing changes

The setting's description now states that the value is a Unix timestamp in seconds with an optional fraction. The reference page is regenerated from it.


promql_evaluation_time is the instant a PromQL query is evaluated at, but it was declared FloatAuto, so it was held in a 32-bit float. The spacing of a float at a present-day Unix timestamp is 128 seconds, so an explicit evaluation time was moved by up to a minute before the query ran.

That is a wrong answer, not a cosmetic one. With a series holding 100 at t-40 and 999 at t-10, asking for t-31:

prometheusQuery(table, 'm', t-31)                 ->  100          ground truth
SET dialect='promql' + promql_evaluation_time     ->  999          before
                                                  ->  100          after

The same float is why the two ways of setting it disagreed. SET converts through a Field and demands the conversion be exact, so it refused a plain Unix timestamp:

SET promql_evaluation_time = 1789683930
  ->  Code: 70. Field value 1789683930 is out of range of float type. (CANNOT_CONVERT_TYPE)

while the query parameter and the command-line flag parse from a string and rounded the same value without a word (getSetting returned 1789683968, 38 seconds later than asked). Every integer below 2^53 converts exactly to a double, so both paths now accept the value and land on the same instant.

DoubleAuto is all this needs: SettingFieldDoubleAuto and its explicit instantiation already exist in SettingsFields.h / SettingsFields.cpp and were simply unreachable, because the traits list in Settings.h had no entry for them. FloatAuto stays for opentelemetry_start_keeper_trace_probability, a probability in [0, 1] where a float is the right choice.

A value already stored in a settings profile is text and is parsed on load, so nothing needs migrating, and settings cross the wire as decimal text rather than raw bytes, so a mixed-version cluster cannot break on this. Both are behaviour changes in the sense that a value that used to be rounded now is not — it moves toward what the operator wrote.

Found while testing #117170 against real scraped Prometheus data. It reproduces identically on a plain TimeSeries table, so it is not that PR's, and the PR's diff does not touch this declaration.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.853-master (included in 26.10 and later)

The setting is read as the instant a PromQL query is evaluated at, but it was
declared FloatAuto, so it was held in a 32-bit float whose spacing at a present
day Unix timestamp is 128 seconds. An explicit evaluation time was therefore
moved by up to a minute before the query ran, which changes the sample an
instant query returns and not merely the timestamp it reports: asking for
1789683929 evaluated at 1789683968.

The same float is why SET and the query parameter disagreed about an integer.
SET converts through a Field and demands the conversion be exact, so it refused
a plain Unix timestamp with "is out of range of float type", while the query
parameter and the command line parse from a string and rounded the same value
without a word. Every integer below 2^53 converts exactly to a double, so both
paths now accept the value and land on the same instant.

DoubleAuto is the only change a setting needs here: SettingFieldDoubleAuto and
its explicit instantiation already exist, and only the traits list was missing
an entry for it. FloatAuto stays for the one probability setting that uses it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QtEKPyQDMCBZfJkiJcs789
@clickhouse-gh clickhouse-gh Bot added comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... external Author is not a member of the ClickHouse organization labels Sep 19, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Sep 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9ea4242]

Summary: ✅


AI Review

Summary

This PR changes promql_evaluation_time from FloatAuto to DoubleAuto, updates the client/local/server entrypoints that read it, and adds regression coverage for integer-second evaluation times. That removes the large present-day Float32 rounding bug, but it still does not preserve many fractional instants on higher-scale DateTime64 series because the setting is still materialized as a binary floating-point value before timestamp parsing.

Findings

⚠️ Majors

  • [src/Core/Settings.cpp:10461] promql_evaluation_time now accepts integer Unix timestamps, but it still silently changes non-binary-exact fractional timestamps on DateTime64(7+) TimeSeries tables. A value like 1700000100.0000001 is rounded when stored as Float64, and parseTimeSeriesTimestamp then truncates that rounded float to the table scale, so the dialect can still evaluate at the wrong instant and pick the wrong sample. The new .5 regression check does not catch this because 0.5 is exactly representable in binary.
    Suggested fix: preserve the original text / decimal form of the setting until parseTimeSeriesTimestamp parses it, or explicitly narrow and document the supported precision and add a focused regression test for that contract.
Final Verdict

⚠️ Request changes: the whole-second wrong-answer bug is fixed, but fractional promql_evaluation_time values can still evaluate at the wrong instant on supported high-precision DateTime64 series.

LLVM Coverage Report

Measured on commit 9ea4242.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 91.80% 91.70% -0.10%
Branches 79.60% 79.50% -0.10%

Changed lines: Changed C/C++ lines covered: 8/8 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 19, 2026
Comment thread src/Core/Settings.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 9ea42424cbc40a52979b03dc36d54b33ae2eff6c was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

Neither contract this change fixes had a test. The tree exercised the table
function's literal path and a cache test that passes an evaluation time without
checking which instant it lands on, so a later change to the field type, to its
string round-trip or to `SET` could bring back the minute-scale rounding or the
refusal of an integer Unix timestamp without anything failing.

The fixture is built around the arithmetic: two samples ten seconds apart, and
an evaluation time of 1700000100, which a 32-bit float rounds to 1700000128,
past the second one. The dialect returning 100 rather than 999 is therefore the
assertion that the instant survived. `SET` and the command line are both driven,
since they used to disagree about the same integer, and a fractional instant is
checked because a float32 could not carry one at all.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QtEKPyQDMCBZfJkiJcs789
@valerypetrov

Copy link
Copy Markdown
Contributor Author

should be ready for review

@valerypetrov

Copy link
Copy Markdown
Contributor Author

@groeneai , can you please check why the CI is failing here?

@groeneai

Copy link
Copy Markdown
Collaborator

Both reds come from master, not from your change.

BuzzHouse (amd_debug) fails with LOGICAL_ERROR: RWLockImpl::getLock(): RWLock is already locked in exclusive mode (STID 2043-36a4). That is a regression from my merged #119105 (TRUNCATE over an Alias table), reported in #121129, and my fix is open in #121134. It is not specific to your branch: over the last 5 days CIDB has the same signature on master itself (BuzzHouse (amd_tsan), 2026-09-21) and on 11 other pull requests. BuzzHouse builds random statement sequences, so a given run reds only when the sequence reaches that path. Mergeable Check is red only because it aggregates this job.

Build profile diff fails with RuntimeError: CI logs cluster query failed in ci/jobs/build_profile_diff_job.py: the job's read of the shared CI logs cluster got no answer, so it measured nothing about your change. #121048 fixed exactly that, merged today at 16:14 UTC, after your run started at 01:07 UTC: the read now raises LogClusterUnavailable and the job reports green when the cluster is unavailable instead of failing. The cluster outage itself is tracked in #120462.

So there is nothing to fix on your side. Merging master now picks up #121048, and the BuzzHouse red clears once #121134 lands.

@nikitamikhaylov nikitamikhaylov self-assigned this Sep 22, 2026
@nikitamikhaylov
nikitamikhaylov added this pull request to the merge queue Sep 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 23, 2026
valerypetrov and others added 2 commits September 22, 2026 19:26
The precision test only writes external samples and tags. Let `TimeSeries`
generate its unused metric-families target instead of defining an external
table with the pre-version-6 `metric_family_name` column. This keeps the
fixture compatible with both the PR base and current master without changing
the evaluation-time assertions.

Related: ClickHouse#120942 (comment)
Related: ClickHouse#119226
CI: https://github.com/ClickHouse/ClickHouse/actions/runs/35799204924
Picks up ClickHouse#121820, which fixed the REPLICA_ALREADY_EXISTS race in
test_active_node_owned_by_another_server that was the only diff-unrelated red.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@valerypetrov

Copy link
Copy Markdown
Contributor Author

@nikitamikhaylov , can you please recheck this one? I modified test which was failing on master.

…on-time-precision

Master moved the settings change history into the setting declarations,
which conflicted with this branch's change of promql_evaluation_time from
FloatAuto to DoubleAuto in Settings.cpp. Keep master's inline history rows
and apply the branch's type and description on top. The default stays
'auto', so no new history row is needed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Core/Settings.cpp
\
DECLARE_WITH_ALIAS(FloatAuto, promql_evaluation_time, Field("auto"), R"(
Sets the evaluation time to be used with promql dialect. 'auto' means the current time.
DECLARE_WITH_ALIAS(DoubleAuto, promql_evaluation_time, Field("auto"), R"(

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.

DoubleAuto fixes the minute-scale Float32 rounding, but it still loses many fractional instants before parseTimeSeriesTimestamp sees them. At DateTime64(7+) scales a present-day value like 1700000100.0000001 cannot be represented exactly as Float64; by the time getFromFloat truncates float_value * scaleMultiplier, it becomes 1700000100.0000000. The timestamp parser already has exact String / Decimal carriers, but this setting declaration forces the value through a lossy binary float first.

The new regression test only uses 1700000100.5, which is exactly representable in binary and therefore misses this remaining wrong-answer case. If promql_evaluation_time is supposed to support fractional evaluation times at the table's native scale, please keep the original text / decimal form until parseTimeSeriesTimestamp parses it, or explicitly narrow the precision contract and test that narrower behavior.

@clickhouse-gh

clickhouse-gh Bot commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

PromQL Compliance Report

Baseline: S3 master a70e6fb20

Suite Baseline Current Delta
Prometheus compliance 98.70% 98.70% +0.00%
Extended support (upstream engine tests) 84.56% 84.56% +0.00%
Suite Passed Failed Unsupported
Prometheus compliance 532 -> 532 (+0) 3 -> 3 (+0) 4 -> 4 (+0)
Extended support (upstream engine tests) 619 -> 619 (+0) 95 -> 95 (+0) 18 -> 18 (+0)

Extended support (upstream engine tests): native-histogram exclusions: 149; excluded assertions: 248; upstream 3da2514eff5c.

Note: Prometheus compliance score is unchanged vs baseline.

Uploaded compliance JSON for this PR commit

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 27, 2026
Merged via the queue into ClickHouse:master with commit 48f30f2 Sep 27, 2026
340 of 341 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... external Author is not a member of the ClickHouse organization pr-bugfix Pull request with bugfix, not backported by default 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