Skip to content

Support binary for aggregate_function_input_format, unify implementation - #91358

Closed
GrigoryPervakov wants to merge 87 commits into
masterfrom
pervakovg/aggregate-insert-format
Closed

GrigoryPervakov wants to merge 87 commits into
masterfrom
pervakovg/aggregate-insert-format

Conversation

@GrigoryPervakov

@GrigoryPervakov GrigoryPervakov commented Dec 2, 2025 •

Copy link
Copy Markdown
Member

Addresses issues in #88088

Support the RowBinary family of input formats for aggregate_function_input_format = 'value' and aggregate_function_input_format = 'array', and unify the value/array deserialization across all input formats (text and binary) behind a single implementation that deserializes into a temporary column of the argument type (or Array of it) and builds the AggregateFunction state via addBatchSinglePlace.

The setting aggregate_function_input_format remains production-tier: it was already released as such in v25.12 and v26.1, so this PR does not change its feature tier and is not a backward-incompatible change.

Related: #88088

Changelog category (leave one):

  • Improvement

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

Support aggregate_function_input_format = 'value' and aggregate_function_input_format = 'array' for binary input formats such as RowBinary when inserting into AggregateFunction columns, and unify the deserialization implementation across input formats.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

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

@clickhouse-gh

clickhouse-gh Bot commented Dec 2, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [15a9bb7]

Summary: ✅


AI Review

Summary

This PR extends aggregate_function_input_format so value and array also work for the RowBinary family, and it consolidates the text and binary deserialization paths around temporary argument columns while restoring the previously released compatibility forms through focused regression tests. I re-checked the resolved review threads against the current code and did not find a remaining correctness, compatibility, or documentation defect in the diff.

Missing context / blind spots
  • ⚠️ I could not execute the new tests locally because this checkout does not contain a built clickhouse or clickhouse-local binary, and the fresh full CI matrix for head 15a9bb793012 is still running. This pass therefore relies on code inspection plus the committed regression tests rather than completed runtime verification on the current head.
Final Verdict

✅ Approve from code review perspective; no new inline findings.

LLVM Coverage Report

Measured on commit 15a9bb7.

Metric Baseline Current Δ
Lines 89.00% 88.90% -0.10%
Functions 91.80% 91.80% +0.00%
Branches 81.30% 81.30% +0.00%

Changed lines: Changed C/C++ lines covered: 345/365 (94.52%) · 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 Dec 2, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the implementation of aggregate_function_input_format to support binary formats (e.g., RowBinary) and unifies the deserialization logic across different input formats.

Key Changes:

  • Added support for binary format deserialization in addition to text-based formats
  • Unified the deserialization implementation using a template-based approach (deserializeFromValues)
  • Converted the bash-based test (.sh) to a SQL-based test (.sql) for better maintainability

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tests/queries/0_stateless/03645_aggregate_function_input_format.sql New SQL test file with comprehensive test cases for aggregate function input formats including binary formats
tests/queries/0_stateless/03645_aggregate_function_input_format.sh Removed bash test script (replaced by .sql file)
tests/queries/0_stateless/03645_aggregate_function_input_format.reference Updated reference output to include new binary format test results
src/DataTypes/Serializations/SerializationAggregateFunction.h Removed obsolete deserializeBasedOnInput method declaration
src/DataTypes/Serializations/SerializationAggregateFunction.cpp Major refactoring: unified deserialization logic, added binary format support, introduced template-based approach

@GrigoryPervakov
GrigoryPervakov force-pushed the pervakovg/aggregate-insert-format branch from 51eca8b to cf9882d Compare December 3, 2025 12:04
@ClickHouse ClickHouse deleted a comment from Copilot AI Dec 3, 2025
@GrigoryPervakov
GrigoryPervakov force-pushed the pervakovg/aggregate-insert-format branch from cf9882d to 4632266 Compare December 3, 2025 14:29
@GrigoryPervakov
GrigoryPervakov marked this pull request as ready for review December 3, 2025 18:26
@alexey-milovidov alexey-milovidov self-assigned this Dec 5, 2025
@GrigoryPervakov
GrigoryPervakov force-pushed the pervakovg/aggregate-insert-format branch from 4632266 to 396ee5c Compare December 10, 2025 19:04
@GrigoryPervakov
GrigoryPervakov force-pushed the pervakovg/aggregate-insert-format branch from 396ee5c to 0d6411e Compare December 18, 2025 12:10
@azat azat changed the title Support binary for aggregate_function_input_format, unify inplementation Support binary for aggregate_function_input_format, unify implementation Dec 18, 2025
GrigoryPervakov and others added 2 commits December 18, 2025 16:49
…-insert-format

# Conflicts:
#	src/Core/Settings.cpp
#	src/DataTypes/Serializations/SerializationAggregateFunction.cpp
alexey-milovidov and others added 3 commits May 10, 2026 10:38
…inputs

The refactor in 0d6411e dropped the check that
`function->deserialize` consumed the entire bounded buffer when reading
a state from a string-based path. As a result, garbage suffixes were
silently accepted for `Escaped`/`Quoted`/`WholeText`/`JSON`/`CSV` state
inputs, regressing tests that expect `BAD_ARGUMENTS` for malformed
states (`02477_single_value_data_string_regression`,
`03716_topk_bad_data`, `04027_redundant_trailing_bytes_aggregate_function_deserialization`,
`04027_reverseUTF8_invalid_utf8`,
`04048_sumcountif_nullable_backward_compat`).

Add an opt-in `check_buffer_consumed` parameter to the shared
`deserializeFromString` helper. The text-format callers — which read a
single value into a `ReadBufferFromString` — pass `true`, restoring the
master-branch behavior of throwing `BAD_ARGUMENTS` on trailing bytes.
The binary per-row path keeps the default (`false`) so streaming
deserialization of subsequent rows is preserved.

CI failures: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=91358&sha=a7a14a69d127be5290c774b24618c22e45097fca&name_0=PR&name_1=Fast%20test
PR: #91358

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
In `SerializationAggregateFunction::deserializeBinary(Field &, ...)` for
`value`/`array` modes, the temporary `place` is created via
`function->create(place)` and used only to build `s.data` via
`function->serialize`. On the success path the matching
`function->destroy(place)` was missing, so aggregate functions whose
state holds non-trivial resources (e.g. containers, external
allocations) leaked those resources for every row parsed in
`value`/`array` modes.

PR: #91358

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
alexey-milovidov and others added 2 commits May 17, 2026 11:28
`createStateFromValues` previously derived the row count from
`arg_columns[0]->size()`. For zero-argument aggregate functions like
`AggregateFunction(count)`, `columns_ptrs` is empty in `value`/`array`
modes, so `arg_columns[0]` is invalid and the server segfaulted.

Pass the row count explicitly: `1` for value mode, the parsed array
length for array mode. Also skip building tuple-component pointers
when there are zero arguments, so the empty-tuple state for `count`
doesn't try to dereference a non-existent ColumnTuple.

PR: #91358

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
`RowBinary` does not support schema inference, so
`INSERT ... SELECT * FROM file(..., RowBinary)` was unstable in
the flaky check: with some random settings the schema was inferred
from the destination table (test passed), with others schema
inference was attempted on the file and failed with
`RowBinary file format doesn't support schema inference`.

Pass the structure explicitly to every `file(..., RowBinary)` read
in Tests 19-22 so the test no longer depends on which schema
inference path is taken.

Also add Tests 23-24 covering zero-argument
`AggregateFunction(count)` for both `value` and `array` modes
(previously caused a segfault, fixed in the preceding commit).

CI failures:
- https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=91358&sha=3bcfba683502caccd778999a3e21ceb223030b18&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29
- https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=91358&sha=3bcfba683502caccd778999a3e21ceb223030b18&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%2C%201%2F2%29
PR: #91358

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@abashkeev abashkeev added the comp-data-types Type system & core datatypes used across query planning/execution. label Sep 3, 2026
…-insert-format

# Conflicts:
#	src/DataTypes/Serializations/SerializationAggregateFunction.cpp
…nd a custom CSV null representation in `array` mode

Two backward-compatibility gaps in the unified `aggregate_function_input_format` parsing, found by the review:

1. A single `Tuple` argument in `value` mode. Released read the whole field as a string and parsed it with the
   tuple's `deserializeTextCSV`, i.e. the flattened CSV form of the tuple (`"2,foo"` in `CSV`, `2,foo` in
   `TabSeparated`, `TSVRaw`, the quoted `VALUES` form and the string-wrapped `JSONEachRow` form for
   `AggregateFunction(any, Tuple(UInt64, String))`). The unified path handed the tuple to the source format's
   tuple parser: in `CSV` it consumed one outer cell per element and swallowed the following columns
   (`1,2,foo,9` was accepted as `x = (2, 'foo'), b = 9`), and the whole-field entrypoints rejected the
   flattened form. Now the field stays bounded and its content is parsed as released did
   (`useLegacyTupleValueParsing`); the native `(2,'foo')` form is accepted too when the content opens with a
   parenthesis. `Nullable(Tuple)` is unaffected: its released form was already the bounded native one.

2. The `N`/`n` dispatch in single-argument `array` mode sent every such bareword to the quoted serialization,
   which only knows the `NULL` keyword, so a custom `format_csv_null_representation` such as `Nothing`
   (`[Nothing,1]` built `[NULL,1]` on released) threw. Only the exact `NULL` keyword takes the quoted parse now;
   every other bareword keeps the released CSV element parse, which recognizes the representation and `NaN`.

Both verified against released `26.7.1`.
…d a custom `format_csv_null_representation` in `array` mode
@alexey-milovidov

alexey-milovidov commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

🕵 Status (2026-09-06):

  • Merged master (2214 commits behind, mergeable = CONFLICTING): one conflict in SerializationAggregateFunction.cpp, only the include lists (master added Core/Defines.h and base/arithmeticOverflow.h for the blocked state allocation in deserializeBinaryBulk); both sides kept. Diff vs master is exactly the PR's files, no submodule drift.
  • Fixed both AI-review blockers in 7b22c48 (the single Tuple argument value contract and the N/n dispatch vs a custom format_csv_null_representation), each verified against released 26.7.1 and pinned by a new test (05099_aggregate_function_input_format_single_tuple_argument_value, 05100_aggregate_function_input_format_array_custom_csv_null_representation); replied on both threads. All 18 existing aggregate_function_input_format tests still pass on the merged build.
  • CI reds on 8640f3397185: Docs examples failed on the timeSeriesPrometheusValueToString example width, fixed on master by Fix width of timeSeriesPrometheusValueToString doc example table (breaks "Docs examples" check) #117827 and pulled in by this merge; AST fuzzer (amd_release, oracle) was a TLP oracle mismatch on a query over remote(...) of a table whose DateTime contents changed between the reference and partitioned runs, unrelated to this PR (see the separate request below).

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=91358&sha=8640f3397185cc700ffa06b44cfc01acd0aa02b7&name_0=PR&name_1=AST%20fuzzer%20(amd_release,%20oracle) and provide a fix in a separate PR. If the fix is already in progress, link it here. It is a TLP WHERE oracle mismatch on SELECT ... FROM remote('127.0.0.{1..10}', currentDatabase(), tmp) where the reference run saw t = 2026-09-03 08:41:23 and the partitioned run 08:41:24: the table's DateTime contents changed between the two runs, so the oracle compared two different states of the data; this PR only touches AggregateFunction serialization.

@groeneai

groeneai commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Acknowledged. I investigated: this is an oracle false positive, and it is unrelated to this PR.

The carrier is tests/queries/0_stateless/03322_initial_query_start_time_check.sql, where tmp is a view rather than a table:

CREATE OR REPLACE VIEW tmp AS SELECT initialQueryStartTime() AS it, now() AS t FROM system.one WHERE NOT ignore(sleep(0.5));

So t is now(), re-evaluated on every read, and the sleep(0.5) in the view body guarantees the two oracle executions are at least half a second apart: the reference query cannot finish in under 0.5s, and the partitioned query only starts after it. That is the 08:41:23 vs 08:41:24 in the report. it is initialQueryStartTime(), which is stable per initial query, and it does match in both rows.

The gate gap: QueryOracleChecker walks every table identifier and resolves it through the catalog, but the only engine it rejects is Distributed, plus the system and INFORMATION_SCHEMA databases. A View passes, and its inner SELECT is never inspected, so the now() never reaches hasNonDeterministicFunctions, which runs on the fuzzed query's own AST where tmp is just a table name. now() already reports isDeterministic() = false, so gating the view body is enough to catch this class.

I will follow up here with a fix PR.

@groeneai

groeneai commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Fix PR: #118484

It screens the definitions a read evaluates, not only the query text: check() now resolves each name the way a read resolves it and screens a view's stored inner query and every ALIAS column expression with the same three predicates that already screen the query, failing closed on anything it cannot prove. Two further spellings hide a name behind an identifier and are covered too: an engine that forwards its read elsewhere (Alias, Merge, Buffer), and IN t or argument 0 of joinGet/dictGet, which only become table identifiers after check() has run.

Run under the oracle, 03322_initial_query_start_time_check fails 8 of 40 runs on master and 0 of 40 with the change. The screen can only skip an oracle check, never fail one.

Nothing is needed on this PR.

In `value` mode `deserializeFromValues` builds a temporary tuple of the
argument types for every argument count except one, so a zero-argument
aggregate such as `AggregateFunction(count)` gets the empty tuple. The
guard that disables `input_format_csv_deserialize_separate_columns_into_tuple`
for the temporary tuple only covered more than one argument, so the empty
tuple still went through the separate-columns branch of
`SerializationTuple::deserializeTextCSV`, which adds a row without
consuming any bytes. A `CSV` row `1,(),9` for
`a UInt8, x AggregateFunction(count), b UInt8` therefore failed with
`CANNOT_PARSE_INPUT_ASSERTION_FAILED`, because the `()` cell was left to
the following column, while released `26.7.1` pre-read one bounded field
and parsed it with the tuple's `deserializeWholeText`.

Widen the guard to every argument count that builds a temporary tuple.
Verified against released `26.7.1`: `1,(),9` and `1,"()",9` now give one
counted row again, an empty field stays the default state, and a field
that is not the empty tuple is rejected instead of spilling into the next
column. The other formats were already field-local for the empty tuple
(`TSV`, `TSVRaw`, `JSONEachRow`, `Values` all match released), and
`RowBinary` needs no bytes for it, exactly like a plain `Tuple()` column.

New test `05136_aggregate_function_input_format_zero_argument_value`.
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Status (2026-09-07):

  • Fixed the remaining AI-review blocker in aa4c603: a zero-argument aggregate in value mode also builds a temporary tuple (the empty one), so the CSV guard that keeps the temporary tuple field-local now covers every argument count except one, not only more than one. On the previous head 1,(),9 for a UInt8, x AggregateFunction(count), b UInt8 failed with CANNOT_PARSE_INPUT_ASSERTION_FAILED, while released 26.7.1 parses it as one counted row.
  • New test 05136_aggregate_function_input_format_zero_argument_value, generated from released 26.7.1 output: the bare and quoted empty tuple, the setting explicitly disabled, an empty field (default state), and a non-empty-tuple field rejected instead of spilling into the following column. The other entrypoints were already field-local for the empty tuple (TSV, TSVRaw, JSONEachRow, Values match released) and RowBinary consumes no bytes for it, exactly like a plain Tuple() column.
  • All 21 aggregate_function_input_format tests pass on the rebuilt binary; local style check is clean (only the two known local-only failures: broken symlinks under the untracked build directory and settings_changes_history, which needs the CI changed_files data).
  • Thanks @groeneai for the oracle analysis and for AST fuzzer oracle: screen the definitions a read evaluates, not only the query text #118484 — agreed, nothing is needed on this PR for that AST fuzzer red.
  • CI on 8e731ad9c824 was fully green; the branch is 450 commits behind master but MERGEABLE, so I did not re-merge.

`serializeBinary(Field, ...)` always writes the length-prefixed opaque
state, but `deserializeBinary(Field, ...)` read the same bytes as a
`value` / `array` payload whenever `aggregate_function_input_format` was
not `state`, so the two stopped being inverses of each other.

The `Field` overloads are the representation of an `AggregateFunction`
value nested inside another value: the argument of `argMax`, the value of
a `sumMap`, or a `JSON` path that does not fit into the dynamic paths and
goes to the shared data. Such a carrier only ever reads back what
`serializeBinary(Field, ...)` wrote, and it may keep the consumed bytes as
they are, so reading the length prefix as an argument value corrupts both
the value and everything that follows it in the row: for
`AggregateFunction(any, UInt64)` the value branch consumed the length
prefix plus seven bytes of the state as the `UInt64` argument and left the
rest behind.

Read the length-prefixed state unconditionally, exactly as before this
change set, and keep the `value` / `array` forms on the `IColumn` path,
which is what a binary input format reads a column with, including a
column nested inside a `Tuple` or a `Dynamic`.

New test `05137_aggregate_function_input_format_binary_field_carrier`.
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pass update.

CI on aa4c60347f4b came back fully green (all 174 checks SUCCESS, MERGEABLE/CLEAN), and the AI review on that head raised one blocker: deserializeBinary(Field, ...) had stopped being the inverse of serializeBinary(Field, ...) under aggregate_function_input_format = 'value'/'array'. That is a real problem for every carrier that recurses through the Field overloads (the argument of argMax, the value of a sumMap, a JSON path that goes to the shared data), so it is fixed in e8c47fc8b430: the Field form is the length-prefixed opaque state again, exactly as on master, and the value/array forms stay on the IColumn path that a binary input format reads a column with. Details and the measurement are in the thread reply.

New test 05137_aggregate_function_input_format_binary_field_carrier. All 22 .sql tests of this pull request pass against a local build of the branch (the two .sh ones need a server and are left to CI); the branch is one day and 734 commits behind master with green CI, so no re-merge this pass.

Remaining: fresh CI on e8c47fc8b430, the AI re-verdict, and the human merge.

zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…inputs

The refactor in 0d6411e dropped the check that
`function->deserialize` consumed the entire bounded buffer when reading
a state from a string-based path. As a result, garbage suffixes were
silently accepted for `Escaped`/`Quoted`/`WholeText`/`JSON`/`CSV` state
inputs, regressing tests that expect `BAD_ARGUMENTS` for malformed
states (`02477_single_value_data_string_regression`,
`03716_topk_bad_data`, `04027_redundant_trailing_bytes_aggregate_function_deserialization`,
`04027_reverseUTF8_invalid_utf8`,
`04048_sumcountif_nullable_backward_compat`).

Add an opt-in `check_buffer_consumed` parameter to the shared
`deserializeFromString` helper. The text-format callers — which read a
single value into a `ReadBufferFromString` — pass `true`, restoring the
master-branch behavior of throwing `BAD_ARGUMENTS` on trailing bytes.
The binary per-row path keeps the default (`false`) so streaming
deserialization of subsequent rows is preserved.

CI failures: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=91358&sha=a7a14a69d127be5290c774b24618c22e45097fca&name_0=PR&name_1=Fast%20test
PR: ClickHouse#91358

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
In `SerializationAggregateFunction::deserializeBinary(Field &, ...)` for
`value`/`array` modes, the temporary `place` is created via
`function->create(place)` and used only to build `s.data` via
`function->serialize`. On the success path the matching
`function->destroy(place)` was missing, so aggregate functions whose
state holds non-trivial resources (e.g. containers, external
allocations) leaked those resources for every row parsed in
`value`/`array` modes.

PR: ClickHouse#91358

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
`createStateFromValues` previously derived the row count from
`arg_columns[0]->size()`. For zero-argument aggregate functions like
`AggregateFunction(count)`, `columns_ptrs` is empty in `value`/`array`
modes, so `arg_columns[0]` is invalid and the server segfaulted.

Pass the row count explicitly: `1` for value mode, the parsed array
length for array mode. Also skip building tuple-component pointers
when there are zero arguments, so the empty-tuple state for `count`
doesn't try to dereference a non-existent ColumnTuple.

PR: ClickHouse#91358

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
`RowBinary` does not support schema inference, so
`INSERT ... SELECT * FROM file(..., RowBinary)` was unstable in
the flaky check: with some random settings the schema was inferred
from the destination table (test passed), with others schema
inference was attempted on the file and failed with
`RowBinary file format doesn't support schema inference`.

Pass the structure explicitly to every `file(..., RowBinary)` read
in Tests 19-22 so the test no longer depends on which schema
inference path is taken.

Also add Tests 23-24 covering zero-argument
`AggregateFunction(count)` for both `value` and `array` modes
(previously caused a segfault, fixed in the preceding commit).

CI failures:
- https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=91358&sha=3bcfba683502caccd778999a3e21ceb223030b18&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29
- https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=91358&sha=3bcfba683502caccd778999a3e21ceb223030b18&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%2C%201%2F2%29
PR: ClickHouse#91358

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
alexey-milovidov and others added 2 commits September 12, 2026 02:28
…ion`

`SerializationAggregateFunction::deserializeBinary(Field &, ...)` is the exact
inverse of `serializeBinary(Field &, ...)` and stays on the length-prefixed
opaque state regardless of `aggregate_function_input_format`, because a carrier
such as the shared data of a `JSON` column keeps the consumed bytes as they are
and reads them back with the same representation.

The `value` and `array` forms therefore only apply to an `AggregateFunction`
cell that the format reads as a column. Say so in the `RowBinary` documentation
(source of truth: the doc string in `BinaryRowInputFormat.cpp`) and in the
description of the setting, instead of advertising blanket `RowBinary` support
for every `AggregateFunction` value.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pass update (2026-09-12), head 15a9bb793012:

  • Merged master (the branch was 3092 commits behind, clean merge, no gitlink drift). This also clears the private Build (arm_tidy) red that made CH Inc sync report build failed: it was src/Storages/MergeTree/MergeTreeIndexConditionText.cpp:36: error: duplicate include [readability-duplicate-include], unrelated to this PR and already fixed on master.
  • Addressed the AI Review ⚠️ Request changes verdict (the only remaining finding, Build profile diff job). I took the second of the two offered actions — narrowing the documented contract rather than changing the Field binary form, because SerializationAggregateFunction::deserializeBinary(Field &, ...) must stay the exact inverse of serializeBinary(Field &, ...): a carrier such as the shared data of a JSON column keeps the consumed bytes as they are and writes them back with the same representation, so it can only accept the length-prefixed opaque state. The RowBinary documentation (source of truth: the doc string in BinaryRowInputFormat.cpp) and the description of aggregate_function_input_format now say explicitly that value / array apply to an AggregateFunction cell that the format reads as a column — including one nested inside Array, Tuple, Map, Nullable, Variant, or a Dynamic / JSON path that has its own subcolumn — and that a JSON path that goes to the shared data always expects the opaque state, independently of the setting. This is the behaviour that 05137_aggregate_function_input_format_binary_field_carrier already pins.
  • Verified locally on the merged tree: clickhouse builds, and all 23 aggregate_function_input_format tests pass.

No unresolved review threads. Waiting on fresh CI and the human merge.

@alexey-milovidov

Copy link
Copy Markdown
Member

I thought about a different implementation:

We support deserialization of aggregate function states in the value and array modes in any data format.

We implement it in the following way: - ask the data format to deserialize a different data structure (header), where instead of AggregateFunction, we ask for the corresponding type, representing a value or an array.

We add a transformation on top, which constructs an AggregateFunction from these values.

In this way, it will be actually unified, as I imagined in the original design.

@alexey-milovidov
alexey-milovidov marked this pull request as draft September 19, 2026 23:37
@alexey-milovidov alexey-milovidov added close in a month if not active This will be closed in case of no information hold Skip for auto-updating. labels Sep 19, 2026
pull Bot pushed a commit to sowelswl/ClickHouse that referenced this pull request Sep 21, 2026
…and a transformation

Instead of implementing the `value` and `array` modes inside `SerializationAggregateFunction`
for every text escaping rule, `FormatFactory::getInput` asks the input format to parse a header
in which every `AggregateFunction(f, T...)` is replaced with the type of the values `f` aggregates
(`T`, or `Tuple(T...)`, or `Array` of it), and wraps the format into
`AggregateFunctionStatesFromValuesInputFormat`, which builds the states from the parsed values
and outputs chunks of the original header. The replacement is recursive inside `Array`, `Tuple` and `Map`.

This makes the setting work uniformly in every input format, including `RowBinary`, `Native`
and `Parquet`, with the parallel parsing, asynchronous inserts and defaults for omitted fields.
`SerializationAggregateFunction` reads only states again.

The values are written as the format writes the argument type: in the JSON formats the value
is a JSON value (`{"x": [1, 2, 3]}`), not a string containing it.

As proposed in ClickHouse#91358 (comment)

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

close in a month if not active This will be closed in case of no information comp-data-types Type system & core datatypes used across query planning/execution. hold Skip for auto-updating. pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants