Skip to content

Antalya 26.6: add UniqApacheHLL - #2398

Open
UnamedRus wants to merge 6 commits into
antalya-26.6from
feature/antalya-26.6/uniq-apache-hll
Open

UnamedRus wants to merge 6 commits into
antalya-26.6from
feature/antalya-26.6/uniq-apache-hll

Conversation

@UnamedRus

@UnamedRus UnamedRus commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • New Feature

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

Aggregate function, which states are compatible with apache data sketches HLL implementation

CI/CD Options

Exclude tests:

  • Fast test
  • Integration Tests
  • Stateless tests
  • Stateful tests
  • Unit tests
  • Performance tests
  • Aarch64 tests
  • All with ASAN
  • All with TSAN
  • All with MSAN
  • All with UBSAN
  • All with Coverage
  • All Regression
  • Disable CI Cache

Regression jobs to run:

  • Fast suites (mostly <1h)
  • Aggregate Functions (2h)
  • Alter (1.5h)
  • Benchmark (30m)
  • CAS (content-addressed storage; Antalya only)
  • ClickHouse Keeper (1h)
  • Iceberg (2h)
  • LDAP (1h)
  • OAuth (5m)
  • Parquet (1.5h)
  • RBAC (1.5h)
  • SSL Server (1h)
  • S3 (2h)
  • S3 Export (2h)
  • Swarms (30m)
  • Tiered Storage (2h)

@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Workflow [PR], commit [a6477a1]

UnamedRus and others added 2 commits September 17, 2026 15:15
Backport of ClickHouse/ClickHouse@a067567, re-created
here rather than cherry-picked so that it carries a sign-off.

The submodule tracked `apache/datasketches-cpp` directly, pinned to `76edd74f`
(2024-05-16), an upstream development commit. It moves onto a `ClickHouse/`-prefixed
branch of our fork, the way `docs/development/contrib` asks:

    ClickHouse/datasketches-cpp, branch ClickHouse/5.2.0
      de8553ba  5.2.0, the newest upstream release (2025-01-15)
      23bd9b07  backport of apache/datasketches-cpp#512

apache/datasketches-cpp#512 is the HyperLogLog union fix. No upstream release carries
it, so it is cherry-picked onto the `5.2.0` tag there. `uniqApacheHLL`, added next,
needs it: without it a merged HLL sketch reports a wrong estimate and serializes a
state that other DataSketches implementations read differently.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: UnamedRus <dtitmoav@gmail.com>
…tion

Ported from `vk/uniq-apache-hll` (github.com/UnamedRus/ClickHouse), which develops the
function against `master`.

`uniqApacheHLL` counts distinct values into an Apache DataSketches HLL sketch, and its
`-State` serializes that sketch in the DataSketches format, so states can be exchanged
with Java, Python and C++ services through the standard `-State`/`-Merge` combinators.
Only the argument types those libraries hash the same way are accepted - integers of at
most 64 bits, Enum8/16, BFloat16, Float32/64, String, FixedString, UUID, IPv4, IPv6,
Date, Date32, DateTime and DateTime64 - so no state can be built here that an external
consumer cannot reproduce.

Two deviations from the branch this is taken from, both forced by the age of this base:

  - the state overrides `merge`, not `mergeImpl`. `IAggregateFunction::merge` is still
    the pure virtual here; the split into a non-virtual `merge` plus a `mergeImpl`
    override came later.
  - `introduced_in` says 26.6 rather than 26.9, this being the release it ships in.

NOT BUILT OR TESTED on this base - only ported and checked by inspection against the
26.6 headers. CI is the first real build.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: UnamedRus <dtitmoav@gmail.com>
@UnamedRus
UnamedRus force-pushed the feature/antalya-26.6/uniq-apache-hll branch from 3c1bcdb to 8cd0586 Compare September 17, 2026 12:16
@alsugiliazova alsugiliazova mentioned this pull request Sep 24, 2026
9 of 30 tasks
@svb-alt
svb-alt requested a review from zvonand September 28, 2026 16:19
@DimensionWieldr

This comment was marked as outdated.

@zvonand zvonand changed the title Feature/antalya 26.6/uniq apache hll Antalya 26.6: add UniqApacheHLL Sep 29, 2026
Reuse `assertUnary`, consolidate state handling, and shorten repetitive
comments and documentation. Merge overlapping HLL tests while retaining
interoperability, cross-resolution, corruption, and dependency coverage.

Use the canonical `Enum` documentation type to avoid a logical-error
exception when reading `system.functions`.

Validation: rebuilt ClickHouse and passed all four remaining PR tests
with the pinned DataSketches revision; no tests skipped.

Related: #2398
@zvonand

zvonand commented Sep 30, 2026

Copy link
Copy Markdown
Member

@blau-ai

@zvonand

zvonand commented Sep 30, 2026

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-30T08:50:26.470323Z 9c9c7fb Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@blau-ai

blau-ai commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

CI triage — @zvonand

Verdict: Only one class of failure is caused by this PR, and it's the expected one — the regression suite noticing the new function isn't covered yet. Everything else is pre-existing / flaky / infra. Nothing points to a bug in the uniqApacheHLL implementation: the PR's own tests (04327, 05026, 05055, 05136) all passed, and every functional/build/unit/integration job for the core code is green.

Head SHA analyzed: 9c9c751 (9c9c7fbb49f510a5ecd72c41c14ab5952d1d4d58).


🔴 PR-caused (1 root cause — action needed, but not in this repo)

Regression … aggregate_functions_1 — fails on every variant (release + aarch64, plain / cas / cas_s3_cache). All share one message:

Aggregate function 'uniqApacheHLL' was added, but not tested.
/aggregate functions/part 1/function_list/untested function uniqApacheHLL → Fail

This is the Altinity clickhouse-regression function_list guard: it asserts that every aggregate function reported by system.functions is present in the suite's known/tested list. Adding uniqApacheHLL (registered at AggregateFunctionUniqApacheHLL.cpp:128) trips it by design.

Fix: add uniqApacheHLL to the aggregate-function list (and, ideally, a small coverage test) in the clickhouse-regression repo — not in this PR. This is a separate repository I don't have write access to, so a human needs to open that PR. Once the function is listed there, all aggregate_functions_1 variants go green. No change is required to the ClickHouse code in this PR.


🟡 Not PR-caused — pre-existing / flaky / infra (safe to re-run or ignore)

Stateless tests — all failures are unrelated to aggregate functions and are confirmed transient by CI's own auto-rerun:

Suite Test CI rerun verdict
amd_msan WasmEdge 2/4 03572_export_merge_tree_part_limits_and_table_functions All reruns passed — not reproducible
amd_debug distributed s3 03572_export_merge_tree_part_limits_and_table_functions All reruns passed — not reproducible
amd_tsan cas s3 1/2 03913_…statistics, 03164_materialize_skip_index_on_merge, 03100_lwu_23_apply_patches, 04049_tuple_inside_nullable_…, 02346_text_index_partially_materialized All reruns passed — not reproducible
amd_tsan cas s3 1/2 04661_refreshable_mv_cancel_during_planning flaky (1/5 reruns failed)
arm_asan_ubsan azure 02354_vector_search_rescoring_distance_in_select_list fails 3/3 — small BFloat16 distance rounding diff (0.203125 vs 0.1875); vector-search FP precision on ARM, no overlap with this PR

Stress test (amd_asan_ubsan, cas s3 storage) — Cannot start clickhouse-server / Check failed. Server-startup/infra failure in the cas-s3 stress variant; all other 15 stress variants (incl. amd_asan_ubsan plain) are green → infra/flaky, not code.

Integration tests (arm_binary, distributed plan, 3/4) — ERROR: Failed to pre-pull Docker images needed by the test batch. Pure infra; the other 3/4 shards passed. Safe to re-run.

Grype Scan (keeper + server-alpine) — CVE-2026-85091 (High) flagged in the base image. Decisive tell: the keeper image contains none of this PR's aggregate-function code yet fails identically → it's a base-image CVE, pre-existing across the branch, not introduced here.

Other regression suites — cas_alter_attach_3, cas_lightweight_delete_4, cas_s3_cache_lightweight_delete_4, cas_selects, s3_azure_1, settings, swarms. These cover SELECT FINAL concurrency, lightweight delete, ALTER ATTACH, S3/Azure, an iceberg setting default (iceberg_manifest_min_count_to_compact AssertionError), swarms, etc. — feature areas with zero code overlap with a single new aggregate function. Spot-checked reports show generic AssertionErrors / timeouts / errored features typical of the branch's regression baseline. Pre-existing noise on antalya-26.6, not caused by this PR.


TL;DR

  • PR-related: aggregate_functions_1 regression only — expected; fix by registering uniqApacheHLL in the clickhouse-regression suite (separate repo, needs a human).
  • Everything else (other regression suites, stateless, stress, integration pre-pull, Grype): pre-existing / flaky / infra — re-run the flaky ones; the Grype CVE and the regression-baseline failures are branch-wide, not from this PR.
  • The uniqApacheHLL code itself looks healthy: its dedicated tests and all core build/functional/unit jobs are green.

🤖 Automated CI triage by @blau-ai. Evidence: praktika result_pr.json + testflows reports for 9c9c751. I can't build/run ClickHouse locally, so these are read from CI artifacts.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9c9c7fbb49

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/AggregateFunctions/AggregateFunctionUniqApacheHLL.h Outdated
Comment thread src/AggregateFunctions/AggregateFunctionUniqApacheHLL.h
…ation

- Construct `hll_union` with the requested `lg_k` instead of flooring it at 7,
  so `uniqApacheHLLMerge(4..6)` produces sketches with the requested `lg_k`.
  `hll_union` accepts `lg_max_k` in [4, 21].
- Serialize an untouched state as the library's compact empty sketch instead
  of a zero-length vector, so external DataSketches consumers can read it.

Related: #2398 (comment)
Related: #2398 (comment)
@DimensionWieldr

Copy link
Copy Markdown
Collaborator

AI audit note: This review comment was generated by AI.

Audit update for PR #2398 (uniqApacheHLL, Apache DataSketches HLL aggregate):

Confirmed defects:

Medium: Fast test and any ENABLE_LIBRARIES=0 build fail to link

  • Impact: clickhouse does not link when DataSketches is disabled. Fast test configures with -DENABLE_LIBRARIES=0, which turns off ENABLE_DATASKETCHES / USE_DATASKETCHES.
  • Anchor: src/AggregateFunctions/registerAggregateFunctions.cpp / registerAggregateFunctions; src/AggregateFunctions/AggregateFunctionUniqApacheHLL.cpp / registerAggregateFunctionUniqApacheHLL
  • Trigger: Configure with -DENABLE_LIBRARIES=0 and link the server.
  • Why defect: The call is unconditional, but the definition is compiled only under #if USE_DATASKETCHES. uniqTheta avoids this by registering inside registerAggregateFunctionUniq, which always exists. There is no #else stub here.
  • Fix direction (short): Provide an empty registerAggregateFunctionUniqApacheHLL when USE_DATASKETCHES is off.
  • Regression test direction (short): Build with -DENABLE_LIBRARIES=0 (the Fast test CMake line in ci/jobs/fast_test.py).

Medium: Empty String values are counted only when the column's character buffer is already allocated

  • Impact: Distinct count for '' changes with block layout. A block of only empty strings contributes nothing. A block that also contains a non-empty string counts '' as a distinct value. Apache DataSketches update(std::string) never records an empty string, so exchanged states disagree.
  • Anchor: AggregateFunctionUniqApacheHLL::add → HllSketchData::insertData → hll_sketch::update(const void *, size_t)
  • Trigger: Compare uniqApacheHLL on a String column of only '' with one that also contains a non-empty value (small enough to stay in coupon mode, so the count is exact).
  • Why defect: insertData forwards a zero length. update(const void *) returns only when the pointer is null, and still hashes a non-null zero-length pointer into a coupon (value is at least 1, so the coupon is not empty). ColumnString::getDataAt yields a null pointer only while chars has never been allocated (c_start == nullptr). Any non-empty value in that column allocates the buffer, so the empty row's pointer becomes non-null.
  • Fix direction (short): Skip size == 0 in insertData so an empty string is never recorded, matching hll_sketch::update(const std::string &).
  • Regression test direction (short): SELECT uniqApacheHLL(s) for [''] and for ['', 'a'] must return the same treatment of '', including when those rows arrive in separate blocks.

Coverage summary:

  • Scope reviewed: factory registration and parameter checks, type dispatch, HllSketchData insert/merge/serialize/deserialize, empty-state and lg_k < 7 fixes, DataSketches 5.2.0 HLL union backport (23bd9b07), and the four stateless tests.
  • Categories failed: optional-library link, empty-string hashing.
  • Categories passed: parameter bounds, rejected types, corrupt-state translation to CORRUPTED_DATA, empty-sketch serialization, merge resolution in [4, 21], HLL union KxQ rebuild (submodule patch), per-state ownership under normal aggregation (no shared mutable sketch).
  • Assumptions/limits: static review only; integer hashing was checked against the documented 8-byte zero-extension contract, not against update(uint32_t) sign-extension; std::llround above 2^63-1 and big-endian UUID byte order were not treated as confirmed defects.

CarlosFelipeOR added a commit to Altinity/clickhouse-regression that referenced this pull request Oct 1, 2026
uniqApacheHLL is an Antalya-only aggregate function (Altinity/ClickHouse#2398)
whose state is compatible with Apache DataSketches HLL. The suite reuses the
any checks for supported types and adds checks for rejected types, HLL
estimation mode, lg_k and HLL type parameters, empty strings, and reading an
external DataSketches state. Skipped on non-Antalya builds and before 26.6.

Snapshots are x86_64 only; aarch64 follows.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: CarlosFelipeOR <carlosfelipeor@gmail.com>
@CarlosFelipeOR

Copy link
Copy Markdown
Collaborator

I added uniqApacheHLL coverage to the clickhouse-regression aggregate_functions suite (57cff3f, 25030e1). This also clears the function_list failure in the regression job. One check fails on this PR's build: uniqApacheHLL throws on an all-NULL argument instead of returning 0.

SELECT uniq(NULL), uniqTheta(NULL);  -- 0  0
SELECT uniqApacheHLL(NULL);          -- Code: 43. Illegal type Nullable(Nothing) of argument for aggregate function uniqApacheHLL

The failing checks are /aggregate functions/part 1/uniqApacheHLL/NULL for all rows and /aggregate functions/part 3/state/uniqApacheHLLState/NULL for all rows.

AI analysis: for an all-NULL argument, the factory still calls the creator with Nullable(Nothing) before the Null combinator replaces it with nothing (AggregateFunctionNull.cpp:113). uniq and uniqTheta accept any type at that step. createAggregateFunctionUniqApacheHLL throws instead. Returning an instance for argument_type.onlyNull() before the final throw should fix it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants