Repository navigation
Print the parameters of eight more aggregate function families with types so the state type name can be read back - #121491
Conversation
…ypes
AggregateFunction(topK(3::Decimal32(0)), UInt64) is accepted, but the state
type name is printed as AggregateFunction(topK('3'), UInt64) and that is what
dataTypeToAST writes into the table metadata. On reload the parameter reparses
as a String, topK reads it through FieldVisitorConvertToNumber, whose String
overload throws CANNOT_CONVERT_TYPE, and the load job fails: ClickHouse refuses
a CREATE in the exact form it persisted. With the default async_load_databases
the server starts and the table is permanently unreadable, un-insertable and
un-droppable; with async_load_databases = 0 it does not start at all.
DataTypeAggregateFunction::getNameImpl renders parameters with
FieldVisitorToString unless the function's shouldPrintParametersWithTypes() is
true, and that visitor deliberately quotes Decimal* and the four wide integers
because SQL has no literal form for them. The CREATE succeeds because the same
visitor accepts those Field types on the way in, so only the reload fails. No
cast syntax is needed to get there: a folded toDecimal32 argument stores the
same Field, e.g.
CREATE TABLE t ENGINE = MergeTree ORDER BY tuple() AS
SELECT exponentialMovingAverageState(toDecimal32(0.5, 1))(x, t) AS s FROM ...
Turn the per-family hook on in the nine classes that back these twelve
registered names, so the printer uses FieldVisitorToCastedLiteral and emits the
::Type suffix parseFieldFromCastedLiteral reads back. Nine sites rather than
eight families because the Generic and Variadic argument shapes are separate
classes; each site was confirmed load-bearing by deleting it and observing the
matching test column redden. The fourth family group to need this, after
timeSeries* (6e4db42) and groupArrayMoving* (2916916).
Scope came from a source-level predicate, reads a parameter numerically and
lacks the hook, rather than from probing one guessed parameter value: of 23
candidate classes, nine are exposed and 15 already reject such a Field at
CREATE, so they cannot persist an unreadable name and must not get the hook.
groupArrayInsertAt is exposed but deliberately excluded: its first parameter is
a default value stored verbatim, so it can be composite, and
FieldVisitorToCastedLiteral recurses into an Array while
parseFieldFromCastedLiteral accepts only a top-level cast. Turning the hook on
there would convert a case that reloads today into BAD_ARGUMENTS. Typing one
parameter position without the other needs per-parameter formatting or a
recursive parser inverse, which is a subsystem design choice rather than part
of this fix.
FieldVisitorToCastedLiteral defaults to skip_unambiguous_cast, so UInt64,
Float64, String, Bool, Null and negative Int64 parameters print byte-identically
and no existing reference file moves. A positive Int64 does gain a suffix,
because a bare positive integer reparses as UInt64; both spellings round-trip,
and 2916916 shipped and pinned the same trade. An already-persisted name
is untouched, so nothing needs migrating.
NativeWriter puts type->getName() into the column header as text, so the Native
format specification is updated in the same change, as the repository's agent
rulebook requires for changes that alter which type strings appear on the wire.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings; bounded: 1 full pass +
Severity: ❌ blocker / Also re-measured on current Session id: cron:clickhouse-review-self-slot-58:20260922-041700 |
|
Workflow [PR], commit [8f0b6b2] Summary: ✅
AI ReviewSummaryThis PR fixes the aggregate-state type-name round-trip bug by enabling typed parameter printing on the exposed aggregate-function families that accept numeric Final Verdict✅ Approve. No inline findings to post. LLVM Coverage ReportMeasured on commit 8f0b6b2.
Changed lines: Changed C/C++ lines covered: 25/26 (96.15%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes16 object files changed (+158.83 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 units21 translation units recompiled, 103 s compile time in total, 21 of them have a recent master baseline. |
|
@groeneai, I'll merge this. But what do you think about removing |
|
Acknowledged. Always printing with types is the simpler contract, so I will go that way and measure the consequences before sending the PR: which state type names change for the families that currently opt out, whether any metadata or reference output depends on the untyped spelling, and whether a name printed with types still parses on a server older than |
95154db
|
The follow-up PR is up: #121725. The hook is gone and every parameter now prints through Measured consequences, all in that PR's description: only a parameter with no unambiguous bare literal form moves, and the two families the audit had missed, |
Related: #120994
Related: #119810
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
topK,topKWeighted,approx_top_k,approx_top_count,approx_top_sum,uniqUpTo,uniqCombined,uniqCombined64,exponentialMovingAverage,stochasticLinearRegression,stochasticLogisticRegressionandgroupNumericIndexedVectorstate columns with aDecimalor wide-integer parameter. The parameter was persisted as a quoted string that reparsed as aStringand was rejected, so after a restart the table was unreadable, un-insertable and un-droppable; withasync_load_databases = 0the server did not start.Description
On 26.8 and 26.9, a
CREATE TABLEwith the column typeAggregateFunction(topK(3::Decimal32(0)), UInt64)is accepted but persists as
AggregateFunction(topK('3'), UInt64), a name the server cannot parse back, sothat table is permanently unreadable and un-droppable (recovery needs deleting the metadata
.sql); withasync_load_databases = 0the server does not start.DataTypeAggregateFunction::getNameImplprints parameters withFieldVisitorToString, which quotesDecimal*and the four wide integers, unlessshouldPrintParametersWithTypes()is true. On reload theparameter reparses as a
String, whichFieldVisitorConvertToNumberrejects (Code: 70). No cast syntaxis needed:
... AS SELECT exponentialMovingAverageState(toDecimal32(0.5, 1))(x, t)folds to the sameField.This turns that per-family hook on in the nine classes backing these 12 names, so the name carries
the
::TypesuffixesparseFieldFromCastedLiteralreads back. Fourth family group to need it,after
timeSeries*,groupArrayMoving*andquantile*(#119810, whose generic carriers it uses).Scope is source-derived (reads a parameter numerically, lacks the hook): 23 candidate files,
nine exposed families, 15 already rejecting such a
Field.Notes:
.referencechanges: every spelling in the tree today prints byte-identically.A positive
Int64is the one working case respelled (topK(3::Int64)); both round-trip, as in2916916ce5d3e.groupArrayInsertAtis the one family intopK+ 9 more: Decimal parameter makes the persisted column type unloadable #120994 left unfixed: its second parameter has the defect,but its first is a default value that can be composite, and a cast inside a composite does not
reparse, so this per-function hook would break a case that works today; 05211 pins that.
NativeFormat.mdx:NativeWriterputs the type name on the wire, per the in-tree spec-sync rule.Workflow [PR]
Sync PR [sync-upstream/pr/121491]
Version info
26.10.1.478-master(included in26.10and later)