Repository navigation
Add groupFormat aggregate function - #93201
Conversation
|
Workflow [PR], commit [81beef8] Summary: ✅
AI ReviewSummaryThis PR adds Missing context / blind spots
Final VerdictStatus: ✅ Approve |
e1a50d3 to
0682b74
Compare
|
The remaining failures appear to be flaky CI tests. Please let me know if you’d like another re-run or if we can proceed as-is. Thanks! |
10ac6fa to
0add1ae
Compare
|
The MSan stress test failure (MemorySanitizer: use-of-uninitialized-value, STID 4179-5154 or 4148-3044) is a known pre-existing issue unrelated to this PR. Fix: #102158 |
Resolve the three open review threads on the pull request. 1. Capture the `FormatSettings` once at creation time (in the factory) and store them as a member, instead of deriving them per group in `insertResultInto`. The context is still resolved on demand, only because `getOutputFormat` requires one - it must not be captured into the function object, which is embedded into `DataTypeAggregateFunction` and can outlive the query that created it. Consequently the format settings of a stored `AggregateFunction(groupFormat(...), ...)` state are no longer guaranteed to come from the finalizing query; this is left intentionally unspecified, so the corresponding documentation sentence and the finalize-time-settings test case are dropped. 2. Disable `write_statistics` for the nested formatter. Otherwise formats such as `JSON` and `XML` would emit a `statistics` section whose `rows_read` / `bytes_read` come from the enclosing query rather than from the group being formatted, putting misleading metadata into the resulting string. Added a regression test. 3. Remove the documentation claim that an empty non-nullable group formats to an empty string. Several formats (for example `CSVWithNamesAndTypes` and `JSON`) emit header or wrapper data for a zero-row block, so the behavior is left intentionally unspecified. ClickHouse#93201 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Address review feedback: the note claimed that query-level format settings are applied, which was too broad. The format settings are captured when the aggregate function is initialized, and `groupFormat` always forces `output_format_write_statistics` off so the formatted string never contains a statistics section. Reword the note to reflect this. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
CI triage for
|
Originally I wanted to mirror But the cost is too high: I'm leaning toward skip-NULL. It lets us delete the whole |
master added several 04337_* tests, so renumber the test to the next free number to keep the test numbering tidy. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`finalizeAggregation(groupFormatState(...))` finalizes the in-memory state and does not exercise the custom binary `serialize` / `deserialize` of `AggregateFunctionGroupFormat`. Add `04342_group_format_serialization`, which stores the state in a `MergeTree` `AggregateFunction` column so that `serialize` runs on INSERT (into the on-disk part) and `deserialize` runs on read, proving the binary state format round-trips. It covers reading a stored state back, merging states deserialized from two separate parts, and a `Dynamic` payload. The `Dynamic` case proves the self-describing Native serialization version is sound: the writer embeds the chosen version (V1 for an old client protocol revision, V2 otherwise) into the stream and the reader recovers it from the stream, so the round-trip is lossless regardless of the captured protocol revision and there is no write-V1 / read-V2 mismatch. Also correct the misleading comment in `03775_group_format` that described the in-memory `finalizeAggregation` as a serialize/deserialize round-trip. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Pushed a re-merge of Test gap (the test did not exercise Serialization version contract ( |
|
Merged latest The only CI failure on the previous head was
This harness bug was fixed on No code changes to |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 136/153 (88.89%) | Lost baseline coverage: none · Uncovered code |
Yes, I changed it to be this way. Now it is quite simple. Going to review... |
The file calls `CurrentThread::get().tryGetQueryContext()`, but `Common/CurrentThread.h` only forward-declares `ThreadStatus`. Without `Common/ThreadStatus.h`, member access through the returned reference fails with `member access into incomplete type 'ThreadStatus'`. This mirrors the include pattern used in `AggregateFunctionFactory.cpp`, `FunctionFactory.cpp`, and all other sites that resolve `tryGetQueryContext` via `CurrentThread::get`. CI report: ClickHouse#93201
Resolve the three open review threads on the pull request. 1. Capture the `FormatSettings` once at creation time (in the factory) and store them as a member, instead of deriving them per group in `insertResultInto`. The context is still resolved on demand, only because `getOutputFormat` requires one - it must not be captured into the function object, which is embedded into `DataTypeAggregateFunction` and can outlive the query that created it. Consequently the format settings of a stored `AggregateFunction(groupFormat(...), ...)` state are no longer guaranteed to come from the finalizing query; this is left intentionally unspecified, so the corresponding documentation sentence and the finalize-time-settings test case are dropped. 2. Disable `write_statistics` for the nested formatter. Otherwise formats such as `JSON` and `XML` would emit a `statistics` section whose `rows_read` / `bytes_read` come from the enclosing query rather than from the group being formatted, putting misleading metadata into the resulting string. Added a regression test. 3. Remove the documentation claim that an empty non-nullable group formats to an empty string. Several formats (for example `CSVWithNamesAndTypes` and `JSON`) emit header or wrapper data for a zero-row block, so the behavior is left intentionally unspecified. ClickHouse#93201 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…upFormat Add `groupFormat` aggregate function
Add a new
groupFormataggregate function that formats all rows within each group using a specified output format (e.g.JSONEachRow,CSV,TabSeparated) and returns the result as aString.This is a group-level counterpart to
formatRow: whileformatRowworks on a single row,groupFormataccumulates all rows in the group and produces a single formatted string using block-based output formats.Example:
Implementation notes:
c1,c2, ... in argument order.AggregateFunction(groupFormat(...), ...)states, finalization is not guaranteed to use the finalizing query's format settings. The nested formatter forcesoutput_format_write_statisticsoff.NULLargument are skipped, matchinggroupArrayandgroupConcat.Closes: #92477
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add
groupFormataggregate function that formats rows in each group using a specified output format and returns the result as a string.Documentation entry for user-facing changes
Version info
26.7.1.78