Skip to content

Add embedded documentation for aggregate function combinators - #106185

Merged
alexey-milovidov merged 10 commits into
masterfrom
aggregate-combinator-documentation
Jun 13, 2026
Merged

alexey-milovidov merged 10 commits into
masterfrom
aggregate-combinator-documentation

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented May 31, 2026 •

Copy link
Copy Markdown
Member

Part of the series adding embedded, runtime-introspectable documentation to ClickHouse component registries (table engines #106177, database engines #106178, data types #106180, formats #106181, dictionary layouts #106182, dictionary sources #106184). This one covers aggregate function combinators.

What it does:

  • Threads the shared Documentation struct (src/Common/Documentation.h) through AggregateFunctionCombinatorFactory::registerCombinator, storing it in CombinatorPair.
  • system.aggregate_function_combinators now exposes description, syntax, examples, introduced_in, and related columns (previously only name, is_internal).
  • Populates all 14 combinators: If, Array, ForEach, Map, State, SimpleState, Merge, Null, OrNull, OrDefault, Distinct, Resample, ArgMin, ArgMax.

Note on doc embedding: combinators are documented on a single combined reference page rather than one page per combinator, so this PR uses accurate concise descriptions (with syntax and related) rather than embedding a full per-combinator markdown page.

StorageSystemCompletions is updated for the additional CombinatorPair field. This PR shares src/Common/Documentation.h/.cpp with the earlier PRs in the series (trivial add/add on merge).

Changelog category (leave one):

  • Improvement

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

Aggregate function combinators now carry embedded documentation, introspectable via the new description, syntax, examples, introduced_in, and related columns of the system.aggregate_function_combinators table.

Documentation entry for user-facing changes

  • Documentation is provided as part of this change (embedded documentation in system.aggregate_function_combinators).

Version info

  • Merged into: 26.6.1.761

Attach the shared `Documentation` struct (introduced for table engines) to
aggregate function combinators, and expose `description`, `syntax`, `examples`,
`introduced_in`, and `related` columns on `system.aggregate_function_combinators`.

- `AggregateFunctionCombinatorFactory::registerCombinator` now takes a final
  `Documentation` argument, stored in `CombinatorPair`.
- All 14 combinators (`If`, `Array`, `ForEach`, `Map`, `State`, `SimpleState`,
  `Merge`, `Null`, `OrNull`, `OrDefault`, `Distinct`, `Resample`, `ArgMin`,
  `ArgMax`) get a description and syntax. Combinators are documented on a single
  combined page, so concise descriptions are used.

`StorageSystemCompletions` is updated for the additional `CombinatorPair` field.

This is a follow-up to the embedded-documentation changes for table engines,
database engines, data types, formats, and dictionary layouts/sources, and
reuses the `Documentation` struct from `src/Common/Documentation.h`.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented May 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1cfb634]

Summary: ✅


AI Review

Summary

This PR threads shared Documentation through AggregateFunctionCombinatorFactory and exposes description, syntax, examples, introduced_in, and related from system.aggregate_function_combinators. The code path and the previously discussed ArgMin/ArgMax, Resample, and SimpleState wording fixes now look consistent, but the regression test still does not prove the stated contract that every user-facing combinator has embedded docs.

Findings

⚠️ Majors

  • [tests/queries/0_stateless/04305_aggregate_function_combinators_documentation.sql:6] system.aggregate_function_combinators is supposed to prove every user-facing aggregate function combinator has non-empty description and syntax, but the test samples only If, Array, State, Merge, and Distinct. Since AggregateFunctionCombinatorFactory::registerCombinator still accepts default-empty Documentation, the test would pass if ForEach, Map, SimpleState, OrNull, OrDefault, Resample, ArgMin, or ArgMax lost their docs.
    Suggested fix: assert over all WHERE NOT is_internal rows, for example by checking countIf(empty(description) OR empty(syntax)) = 0 and the expected public combinator count.
Tests
  • ⚠️ Expand 04305_aggregate_function_combinators_documentation to cover every non-internal combinator, not just the current five-name sample.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: broaden the regression test so the new system.aggregate_function_combinators documentation contract is enforced for all user-facing combinators.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label May 31, 2026
