Skip to content

Revert "Revert "Fix propagation of settings in accurateCastOrDefault"" - #114912

Merged
alexey-milovidov merged 17 commits into
masterfrom
revert-114911-revert-109946-respect-settings-accurate-cast-or-default
Aug 20, 2026
Merged

alexey-milovidov merged 17 commits into
masterfrom
revert-114911-revert-109946-respect-settings-accurate-cast-or-default

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 15, 2026 •

Copy link
Copy Markdown
Member

Restores propagation of query settings in accurateCastOrDefault and preserves successful source NULLs encoded by Dynamic and Variant.

Related: #114911
Depends on #114769

Changelog category (leave one):

  • Bug Fix

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

  • Fix propagation of query settings and NULL handling in accurateCastOrDefault.

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

Version info

  • Backported to: 26.7.5.9, 26.6.4.15, 26.5.8.12, 26.3.23.3, 25.8.34.8

@clickhouse-gh

clickhouse-gh Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cd98c24]

Summary: ✅


AI Review

Summary

This PR restores accurateCastOrDefault to the shared cast-resolution path so it respects query settings, timezone substitution, and DataTypeValidationSettings the same way as CAST and accurateCastOrNull, and it fixes the handling of successful source NULLs versus real conversion failures across Nullable, Dynamic, Variant, and LowCardinality(Nullable(...)) cases. After checking the current code, the PR discussion, and the added regressions, I did not find a remaining correctness or compatibility issue worth posting as a new review comment.

Final Verdict

✅ No new findings.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.80% 86.90% +0.10%
Functions 91.90% 92.00% +0.10%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 66/70 (94.29%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Aug 15, 2026
Comment thread src/Functions/castOrDefault.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing cd98c2445 with master 747e52eb5 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 702.05 MiB 699.02 MiB -3.03 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes

5 object files changed (+32.17 KiB total), 0 added.

Object file Master PR Δ
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/castOrDefault.cpp.o 1.10 MiB 1.13 MiB +30.61 KiB (+2.71%)

737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Closing as obsolete: the PR head commit f17baeb60398 is already contained in current master (83564faa3faa). All CI checks passed and there are no unresolved review threads.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

^ It's not clear to me.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default and removed pr-not-for-changelog This PR should not be mentioned in the changelog labels Aug 15, 2026
Comment thread src/Functions/castOrDefault.cpp Resolved
Comment thread src/Functions/castOrDefault.cpp Resolved
Comment thread src/Functions/castOrDefault.cpp Resolved
Comment thread src/Functions/castOrDefault.cpp Resolved
Do not wrap target types that encode NULL natively in an outer `Nullable`.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Addressed the unresolved cast_keep_nullable review in 853ee20: native NULL targets now avoid an invalid outer Nullable, with regressions for Dynamic, Variant, and LowCardinality(Nullable(...)).

Comment thread src/Functions/castOrDefault.cpp Resolved
@Avogar Avogar added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Aug 17, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

The pr-must-backport label produced five backports of this PR, and three of them do not compile.

backport base Build jobs red
#115535 25.8 7
#115536 26.3 7
#115537 26.5 7
#115538 26.6 0 (green)

All 21 red jobs die at the same translation unit with the same error:

src/Functions/castOrDefault.cpp:49:51: error: no member named 'createNullMap' in 'DB::ColumnVariant'
src/Functions/castOrDefault.cpp:51:32: error: no member named 'createNullMap' in 'DB::ColumnVariant'

The cherry-pick applied cleanly because nothing conflicted: this PR restores the caller, and the callee is what those branches lack. ColumnVariant::createNullMap() was added by 01da8f1d1d66 (#105467, @ Avogar), which carries no backport label. Declarations of it in src/Columns/ColumnVariant.h, measured at each ref:

25.8: 0   26.3: 0   26.5: 0   26.6: 1   26.7: 1   master: 1

26.6 is green for exactly that reason.

If you want the prerequisite to land first, I measured how far it ports. Simulating the cherry-pick of 01da8f1d with git merge-tree:

  • 26.3 and 26.5: clean, 5 files, +102/-19
  • 25.8: conflicts in src/Functions/FunctionsConversion.h

So v26.3-must-backport on #105467 covers both cleanly portable branches, and expands to [26.3, 26.5, 26.6, 26.7] with 26.6/26.7 skipped as empty since they already contain it. 25.8 needs a hand-resolved port or dropping #115535, which is a separate call.

I have not touched the robot's PRs and I am not hand-authoring release-branch ports, per the label route you confirmed on #111910. Flagging the measurement so the decision is yours.

robot-ch-test-poll4 added a commit that referenced this pull request Aug 20, 2026
Cherry pick #114912 to 26.7: Revert "Revert "Fix propagation of settings in `accurateCastOrDefault`""
robot-clickhouse added a commit that referenced this pull request Aug 20, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 20, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 20, 2026
Backport #114912 to 26.7: Revert "Revert "Fix propagation of settings in `accurateCastOrDefault`""
alexey-milovidov added a commit that referenced this pull request Aug 21, 2026
Backport #114912 to 26.5: Revert "Revert "Fix propagation of settings in `accurateCastOrDefault`""
clickhouse-gh Bot pushed a commit that referenced this pull request Aug 23, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 23, 2026
Backport #114912 to 26.6: Revert "Revert "Fix propagation of settings in `accurateCastOrDefault`""
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

Gentle ping on the open decision here: #115535 (25.8) and #115536 (26.3) still do not compile, because they restore the caller while those branches lack the callee ColumnVariant::createNullMap(), added by #105467 which carries no backport label. Measurement and the port simulation are in #114912 (comment). @Avogar, applying v26.3-must-backport to #105467 would land the prerequisite on both cleanly portable branches; 25.8 needs a hand-resolved port or dropping #115535, which is a separate call. I am not hand-authoring release-branch ports, so the call is yours.

alexey-milovidov added a commit that referenced this pull request Aug 24, 2026
The tests backported with #114912 assert behavior that comes from other,
unbackported master changes:
- `04510_accurateCastOrDefault_settings`: the time-zone substitution block
  needs master's `substituteTimeZoneInDateTimeType` in `CastOverloadResolverImpl`.
- `04512_accurateCastOrDefault_nullable_target`: the `Dynamic` and
  `LowCardinality(Nullable(...))` targets need master's `canContainNull`
  check in `CastOverloadResolverImpl::getReturnTypeImpl` (25.8 still has
  `isVariant`, so `makeNullable(Dynamic)` throws ILLEGAL_TYPE_OF_ARGUMENT).

Same trim as the 26.3 backport #115536. Both trimmed tests verified locally
against this PR's own CI binary (25.8.33.1).

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115535&sha=a4fa72b7604c3af05e53398053eaa63f87bbadd9&name_0=BackportPR
PR: #115535

Co-Authored-By: Claude Fable 5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Aug 24, 2026
Edited following .claude/skills/edit-changelog/SKILL.md, by hand on a
workstation: the editing step of the NightlyChangelog job has been failing
its own verification since 2026-08-12, so three raw blocks had accumulated
(47 + 84 + 628 entries).

Of the 759 raw entries, 482 are integrated into the in-progress 26.8 section
and 277 are dropped:

- Section 3: the 300 `NOT FOR CHANGELOG / INSIGNIFICANT` entries are dropped,
  except 41 that describe a user-visible change and are promoted into a real
  category, among them a server abort on a corrupt `ORC` stripe footer
  (#114924), `EXPLAIN ANALYZE` for streaming queries (#112445), `SELECT` from
  `TimeSeries` (#115622), streaming watermarks (#106169), and the
  `clickhouse-local` CORS overrides (#115129).
- Section 2: every revert in the range cancels out inside it, so neither side
  appears. Two are re-applications: #114912 re-applies the
  `accurateCastOrDefault` fix, so #109946 keeps its entry with both links and
  the intervening revert #114911 is gone; #114409 re-applies the PromQL
  streaming plan, recorded on the #113656 entry.
- Section 4: `Build/Testing/Packaging Improvement` keeps the seven entries a
  user, packager or from-source builder notices (musl `getaddrinfo` and
  `sched_getcpu`, signed macOS artifacts, Debian packages for release builds
  only, zstd-compressed Docker layers, `unit_tests_dbms` without the full
  library set, vendored Rust built with optimizations locally) and drops the
  CI plumbing.
- Sections 5 and 6: bare pull request URLs converted to links, settings put
  in backticks, four entries rewritten from developer notes into user-visible
  descriptions, and three moved into `Performance Improvement`.

No entry of a strict-retention category was deleted: the job's own
`verify_edit` passes on this edit.

Not done here, because the release manager does it at release time: the full
significance sort, the aggressive merging of sibling pull requests, and the
`FIXME` release date and presentation links.
alexey-milovidov added a commit that referenced this pull request Aug 26, 2026
Backport #114912 to 26.3: Revert "Revert "Fix propagation of settings in `accurateCastOrDefault`""
alexey-milovidov added a commit that referenced this pull request Aug 27, 2026
Address review: `resolve_reverted_originals` granted deletion credit to every
raw-block revert with a `Reverts owner/repo#N` marker, even when that revert
was itself reverted later in the same range — so an edit dropping `#109946`
(reverted by `#114911`, which `#114912` reverted in turn) still passed
verification while the fix ships in the release.

Now the resolved reverts are walked in descending PR-number order (a revert
always has a higher number than its target): an uncancelled revert cancels
the reverts it targets and only uncancelled reverts contribute deletion
credit. Because a revert of a revert made through the web UI can lack the
body marker (`#114912` has none), the target is also resolved from the
nested title — `Revert "Revert "X""` binds to the earlier range revert
titled `Revert "X"`.

PR: #116221

Co-Authored-By: Claude Fable 5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Aug 27, 2026
Backport #114912 to 25.8: Revert "Revert "Fix propagation of settings in `accurateCastOrDefault`""
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 28, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 28, 2026
alexey-milovidov added a commit that referenced this pull request Aug 28, 2026
`verify_edit` was only net-effect aware inside one raw block, while the job
edits a release cycle in ~30 nightly increments and a revert chain routinely
spans them:

1. run N integrates `#109946`;
2. run N+1 sees `#114911` and deletes `#109946`;
3. run N+2 sees only raw `#114912`.

On run N+2 nothing disappears in the edit — `#109946` went away the previous
day — so verification passed with a shipped fix missing from `CHANGELOG.md`,
and the editing agent had no way to know the entry ever existed: it is gone
from the file, and the intervening revert is gone from the raw blocks.

The branch now carries that memory itself, in trailers on its own edit
commits, the same way `Changelog-generated-up-to:` carries the generation
point:

    Changelog-revert: <revert> <reverted> <title of the revert>
    Changelog-deleted-entry: <pull request> <its bullet as it was deleted>

`analyze_reverts` resolves each run's reverts against that ledger and reduces
the *cumulative* graph, so a chain spread over several runs behaves exactly
like one arriving in a single raw block, at any depth:

- the reduction is what decides deletion credit, so a cancelled revert
  licenses nothing;
- an entry recorded as deleted whose revert is no longer uncancelled has to
  be back in `CHANGELOG.md` — `verify_edit` fails the run while it is not,
  and the prompt asks for it by name, quoting the bullet from the ledger;
- the recorded titles also let a web-UI `Revert "Revert "X""` (which carries
  no `Reverts owner/repo#N` marker) bind to an earlier revert the job saw
  days ago.

A branch whose edit commits predate the trailers has an empty ledger and
keeps the previous behaviour.

`ci/tests/test_changelog_nightly_revert_ledger.py` pins the timelines: the
whole chain in one block, the revert alone, the revert of the revert arriving
after the deletion, a revert of the re-apply, an empty ledger, and an
unresolvable revert.
alexey-milovidov added a commit that referenced this pull request Aug 28, 2026
**The retention path judged entries by any link, the restore path by
attribution.** The previous commit fixed the restore side only, so a strict raw
entry still counted as preserved when another bullet merely mentioned its pull
request in prose — and `revert_licensed_deletions` then had no attributed
bullet to snapshot, making the entry unrecoverable as well as gone. Both halves
of `disappeared_entries` now use the attribution, which also removes a
spurious failure in the other direction: rewording a bullet and dropping an
inline reference to another pull request is not the loss of that pull
request's entry.

**A restoration did not have to record the pull request that re-applied the
change.** Skill section 2.5 appends its link to the entry, and that link is
the only trace of the re-apply left in the release, since its own revert
bullet is deleted. Restoring a bare `#109946` without `#114912` passed.
`verify_edit` now requires it, on the bullet the entry landed on rather than
somewhere in the section, and only for this run's restorations — a later edit
may reword the entry.

**The duplicate guard compared sets of duplicated pull requests.** An entry
already written twice could gain a third copy without changing the set.
`duplicate_attributions` becomes `attribution_counts`, and the check is
`count > max(1, count before the edit)`: no increase is allowed, while the
count an edit inherits is left alone (removing an entry is what the retention
rule forbids).

Four tests added; each fails without its fix.
alexey-milovidov added a commit that referenced this pull request Aug 28, 2026
`reapplied_by` walked one level out from the direct remover, so it found the
revert that first put a change back and stopped there. With
`#109946` ← `#114911` ← `#114912` ← `#115500` ← `#116000` — out, back, out,
back, all inside one cycle — it reported only `#114912`, which the recorded
bullet already carried from the first restoration. The re-apply check was
therefore satisfied by the stale line and `#116000` was lost for good: a
revert of a revert has no bullet of its own, so the link on the entry is its
only trace in the release.

`revert_chain` now walks the whole chain above the entry, and the uncancelled
reverts of that chain are the ones that ship, so they are the ones that belong
on the bullet. `removed_by` is the complement — the cancelled ones — which also
makes the prompt name both removals of a repeated cycle instead of the first.
The three-pull-request case is unchanged: one remover, one re-applier.

The prompt asks for the links of every re-applier, noting that some may
already be on the recorded line from an earlier restoration.

`test_a_longer_chain_records_every_reapply` walks the five-pull-request
timeline and asserts `removed_by == ['114911', '115500']`,
`reapplied_by == ['114912', '116000']`, that replaying the recorded line is
rejected for missing `#116000`, and that appending it passes. It fails with
the one-level walk.
valerypetrov pushed a commit to valerypetrov/ClickHouse that referenced this pull request Aug 28, 2026
The editing step of the `NightlyChangelog` job has been failing its own
verification every night since 2026-08-12, always the same way:

    Entries disappeared in the edit without a matching revert (['103182', '109946'])

`verify_edit` requires that every raw entry of a strict-retention category
keeps its pull request link - an entry may be rewritten, merged or moved, but
not dropped, because the generation point has already moved past it and no
later run will offer it again. The prompt never said so, and the skill stated
the rule only implicitly, so the agent pruned entries it judged
insignificant: `ClickHouse#103182` (`Lightweight Updates v2`, a `Backward Incompatible
Change`) was deleted outright.

The second half of the same failure is the revert handling. `ClickHouse#109946` fixed
the propagation of settings in `accurateCastOrDefault`, `ClickHouse#114911` reverted
it, and `ClickHouse#114912` reverted that revert - all three in one range. The skill
covers this in section 2.5, but the agent reached the "landed and then
reverted, so delete both" rule first and lost a fix that ships.

So:

- The prompt now lists the strict-retention categories (from
  `STRICT_RETENTION_CATEGORIES`, so the two cannot drift apart), says which
  entries may be deleted and why deleting anything else is unrecoverable, and
  states the revert-of-revert rule.
- The skill gets a retention rule ahead of the individual edits, and the
  walk over `NO CL ENTRY` checks whether a revert is itself reverted before
  it concludes that a change was reverted. The `accurateCastOrDefault` chain
  is written out there as the worked example.
- A retry now tells the agent why the previous attempt was rejected. Without
  it, all three attempts of a run reproduced the same edit and the same
  rejection - visible in every run from 2026-08-12 on.

A hand edit that followed these rules passed `verify_edit` on the first try,
which is how the 26.8 backlog (759 raw entries) was cleared in
ClickHouse#111720.

Related: ClickHouse#111720
Related: ClickHouse#116138
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

6 participants