Repository navigation
Print quantile parameters with types so the state type name can be read back - #119810
Conversation
…ad back
A quantile level may be any numeric Field. DataTypeAggregateFunction::getNameImpl
prints parameters with FieldVisitorToString whenever shouldPrintParametersWithTypes()
is false, and that visitor deliberately quotes DecimalField, the wide integers, UUID,
IPv4 and IPv6 ("there are no Decimal and big integer literals in SQL"). So the state
type name for such a level came out as AggregateFunction(quantile('0.5'), Float64).
That name is what lands in the table metadata. On re-parse the parameter is a String,
which quantile's level check rejects with CANNOT_CONVERT_TYPE, so the metadata load
job fails and the server does not start at all - not just the one table. Recovery
needs hand-editing the metadata .sql. The same visitor accepts a DecimalField, which
is why the CREATE succeeds and only the reload fails: ClickHouse accepted a CREATE
whose own persisted form it would later refuse. On a Replicated database the CREATE
is re-parsed from its serialized form, so it failed there immediately instead.
Both reachability paths are ordinary SQL. The type spec 0.5::Decimal32(1) goes
through parseFieldFromCastedLiteral, and constant folding stores the folded Field
verbatim, so quantileState(toDecimal32(0.5, 1))(x) produces the same unreadable name
with no special syntax, and CREATE TABLE ... AS SELECT of it persists one.
Turn on the per-function hook the subsystem provides for exactly this, so the name
carries ::Type suffixes that parseFieldFromCastedLiteral reads back. This is the third
family to need it, after timeSeries* (6e4db42) and groupArrayMoving*
(2916916). AggregateFunctionQuantile.h is the template behind 18 registration
units, so one override covers every quantile*/quantiles*/median* name - which is
exactly the set whose level check rejects a String.
Two supporting changes. AggregateFunctionTuple needs its own override: it holds a
vector of nested functions, while IAggregateFunction delegates the hook through the
singular getNestedFunction(), so -Tuple would otherwise keep the unreadable spelling.
And ColumnAggregateFunction::getTypeString now shares the state type's parameter
printer instead of hardcoding FieldVisitorToString - that string is the name carried
inside a serialized state Field and is compared against the state type's name, so the
two have to agree.
The common spellings do not move: quantile(0.5) (Float64), quantile(1) (UInt64) and
quantile(false) print as before, because FieldVisitorToCastedLiteral omits the suffix
where the plain form re-parses to the same Field type. 1::Int64 becomes
quantile(1::Int64), for the same round-trip fidelity 2916916 argued for.
No setting is added or changed, so there is no SettingsChangesHistory.cpp entry.
Metadata already carrying the broken spelling is not repaired - the stored text is
unchanged, so it does not load before or after; this stops new occurrences.
Alternatives rejected: accepting the quoted form on read would legalise a spelling
the parameter type itself rejects, and 05079 pins that rejection; printing a Decimal
or wide integer unquoted would trade a hard error for silently wrong values, since an
unquoted Decimal256 re-parses through ParserNumber as Float64, and it cannot spell
UUID/IPv4/IPv6 at all; a global Field-type rule in the printer would bypass the hook
and respell type names for argMin/argMax/intervalLengthSum/groupArrayInsertAt, which
read back fine today and whose names NativeWriter puts on the wire as text.
An audit of all 259 aggregate functions found six further families with this defect
(topK, approx_top_k, exponentialMovingAverage, stochastic*Regression, uniqUpTo). They
are tracked separately: the hook is per-family and propagates through combinators, so
each needs its own parameter-contract and caller analysis.
Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: 1 gate finding, 4 of my own, 0 blockingAn independent model reviewed this diff cold; I adjudicated its finding against the code. 💡 From my own pass, fixed before publishing: the description said the override covers 46 family names, but
Session id: cron:clickhouse-review-slot-10:20260913-161300 |
|
Workflow [PR], commit [d9c814e] Summary: ✅
AI ReviewSummaryThis PR fixes the Final Verdict✅ No actionable findings. LLVM Coverage ReportMeasured on commit d9c814e.
Changed lines: Changed C/C++ lines covered: 47/47 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes26 object files changed (+323.54 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units110 translation units recompiled, 894 s compile time in total, 110 of them have a recent master baseline. |
fcbf73e
Two conflicts, both in the state-name printer this branch shares with ClickHouse#119810 (merged as d9c814e), which took the DataTypeAggregateFunction::formatParameters helper out of this branch: - src/Columns/ColumnAggregateFunction.cpp: master now calls the shared helper with getParameters(). This branch exists to print getStateParameters() there instead, so the argument is kept and the rest of master's hunk (the SipHashingWriteBuffer change to updateHashWithValue) is taken as is. - src/Columns/tests/gtest_column_aggregate_function.cpp: both sides appended a test at the end of the file. Both are kept; they cover different printers, quantile with a Decimal level from master and an argMin state name carrying a Map parameter here. Nothing else conflicted: the formatParameters consolidation and its comments are already on master in identical form, so the merge drops this branch's copy of them and keeps only the getStateParameters mechanism plus the parameter-tolerant nameMatchesState. Co-Authored-By: Claude Opus 5 <[email protected]>
|
@pufit could you add 26.9 has the bug. The 26.9 branch is red on it,
26.9 is the only branch that needs it. It also reds other people's pull requests now. Since Nothing does it automatically: For context, @ PedroTadim named this PR as the fix for the same signature in #120550. |
|
Hi @pufit, gentle ping: any update on adding |
Closes #120550
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a server startup failure after creating a table with a
quantile*state column whose level is aDecimal, a wide integer, aUUID, anIPv4or anIPv6. Such a level was persisted into the metadata as a quoted string, which reparsed as aStringand was rejected, so metadata loading failed withCANNOT_CONVERT_TYPEand the server did not start. The sameCREATEalso failed outright on aReplicateddatabase.Description
AggregateFunction(quantile(0.5::Decimal32(1)), Float64)is accepted, but persists asAggregateFunction(quantile('0.5'), Float64). On the next start it reparses as aString,quantile'slevel check rejects it with
Code: 70 CANNOT_CONVERT_TYPE, and the metadata load job fails, so thewhole server does not start (recovery needs editing the metadata
.sql).Root cause:
DataTypeAggregateFunction::getNameImplprints parameters withFieldVisitorToStringwhenshouldPrintParametersWithTypes()is false, and that visitor quotes exactlyDecimalField, the wideintegers,
UUID,IPv4andIPv6. No special syntax needed:quantileState(toDecimal32(0.5, 1))(x)folds to the sameField.Fix: turn that per-function hook on in
AggregateFunctionQuantile, so the name carries the::Typesuffixes
parseFieldFromCastedLiteralreads back. Third family to need it, aftertimeSeries*(
6e4db42cb76bf) andgroupArrayMoving*(2916916ce5d3e); it covers all 54quantile*/quantiles*/median*names.AggregateFunctionTupleneeds its own, since the base classdelegates through the singular
getNestedFunction()and it holds a vector;ColumnAggregateFunction::getTypeStringnow shares the state type's printer, so a serialized stateFieldcarries the same spelling.quantile(0.5),quantile(1)andquantile(false)are unchanged;1::Int64becomesquantile(1::Int64). Metadata already carrying the broken spelling is not repaired: the stored textdoes not change, so it does not load before or after.
Found in CI: 8
Stress testruns on unrelated PRs never got the server back, losing the whole job,and the
DBReplicatedcheck has 9 master hits (query and counts below). Validated with a new test05210, an updated05079reference, 100/100 randomized runs, and a gtest pinning the two printerstogether.
Overlaps my open #118156 in three files and repeats its
formatParametersextraction, so whichevermerges second keeps one copy. Auditing all 259 aggregate functions found 6 more families with the same
defect (
topK,approx_top_k,exponentialMovingAverage,stochastic*Regression,uniqUpTo), handledseparately.
CI footprint and the observed startup failure, before the fix
6
Stress testflavours: 8 rows / 8 distinct PRs / 0 master (it needs a restart, which only Stressdoes), 2026-09-08 to 2026-09-13.
Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DBReplicated, parallel, 2/3): 71 rows / 58 distinct PRs / 9 master rows, 2026-09-06 to 2026-09-13.In CI that surfaces as
Cannot start clickhouse-server: server process is not running after 11 start attempts, with the same722 -> 695 -> 70chain once per start attempt.Workflow [PR]
Sync PR [sync-upstream/pr/119810]
Version info
26.10.1.136(included in26.10and later)