Addresses review feedback on the embedded documentation exposed via
`system.aggregate_function_combinators`:

- `ArgMin`/`ArgMax`: the previous text described only the single nested
  argument case (`sumArgMin(x, key)`). In general the last argument is
  the comparable key and the nested aggregate processes all preceding
  arguments, which may be zero (`countArgMin(key)`), one
  (`sumArgMin(x, key)`), or several (`corrArgMin(x, y, key)`). The
  description and `syntax` now reflect this general calling convention.

- `Resample`: the `syntax` omitted the second parameter list that
  supplies the nested aggregate arguments and the resampling key. It is
  now `<aggregate_function>Resample(start, end, step)(<aggregate_function_arguments>, resampling_key)`,
  matching the public documentation.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
alexey-milovidov and others added 2 commits June 3, 2026 00:46
`AggregateFunctionSimpleState::insertResultInto` delegates to the nested
function, so the combinator returns the final aggregation result value
(typed as `SimpleAggregateFunction`), not a serialized intermediate state.
The previous wording described it like `State`, which would teach an
incorrect calling convention via `system.aggregate_function_combinators`.

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

Copy link
Copy Markdown
Member Author

The failures of 00175_obfuscator_schema_inference and 00096_obfuscator_save_load in Stateless tests (amd_tsan, parallel) are NOT caused by this PR.

They were introduced by #104690 ("Add UntrackedMemory asynchronous metric"), which made clickhouse-obfuscator abort (SIGABRT) on process teardown: the query results are correct, but the Aborted line on stderr fails the test. #104690 has now been reverted (#106365).

#104690 was merged in violation of the ClickHouse team rules: its own CI already showed these two tests failing (10 times between May 12 and June 1) before it was merged.

Please update your branch to pick up the revert; the tests should pass again.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Merged master to bring the branch up to date (was 953 commits behind). This picks up the revert of #104690 (#106365), so the unrelated 00175_obfuscator_schema_inference / 00096_obfuscator_save_load failures should be gone.

The shared src/Common/Documentation.h/.cpp merged cleanly with no add/add conflict — master already contains the identical Documentation struct from the earlier PRs in the series, so the diff is now just the combinator registrations, the system.aggregate_function_combinators columns, completions, and the test.

Verified locally: rebuilt clickhouse clean, and 03307_aggregate_function_combinators_documentation output matches its reference. All 14 combinators carry a non-empty description and syntax.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Merged master (was 347 commits behind) — clean merge, no conflicts; the shared src/Common/Documentation.h/.cpp from the earlier PRs in the series merged trivially. Rebuilt clickhouse and verified locally: system.aggregate_function_combinators exposes description/syntax/examples/introduced_in/related for all 14 combinators, the new test 04305_aggregate_function_combinators_documentation passes, and the 02117_show_create_table_system reference matches the new column layout. No unresolved review threads.

The CI reds are all unrelated, pre-existing flakies:

  • Stateless tests (amd_debug, parallel): the Logical error: Virtual row boundary violated in MergingSortedAlgorithm aborts the debug server, which produces the collateral 03222_create_timeseries_table and Server died failures. This is Fix LOGICAL_ERROR Virtual row boundary violated under read-in-order over Union #106664 (fix in progress, assigned to @vdimir).
  • Stress test (amd_tsan): generic Hung check failed with a TSan stack in PullingAsyncPipelineExecutor/ThreadPool — no relation to combinator-registry documentation threading.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

@groeneai, fix

test_parallel_replicas_over_distributed/test.py::test_parallel_replicas_over_distributed[test_multiple_shards_multiple_replicas-10-1]

and send a PR with the fix.

@groeneai

groeneai commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

@alexey-milovidov this isn't a test_parallel_replicas_over_distributed failure. helpers/cluster.py::shutdown scans each instance's docker log for ================== and the hit is in the zoo2-1 clickhouse-keeper container, not the test's clickhouse-server nodes. The test's own assertions all passed.

The actual race (from _instances-gw2/docker.log in logs.tar.gz, fb27559):

WARNING: ThreadSanitizer: data race (pid=1)
  Read at 0x...6008 by thread T33 'KeeperRequest':
    #1 KeeperRequestForSession::operator=(&&) src/Coordination/KeeperCommon.h:57
    #2 NonblockingBoundedQueue<KeeperRequestForSession>::tryPop src/Common/NonblockingBoundedQueue.h:138
    #3 KeeperRequestDispatcher::tryPopRequest src/Coordination/KeeperRequestDispatcher.cpp:346
    #4 KeeperRequestDispatcher::dispatchThread .cpp:653
  Previous write at same address by thread T6 'KeeperHandler':
    #1 KeeperRequestForSession::operator=(&&) src/Coordination/KeeperCommon.h:57
    #2 NonblockingBoundedQueue<KeeperRequestForSession>::tryPush src/Common/NonblockingBoundedQueue.h:107
    #3 KeeperRequestDispatcher::putRequest::$_0 src/Coordination/KeeperRequestDispatcher.cpp:307
    #6 KeeperTCPHandler::receiveRequest src/Server/KeeperTCPHandler.cpp:830
  As if synchronized via sleep [dispatchThread .cpp:660]

Producer and consumer touch the same 8-byte field of the same Slot in the request queue. The Vyukov protocol uses slot.pos acquire/release as the single sync point for slot.value; the As if synchronized via sleep note means TSan could not prove that pair (likely a tracking limitation on Vyukov-style MPMC queues).

CIDB, 90d: 1100+ Sanitizer assert found for instance zoo* hits across 8 distinct test files, almost exclusively Integration tests (amd_tsan, *). Heaviest spike 2026-04-10 to -16 (152-268/day) immediately after KeeperRequestDispatcher2 landed (commit 2bfce0838853, 2026-04-07, Michael Kolupaev / @ al13n321). Since late April it has tapered to ~1-2/day. PR #106185 itself touches only aggregate-function combinator code. No existing issue or fix PR for this race.

I am hesitant to patch the queue speculatively without a local TSan repro, and a tests/tsan_ignorelist.txt entry would silence a real diagnostic. Could you direct me on which path you want: (a) ignorelist entry on NonblockingBoundedQueue::tryPush/tryPop, (b) hand off to @ al13n321 (the queue's author), or (c) something else? Happy to open a small PR for (a) if that is what you want.

Failing report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106185&sha=fb27559f055b68972384718352e7c41b809441b3&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%206%2F6%29

session: cron:clickhouse-ci-task-worker:20260609-020700

@al13n321

al13n321 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

I couldn't figure out the NonblockingBoundedQueue TSAN error. Here's a PR that may or may not have any effect on it: #106801

@groeneai

groeneai commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Thanks for taking a look. Reading #106801: the second slot.pos.load(acquire) plus the parity invariant ((slot.pos - slot_idx) % 2 == 0 in tryPush, == 1 in tryPop) is a clean win regardless of TSan. It catches a real protocol violation deterministically, and the extra acquire is plausibly enough to nudge TSan past whatever heuristic it is missing on the original Vyukov fence.

I will track the CIDB signal after #106801 merges:

  • Baseline: ~1-2/day across 8 distinct integration tests since late April, down from the 152-268/day spike right after KeeperRequestDispatcher2 landed.
  • If the rate decays to zero in 7 days: chronic closed; the extra acquire was the missing TSan hint.
  • If the parity check ever fires (std::abort): real bug, will report immediately.
  • If neither and the rate continues: a tsan_ignorelist entry on NonblockingBoundedQueue::tryPush/tryPop is the obvious fallback. Happy to send that PR once we have the data.

Session: cron:clickhouse-ci-task-worker:20260609-081800

@clickhouse-gh

clickhouse-gh Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.70% 84.80% +0.10%
Functions 92.30% 92.40% +0.10%
Branches 77.30% 77.30% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 90/90 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Jun 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jun 13, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

@groeneai, send a follow-up PR.

The documentation should be as complete as the Markdown docs on the website. We can copy Markdown docs directly to the source code. The end goal is to make Markdown docs fully generated from the source code.

Merged via the queue into master with commit 0f3fdcf Jun 13, 2026
166 checks passed
@alexey-milovidov
alexey-milovidov deleted the aggregate-combinator-documentation branch June 13, 2026 20:28
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants