Skip to content

Make the toYYYYMM documentation example independent of the current date - #117459

Merged
Algunenano merged 1 commit into
ClickHouse:masterfrom
groeneai:toyyyymm-doc-example-independent-of-current-date
Sep 1, 2026
Merged

Algunenano merged 1 commit into
ClickHouse:masterfrom
groeneai:toyyyymm-doc-example-independent-of-current-date

Conversation

@groeneai

@groeneai groeneai commented Sep 1, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

The documented example of toYYYYMM no longer depends on the current date.

Description

Docs examples has been red on every PR since 2026-09-01 04:00 UTC.

src/Functions/toYYYYMM.cpp documented an example whose query reads the clock while its expected
output is a hardcoded literal:

SELECT toYYYYMM(now(), 'US/Eastern')   -- documented: 202608

tests/docs_examples/runner.py compares the documented response to the server output verbatim, so
202608 held only while the current month in US/Eastern was August 2026. At 2026-09-01 04:00 UTC
that timezone rolled into September, the query began returning 202609, and the comparison has
failed on every run since: in CIDB the Documentation examples sub-result went from 400 OK / 6 FAIL
in the preceding 24 hours to 0 OK / 12 FAIL afterwards, across 12 unrelated PRs. It entered the
baseline as passing on 2026-08-02 because it was true that day, so this is a latent time bomb:
bumping the number would only move the failure to 2026-10-01.

The fix makes the example clock-independent with the idiom its siblings already use (toYYYYMMDD,
toYYYYMMDDhhmmss, toYear, toMonth, toQuarter and toDayOfMonth all pin a fixed
toDateTime literal):

SELECT toYYYYMM(toDateTime('2026-01-01 03:04:05', 'UTC'), 'US/Eastern')   -- 202512

That input is 2025-12-31 22:04:05 in US/Eastern, so the timezone argument now visibly moves the
result down a month and a year; with now its effect was invisible on all but one day a month. The
expected output is a byte-exact capture from a real run.

I left the generated docs/** pages carrying the same stale value alone: they sit inside
autogenerated regions that ci/jobs/docs_autogen_nightly.py regenerates from this source.

The example fails 3/3 runs without this change and passes 6/6 with it, and altering one digit of the
new expected value turns it red again. Of all 2223 documented examples this was the only one pairing
a clock-reading query with a hardcoded response and no known-failures entry.

Failing report:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117427&sha=a27d7145482ec43f1f88038913acc7398113e78e&name_0=PR&name_1=Docs%20examples


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

Version info

  • Merged into: 26.9.1.487 (included in 26.9 and later)

The example paired a query that reads the clock with a hardcoded expected output:

    SELECT toYYYYMM(now(), 'US/Eastern')   ->   202608

`tests/docs_examples/runner.py` compares the documented response to the server's
output verbatim, after nothing but `str.strip`, and an `output` mismatch with no
entry in `tests/docs_examples/known_failures.txt` is verdict `unexpected`, which
fails the job. `202608` was true only while the current month in `US/Eastern` was
August 2026, so the example broke the instant that timezone rolled into September
at 2026-09-01 04:00 UTC. It had entered the baseline as passing on 2026-08-02
because it was correct that day, which is why nothing caught it earlier: a latent
time bomb rather than flakiness. Bumping the literal to `202609` would only move
the failure to 2026-10-01.

The replacement uses the idiom the immediate siblings already use, a fixed
`toDateTime` literal. `toYYYYMMDD`, `toYYYYMMDDhhmmss`, `toYear`, `toMonth`,
`toQuarter` and `toDayOfMonth` are all written that way.

    SELECT toYYYYMM(toDateTime('2026-01-01 03:04:05', 'UTC'), 'US/Eastern')   ->   202512

That instant is `2025-12-31 22:04:05` in `US/Eastern`, so the timezone argument
moves the answer down a month and a year, which makes its effect visible; with
`now` the two spellings of the query agreed on all but one day a month. Both
timezones are pinned in the query, so the value does not depend on the server or
the session timezone either.

The generated pages under `docs/` carry the same stale value and are deliberately
untouched: they lie inside autogenerated regions, and
`ci/jobs/docs_autogen_nightly.py` regenerates them from this registration.

An `unstable` entry in `known_failures.txt` was rejected as the alternative. It
accepts any outcome, so it would permanently retire the check for this example
and leave the published page showing a value that is wrong for readers eleven
months out of twelve. That treatment is right for `today` and `yesterday`, whose
subject is the clock; here the clock is incidental to what the example teaches.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 1, 2026
@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review - no findings; 2 nits noted, not blocking (click to expand)

The change was re-reviewed cold by an independent reviewer (no access to the author's evidence during
the review) and then by a second model. Both passed with no blocker and no major finding.

Independent cold review. Enumerated the carriers of the invariant from source before reading the
author's scope claim: 88 documentation examples pair a nondeterministic query with a hardcoded
response, of which 15 read the clock. Twelve are already baselined unstable in
tests/docs_examples/known_failures.txt; the four that are not (isConstant#3, timezoneOf#0,
IPv6NumToString#1, IPv6NumToString#2) are genuinely deterministic, because their documented value
does not move with the clock. Function/toYYYYMM#0 was the only unbaselined member of the narrower
dangerous class: reads the clock and documents a value that stays constant for a period, then
flips at a calendar boundary. Anything wrong on every run was forced into the baseline the day it was
written, so only a slow drifter can pass its baseline run and break later. Single site confirmed.

The documented value was checked without running anything, against a currently-passing sibling rather
than against the author's capture: toYYYYMMDD.cpp commits
toYYYYMMDD(toDateTime('2026-01-02 03:04:05','UTC'),'US/Eastern') = 20260101, which requires the
same UTC-5 offset over the same dates, so 202512 here follows. PrettyCompact renders
len(column_name) + 4: the sibling is 66 -> 70 wide, this one is 64 -> 68, and all three new lines
measure 68 with the correct box-drawing code points.

Oracle liveness traced rather than assumed: the example is not skipped by any of the runner's
--global-objects, external-call or documented-exception paths, its id is index-based so the retitle
orphans no baseline entry, and the comparison is str.strip and nothing else.

Leaving the generated docs/** pages untouched was verified in both directions:
check_autogenerated_regions only compares regions in docs files the PR changes, so this PR passes
it; had the generated pages been edited, the same blocking sub-check would have failed without the
pr-autogenerated-docs label.

💡 nit, noted not blocking - the changelog category could be Documentation rather than CI Fix or Improvement, since the diff is entirely documentation content. Kept as is: the in-tree rulebook
assigns CI-report fixes to CI Fix or Improvement, and both categories are changelog-exempt.

💡 nit, noted not blocking - line 18 of the same file writes YYYYMMDDToDate() with parentheses,
against the repository's preference for f over f(). It is pre-existing and untouched here;
correcting it would add an unrelated hunk to a CI fix.

Session id: cron:clickhouse-review-slot-8:20260901-063200

@clickhouse-gh clickhouse-gh Bot closed this Sep 1, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 1, 2026
@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. python3 tests/docs_examples/runner.py --filter '^toYYYYMM' against a server built from the unmodified base returns RC=1 with Function/toYYYYMM#0 [output], documented 202608 vs actual 202609, in 3 of 3 runs. A pure function of the wall clock: no fixture, no randomization, no timing.
b Root cause explained? Yes. The example's query reads the clock (SELECT toYYYYMM(now(), 'US/Eastern')) while its documented response is the hardcoded literal 202608. tests/docs_examples/runner.py compares the two verbatim after nothing but str.strip, and an output mismatch with no known_failures.txt entry is verdict unexpected, which fails the job. 202608 held only while the current month in US/Eastern was August 2026; that timezone rolled into September at 2026-09-01 04:00 UTC. The example entered the baseline as passing on 2026-08-02 because it was true that day, so it is a latent time bomb, not flakiness.
c Fix matches root cause? Yes: it removes the clock dependency itself. Rejected as band-aids: bumping 202608 to 202609 (re-breaks on 2026-10-01), an unstable entry in known_failures.txt (accepts any outcome, so it permanently destroys the check for this example and leaves the published page wrong for readers), dropping the documented response, and widening the comparison.
d Test intent preserved / new tests added? Yes, and strengthened. The example still teaches the YYYYMM conversion and the optional timezone argument, and now demonstrates the timezone argument better: measured 202601 without it against 202512 with it, whereas with now the two spellings agree on all but one day a month. Docs examples is itself the regression test for this defect and runs on this PR by construction, since the job digest includes the build paths (ci/defs/job_configs.py:1817-1820). Nothing was removed or weakened.
e Both directions demonstrated? Yes. Without the change: RC=1, 3 of 3 runs. With it: RC=0, 3 ok, 0 not ok, 6 of 6 runs. The two binaries carry distinct Build IDs (b355698d... and 721563ef...), each asserted against the server that produced its verdict via SELECT lower(buildId()). The filter also selects toYYYYMMDD and toYYYYMMDDhhmmss as a free control; both pass in every arm.
f Fix is general across code paths? Yes, measured rather than assumed, over all 2223 examples read from the running server's system.documentation. A deliberately broad clock and environment predicate leaves 64 examples with no baseline entry; sharpening it to the actual signature (query reads the clock and the documented response embeds a dated literal that would drift) leaves 0. The pre-fix example fed to that same predicate is caught, so the zero is a real absence rather than a predicate that cannot fire. Scope is a single site; no sweep is warranted.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. The new query pins both the input timezone ('UTC') and the output timezone ('US/Eastern'), so its value is independent of server and session configuration: measured 202512 under all seven of session_timezone = UTC, US/Eastern, Asia/Tokyo, Pacific/Kiritimati, Pacific/Midway, Europe/Moscow, America/Sao_Paulo. The type-wrapper matrix does not apply: no code path changes, only documentation metadata.
h Backward compatible? (maintainer-approved exception only) N/A. FunctionDocumentation is metadata only: no wire format, no serialization, no setting default, no compiled behaviour change, and no SettingsChangesHistory.cpp implication.
i Invariants and contracts preserved? Yes. The invariant restored is that a documented response must be a pure function of the example's own query text. The example id is index-based (runner.py:158), so Function/toYYYYMM#0 is unchanged by the retitling and no baseline entry becomes stale: both full runs report stale: 0 against 124 known. The documented response is a byte-exact capture taken through the runner's own client and output settings, so the response-equals-server-output contract holds by construction rather than by hand-drawing the box.

Session id: cron:clickhouse-impl-slot-6:20260901-054600

@clickhouse-gh

clickhouse-gh Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [26de122]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6) ERROR
Container memory budget exceeded (/docker) ERROR cidb IGNORED

AI Review

Summary

This PR replaces the toYYYYMM documentation example's now()-based query with a fixed toDateTime literal so the documented response no longer drifts at month boundaries. I reviewed the current diff, the surrounding FunctionDocumentation context, and the existing PR discussion, and I did not find a remaining issue worth posting inline.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

Measured on commit 26de122.

Metric Baseline Current Δ
Lines 88.60% 88.60% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 80.90% 80.90% +0.00%

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

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 1, 2026
@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

cc @Ergus @antaljanosbenjamin, could you review this? The toYYYYMM documentation example paired a now-based query with the hardcoded response 202608, so Docs examples has been red on every PR since US/Eastern rolled into September; this pins a fixed toDateTime literal, the idiom toYYYYMMDD and toYear already use.

@clickhouse-gh

clickhouse-gh Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 26de122fd with master 38a9ca207 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 9f35a2b2a; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 6 s compile time in total, 7 of them have a recent master baseline.

Job report

@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 26de122

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6) / Container memory budget exceeded (/docker) host container-budget kill; the unreclaimable /docker leaf was sized last, so its cap was the only one that bound #117412 (external, merged 2026-09-01T11:31:33Z)

The shard died before any test could be attributed, so the 2520 other rows on that job are
passengers of the same kill rather than separate failures. #117412 names this exact signature on
the ASan+UBSan shards in its own diff. It merged at 11:31:33Z and this job started at 11:0xZ, so
the tree that ran predates the fix; I verified the fix is absent at 26de122 and present at its merge
commit d65ba26ae8b3. Nothing else on the head failed.

Session id: cron:our-pr-ci-monitor:20260901-123000

@Algunenano
Algunenano disabled auto-merge September 1, 2026 13:35
@Algunenano
Algunenano added this pull request to the merge queue Sep 1, 2026
Merged via the queue into ClickHouse:master with commit 8627fa2 Sep 1, 2026
342 of 344 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 1, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 5, 2026
Picks up three merged fixes that post-date this branch's previous master
merge and that its CI run was red on:

  ClickHouse#117580  Bugfix validation master-build lookup for the new S3 prefix
  ClickHouse#117459  date-dependent toYYYYMM documentation example
  ClickHouse#117412  integration tests' nested-container memory budget

Co-Authored-By: Claude Opus 5 <[email protected]>
alexey-milovidov added a commit to groeneai/ClickHouse that referenced this pull request Sep 19, 2026
The branch was 25480 commits behind `master`. The merge is clean: `MergeTask.cpp`
changed a lot on `master` since the fork point, but not in the two regions this
branch edits - the `TTLDrop` short-circuit in
`ExecuteAndFinalizeHorizontalPart::prepare` and the segment selection in
`MergeTextIndexStage::prepare`.

Refreshing also picks up ClickHouse#117459, which fixes the `Docs examples` failure on the
previous head: the `toYYYYMM` documentation example pinned its output to the
month it was written in.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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 groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-ci 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.

3 participants