Repository navigation
Always print aggregate function parameters with types - #121725
alexey-milovidov merged 10 commits into
Conversation
DataTypeAggregateFunction::formatParameters chose between two Field printers per aggregate function, through the virtual IAggregateFunction::shouldPrintParametersWithTypes(). A function had to opt in to having its parameters printed in a form that reads back as the same Field, so the opt-in list was an unfinished audit rather than a behaviour toggle: it was extended for quantile in ClickHouse#119810 and for eight more families in ClickHouse#121491, and it still missed exponentialTimeDecayed{Sum,Max,Count,Avg}. FieldVisitorToCastedLiteral is constructed with its default skip_unambiguous_cast = true, so it already suppresses the ::Type suffix wherever the bare literal reparses to the same Field. Comparing it with FieldVisitorToString, the printed text differs only for a non-negative Int64, a wide integer, a UUID, an IPv4/IPv6 and a DecimalField, plus an Array, Tuple or Map holding one of those. The hook therefore only ever chose between "always correct" and "correct unless a parameter happens to carry one of those types", which is what makes it removable rather than a user-facing option. Because the only use of the IAggregateFunction argument was the hook call, the argument is dropped and the signature reduces to formatParameters(parameters). The visitor suffixes the ELEMENTS of a composite value, so a composite parameter now prints as a call over literals, for example sumMapFiltered(['1'::Decimal32(1)]). parseFieldFromCastedLiteral accepted only an ASTLiteral or a top-level CAST, so that name throws BAD_ARGUMENTS while the untyped spelling parses. Printing typed without extending the reader would convert a working DETACH/ATTACH of sumMapFiltered([toDecimal32(1, 1)]) into a hard failure, so the parser gains a recursive branch for the two composite shapes the visitor emits. A Map parameter still reads back as an Array, which it already does today in both visitors. The <algorithm> include in AggregateFunctionTuple.cpp was added by d9c814e for the std::ranges::any_of of the deleted override and has no other user in that translation unit; the FieldVisitorToString.h include in DataTypeAggregateFunction.cpp likewise loses its only user. Requested in ClickHouse#121491 (comment)
…-parameters-with-types
…entence and test ClickHouse#121491 landed while this branch was in progress. It added nine more shouldPrintParametersWithTypes overrides, a NativeFormat sentence describing the ::Type suffix as a property of the aggregate function, and a test arm asserting that a composite parameter keeps an untyped spelling because a suffix inside a composite does not parse back. With the hook gone the overrides have nothing to override, so they are deleted along with their comments; the docs sentence now states the rule the code actually follows, which is that the suffix depends on the parameter's value and lands on the elements of a composite; and the composite arm of 05211_aggregate_parameter_type_name_round_trip expects the typed spelling, its DETACH/ATTACH assertion unchanged, because the recursive array/tuple branch in parseFieldFromCastedLiteral is what makes that name readable.
The reader this branch adds has two result paths, array and tuple, and every
composite fixture in 05238 and in 05211 was an array, so the tuple path in
parseFieldFromCastedLiteral had no test. The validation notes asserted that
both printed tuple spellings work; nothing stood behind that assertion.
Both new arms use groupArrayInsertAt, whose first parameter is a default value
of the argument type, so a Tuple default is reachable from ordinary SQL: a
Tuple(Decimal32(1), UInt64) default prints as ('1.5'::Decimal32(1), 7), which
parses as a call of tuple, and a Tuple(Decimal32(1)) default prints as
tuple('1.5'::Decimal32(1)), which is a different printed shape. Both run
through the oracles the file already had, so no oracle line was added. The
empty-tuple spelling is deliberately left out: it works, but it is a third
spelling for a degenerate type.
Proven live rather than assumed. With only the tuple result path replaced by a
throw, 05238 fails at that throw while parsing groupArrayInsertAt, and the
typed_array column that sits before the tuple columns still parses, so the
array path is untouched and the rejection belongs to the new arms.
This also corrects the cross-version answer in the pre-PR validation notes,
which claimed the exposure was wholly pre-existing. Measured per release
branch, it has two halves: the scalar ::Type suffix has been readable since
26.6, but the composite array/tuple spelling is new in this commit and no
released version parses it, so a mixed-version distributed query over such a
state, or a downgrade, gets BAD_ARGUMENTS. The description already said this;
the notes did not.
Co-Authored-By: Claude Opus 5 <[email protected]>
The name of an aggregate function state is what crosses the Native protocol: NativeWriter sends type->getName() and NativeReader rebuilds the type from that name through the data type factory, so this branch's printer change decides whether a state sent between two servers still compares equal to the destination column. Nothing in the suite exercised that path. 05238 covers the metadata carrier only: a declared column, a query-built state, initializeAggregation, DETACH and ATTACH, all inside one server. The new test inserts a state with a Decimal parameter through remote() into a column declared from the same expression. prefer_localhost_replica = 0 is what makes that a real connection rather than a local plan: SelectStreamFactory takes the local shortcut only when the setting is on and the shard is local, and isLocalAddress requires the port to match, so a self-addressed remote() with the setting off still goes over the wire. One server is therefore enough. It covers the direction this branch starts accepting. Before, the untyped name degraded a Decimal parameter to a String on the receiving side, so the insert was rejected with CANNOT_CONVERT_TYPE naming the same type twice; the previous binary fails the new test at exactly that point, inside RemoteQueryExecutor::processPacket, which is also what proves the hop is real. The opposite direction, a typed state into a column whose parameter genuinely is a String, stops being accepted. That one is deliberately not pinned: whether the new acceptance set is the intended contract is not mine to assert. Also makes the formatParameters comment say where the suffix lands. A composite value carries no suffix itself, its elements do, which is the property the recursive reader branch exists for.
05239 asserted the destination's typed state name and finalizeAggregation, and neither depends on how the state arrived: running the test with prefer_localhost_replica = 1 produced the reference byte for byte. The carrier the test exists for was pinned only by a SETTINGS clause whose effect nothing checked, so if that clause were ever dropped or made a no-op the test would keep passing as a weaker duplicate of 05238. prefer_localhost_replica is also randomized by the runner, which is what makes the query-level clause load-bearing. Key the INSERT with log_comment and assert that a secondary query was logged, the idiom 04366_secondary_query_internal_flag_propagation.sh already uses for the same reason. A local shortcut dispatches none, so flipping prefer_localhost_replica to 1 now flips the new line from 1 to 0 while the other two lines stay identical. parseFieldFromCastedLiteral accepts array(...) and tuple(...) since this branch, but its BAD_ARGUMENTS message still enumerated only a literal and a CAST of a literal, so a user hitting it on a composite read an incomplete list. No test or reference asserts that text; the one other mention is a prose comment in 05079, whose assertion matches the error code.
Review round 5. Comment accuracy only: no behaviour change, no added lines, no new test. The rebuilt binary has the same Build ID as before the round, which is the mechanical proof of that; comments do not survive the preprocessor, so every dependent translation unit recompiled to a byte-identical object and the linked image is identical. DataTypeAggregateFunction.h: the doc comment on formatParameters stated a universal rule that the code does not keep. Three Field types print through FieldVisitorToString with no ::Type suffix (Object, AggregateFunctionStateData, CustomType), and parseFieldFromCastedLiteral has no target for any of them, so none round-trips. Behaviour there is byte-identical to master, because the non-opted-in functions already used FieldVisitorToString: only the sentence was wrong. It now attributes the suffix to FieldVisitorToCastedLiteral and says "where the type has one", which is what excludes those three, rather than promising it for every value. The composite clause is kept deliberately: it is the reason the coupled reader change exists and is not derivable from the declaration below it. 05239_aggregate_parameter_types_native_hop.sh: the comment explaining prefer_localhost_replica = 0 named isLocalAddress, an internal C++ symbol. A test should not reach into the implementation, since that couples it to code it cannot see and goes stale silently. Reworded to state the observable behaviour instead: a same-host, same-port shard is otherwise served locally, so there is no Native hop to cross. The script body, its settings, its log_comment and its reference file are unchanged, and the file is still 39 lines. The one remaining isLocalAddress reference under tests/ is in 04050_skip_unavailable_shards_local_missing_table.sql, which this PR does not touch, so it is left alone. Validation: warm incremental build RC=0 (14574 targets, relink); 05239 [ OK ] 1.33 sec on the rebuilt binary, with the server's buildId() asserted equal to readelf's; ci/jobs/check_style.py output byte-identical to the previous round (its one failing leg needs CI's changed-files hook).
Drop the array/tuple branch's design narration, cut the header bullet to the grammar and the Map-reads-back-as-Array property, and state formatParameters' spelling as an invariant.
Internal second-model reviewAn independent model reviewed this diff cold and a separate pass adjudicated its findings against the Declined, each on a measurement rather than on scope:
Agreed and fixed across the six rounds: a missing typed-tuple arm in 05238, with a negative control that |
Pre-PR validation gate (a-i)
Verification: 50/50 randomized runs of each new test green; the 58 existing test files that mention a |
|
Workflow [PR], commit [c02ff20] Summary: ✅
AI ReviewSummaryThis PR replaces the per-family aggregate-parameter audit with value-driven printing and teaches the parser to read typed elements inside array and tuple parameters, which fixes several real round-trip failures. I would still block it as written, because it also changes the PR Metadata
Findings
Final Verdict
LLVM Coverage ReportMeasured on commit c02ff20.
Changed lines: Changed C/C++ lines covered: 65/66 (98.48%) · Uncovered code |
|
On the Gate the spelling behind a revision or a compatibility setting and there is no break to declare, so Keep the break intentionally and Three measured bounds, so the call rests on numbers rather than on my summary. The scalar |
CI finish ledger - e9418b6Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Measured at this head, not inherited: across the whole commit there is exactly one Neither row can come from this diff. Row 1 aborts inside the planner while building actions for On row 1's owner: my own earlier fix for this signature, #115005, was closed on 2026-09-21 as Session id: cron:our-pr-ci-monitor:20260923-203258 |
…-parameters-with-types
Conflicts:
- AggregateFunctionTuple.{h,cpp}: keep master's new isOnlyWindowFunction override and drop the
shouldPrintParametersWithTypes one. Keep #include <algorithm>, which isOnlyWindowFunction now uses.
- NativeFormat.mdx moved to docs/resources/develop-contribute/native-protocol/format.mdx; the
parameter-spelling sentence is re-applied on master's text there.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The comment trim dropped "where its type has one", which made the rule universal. Object, AggregateFunctionStateData and CustomType parameters are printed through FieldVisitorToString with no suffix, so the unqualified sentence was false for them. Comment only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| stream << applyVisitor(FieldVisitorToCastedLiteral(), parameters[i]); | ||
| else | ||
| stream << applyVisitor(FieldVisitorToString(), parameters[i]); | ||
| stream << applyVisitor(FieldVisitorToCastedLiteral(), parameters[i]); |
There was a problem hiding this comment.
❌ This makes the new composite ::Type spelling unconditional for every AggregateFunction(...) state name, but there is still no protocol-revision or compatibility gate around it. Older servers do not parse typed elements inside array/tuple parameters, so a mixed-version remote()/distributed hop or a downgrade starts failing with BAD_ARGUMENTS as soon as a state name like groupArrayInsertAt(['1'::Decimal32(0)], 3) crosses the boundary.
Please negotiate the new spelling behind a revision / compatibility setting and keep emitting the legacy header to older readers, or treat this as an explicit backward-incompatible format change with a migration path.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes152 object files changed (-825.26 KiB total), 0 added.
719 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 units352 translation units recompiled, 2620 s compile time in total, 352 of them have a recent master baseline. |
Master removed IAggregateFunction::shouldPrintParametersWithTypes in ClickHouse#121725 and now always prints aggregate function parameters with types, so the override no longer compiles after the master merge. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`AcceptsStateNameSpellingUnreadParameters` asserted that `DataTypeFactory` cannot parse the decoded type's name, `AggregateFunction(argMin([(1, 2)]), UInt8, UInt8)`. Since ClickHouse#121725 taught `parseFieldFromCastedLiteral` to read `array`/`tuple` parameters, that name parses, so the precondition fails in all unit test jobs once master is merged. The precondition only documented which branch of `nameMatchesState` accepts the Field. The behaviour the test pins does not depend on it: the state type still drops the unread parameter, both carriers still accept the decoded Field, and the `argMax` name is still rejected. On master the acceptance now goes through the parse branch; on a branch without ClickHouse#121725 it goes through the verbatim comparison. The headers of 05076 and 05180 no longer claim the parser rejects the name. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…state-constant-identity Resolve the conflict with ClickHouse#121725, which removed the `function` argument of `DataTypeAggregateFunction::formatParameters`: `getAggregateFunctionNames` now spells the parameters with the one-argument form, as `getNameImpl` does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Parameters of `AggregateFunction` are printed with their types only since #121725, which is not in 26.8. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Parameters of `AggregateFunction` are printed with their types only since #121725, which is not in 26.9. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #121491
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
An aggregate function parameter whose value has no unambiguous bare literal form, such as a
Decimal, a wide integer, aUUID, anIPv4/IPv6or a non-negativeInt64, is now always printed with an explicit::Typesuffix, and inside an array or tuple parameter the suffix goes on the elements. Such a parameter therefore reads back as the sameFieldfor every family, instead of only for the ones that had opted in. The name also travels over the Native protocol, so an insert into a column whose parameter was spelled without the type is now rejected there too, as it already was locally.Description
DataTypeAggregateFunction::formatParameterspicked one of twoFieldprinters per function, through the virtualshouldPrintParametersWithTypes(). Opting in kept the name reading back as the same parameters, so the list was an unfinished audit: it grew twice (#119810, #121491) and still missedgroupArrayInsertAtandsumMapFiltered, both covered below. This deletes the hook and always usesFieldVisitorToCastedLiteral.Which names change: only a parameter with no unambiguous bare literal form, or a composite holding one. Everything else is byte-identical: the visitor runs with
skip_unambiguous_cast = true. Measured:sumMapFiltered(['1'])becomessumMapFiltered(['1'::Decimal32(1)]),topK(10)does not move, and only #121491's.referencemoves.The suffix lands on the ELEMENTS of a composite, which
parseFieldFromCastedLiteraldid not accept, so printing typed alone would have broken a workingDETACH/ATTACHofsumMapFiltered([toDecimal32(1, 1)]); the reader therefore gains a recursivearray/tuplebranch.In a
Replicateddatabase,CREATE TABLE ... AS SELECTof such a state re-created the column from the untyped name and failed withCANNOT_CONVERT_TYPE; it now succeeds, as does test 05211 onDBReplicatedruns.Compatibility, measured. A scalar suffix reads back on 26.6+, so only 26.5 and older reject one, pre-existing (
quantile#119810,timeSeries*). The composite spelling is new, so no released version reads it: a mixed-version distributed query over such a state, or a downgrade, getsBAD_ARGUMENTS. Between two current servers the name also decides which inserts are accepted: an insert into aDecimal-parameter column starts working, one into aString-parameter column stops, as it already did locally and under binary type encoding.Out of scope:
DataTypeCustomSimpleAggregateFunction; theEXPLAINandsystem.query_logprinters, never reparsed; anObjectparameter, still untyped; aMap, printed as an array, so its entries take suffixes and read back as anArray.The insert matrix, measured on two servers, one binary per arm
The source is
CREATE TABLE ... ENGINE = Memory AS SELECT groupArrayInsertAtState(toDecimal32(1.5, 1), 3)(x, i), so its parameter is aDecimalField. TheStringdestination declares the same column with'1.5', which is how a server without this change persists that type. Each accepted cell is confirmed by reading the state back withfinalizeAggregation.DecimalStringremote()CANNOT_CONVERT_TYPEDecimalStringCANNOT_CONVERT_TYPECANNOT_CONVERT_TYPEStringStringremote()DecimalDecimalremote()CANNOT_CONVERT_TYPEBefore the change all four columns print the same name, so the rejection in the last row names one type twice.
NativeWritersendstype->getName()andNativeReaderrebuilds the type from it, so the lossy name degraded aDecimalparameter to aStringon the receiving side andstrictEqualscompared that degraded value.native.encode_types_in_binary_formatencodes each parameter as a typedField, so it already behaved as the last two rows do now.Workflow [PR]
Sync PR [sync-upstream/pr/121725]
Version info
26.10.1.2115-master(included in26.10and later)