Skip to content

Fix flaky test 04402_map_functions_lowcardinality - #108677

Merged
m-selmi merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-04402-map-lowcardinality-bucketed
Jul 9, 2026
Merged

m-selmi merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-04402-map-lowcardinality-bucketed

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

04402_map_functions_lowcardinality builds MergeTree tables with a Map(LowCardinality(String), String) column and reads the Map back to verify that CREATE TABLE AS preserves the column type and that CHECK TABLE passes. It does not check the Map key order.

CI randomizes map_serialization_version_for_zero_level_parts to with_buckets, which stores Map keys in hash-bucket order in zero-level parts instead of insertion order. Reading the Map back then yields a reordered Map and the output differs from the reference:

-key_1	{'attr_2':'value_2','attr_3':'value_3'}
+key_1	{'attr_3':'value_3','attr_2':'value_2'}

CI's own randomized-settings diagnosis confirmed the root cause: same randomized settings reproduce 190/190, no randomization passes 329/329, minimization isolates --map_serialization_version_for_zero_level_parts with_buckets.

Fix: pin map_serialization_version and map_serialization_version_for_zero_level_parts to basic on both tables so the stored order stays the insertion order. This is the same approach as the merged fixes for 03399_mapContains_functions (#101541) and 02030_function_mapContainsKeyLike (#101538).

CI report (master, arm_binary): https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=a115e2281161cc8955e2590afdd34cfd63084b1f&name_0=MasterCI&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29

Verification: 50/50 pass with full randomization after the fix; 30/30 fail before the fix when the culprit MergeTree settings are injected (exact reorder diff above).

The test creates MergeTree tables with a Map(LowCardinality(String), String)
column and reads the Map back to check that CREATE TABLE AS preserves the column
type and that CHECK TABLE passes. It does not check the Map key order.

CI randomizes map_serialization_version_for_zero_level_parts to 'with_buckets',
which stores Map keys in hash-bucket order in zero-level parts instead of
insertion order. Reading the Map back then yields a reordered Map
({'attr_3':'value_3','attr_2':'value_2'} instead of the inserted order), which
differs from the reference.

Pin map_serialization_version and map_serialization_version_for_zero_level_parts
to 'basic' on both tables so the stored order stays the insertion order. Same
approach as the merged fixes for 03399_mapContains_functions (ClickHouse#101541) and
02030_function_mapContainsKeyLike (ClickHouse#101538).

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

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. clickhouse-test --no-random-settings --merge-tree-settings "--map_serialization_version_for_zero_level_parts with_buckets --map_buckets_min_avg_size 1 --map_buckets_coefficient 1.92" --test-runs 30 04402_map_functions_lowcardinality → 30/30 FAIL. Also reproduced directly in clickhouse-local with those CREATE TABLE settings.
b Root cause explained? Yes. CI randomizes map_serialization_version_for_zero_level_parts to with_buckets, which stores Map keys in hash-bucket order in the zero-level part instead of insertion order. Reading the Map back yields {'attr_3':'value_3','attr_2':'value_2'} instead of the inserted {'attr_2':'value_2','attr_3':'value_3'}, so the output differs from .reference.
c Fix matches root cause? Yes. Pins map_serialization_version and map_serialization_version_for_zero_level_parts to basic on both tables so the stored order stays insertion order. Directly disables the bucketing that the randomizer turns on. Not a band-aid (no no-random-* tag, no assertion widening).
d Test intent preserved? Yes. The test checks that CREATE TABLE AS keeps the Map(LowCardinality(String), String) column type and that CHECK TABLE passes — neither depends on Map key order. Pinning serialization to basic only stabilizes the incidental key order; all type/CHECK assertions are unchanged.
e Both directions demonstrated? Yes. Without fix + culprit settings: 30/30 FAIL (exact reorder diff). With fix + full randomization: 50/50 PASS.
f Fix is general across code paths? N/A (flaky test setting fix, not a code bug).
g Fix generalizes across inputs? N/A (flaky test setting fix, not a code bug).
h Backward compatible? N/A (flaky test setting fix, not a code bug).
i Invariants and contracts preserved? N/A (flaky test setting fix, not a code bug).

Session id: cron:clickhouse-worker-slot-4:20260627-012200

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @Avogar — could you review this? It pins map_serialization_version/map_serialization_version_for_zero_level_parts to basic in 04402_map_functions_lowcardinality so randomized with_buckets serialization stops reordering Map keys by hash bucket (the test checks column type + CHECK TABLE, not key order). Same fix as the merged #101541 and #101538.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 27, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f6300c9]

Summary: ✅


AI Review

Summary

This PR stabilizes 04402_map_functions_lowcardinality by pinning map_serialization_version and map_serialization_version_for_zero_level_parts to basic on both MergeTree tables in the CREATE TABLE ... AS SELECT reproducer. The change matches the stated flake mechanism: randomized with_buckets serialization can make stored Map key order differ from the reference, while the test contract is about preserving Map(LowCardinality(String), String) and CHECK TABLE. I did not find review-blocking issues.

Missing context / blind spots
  • ⚠️ I could not rerun the stateless test locally because this checkout has no build* directory or clickhouse binary. The direct S3 PR report currently returns zero individual test results; the PR description's 50/50 pass and 30/30 fail reproduction are the available execution evidence.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 27, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.40% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.60% +0.00%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 425 line(s), 37 function(s) across 131 file(s) · Details

Top files
  • src/Functions/FunctionShowCertificate.cpp: 36 line(s), 2 function(s)
  • src/Backups/BackupEntriesCollector.cpp: 29 line(s), 2 function(s)
  • src/Functions/UserDefined/ExternalUserDefinedExecutableFunctionsLoader.cpp: 21 line(s), 1 function(s)
  • src/IO/S3/copyS3File.cpp: 13 line(s)
  • src/Parsers/parseFieldFromCastedLiteral.cpp: 11 line(s), 11 function(s)

Full report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — f6300c9

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (amd_asan_ubsan, db disk, distributed plan, sequential, 1/2) / Segmentation fault (STID 1760-4344) + Server died crash #108572 (ours, open)
Sync — CH Inc sync (private, not actionable)

The segfault is a pre-existing trunk crash in the MergeTree compact-part String size-stream read path (SerializationString::deserializeBinaryBulkWithSizeStream -> readBig -> SerializationNumber<UInt64>::deserializeBinaryBulk memcpy), reachable on a corrupt/desynced .size sub-stream. It is unrelated to this PR (which only pins map_serialization_version to basic in 04402_map_functions_lowcardinality.sql): the same signature appears in 2 unrelated PRs / 0 master in 30d. Owner = our open PR #108572, which guards exactly that path (appendStringSizesToColumnStringOffsets) so a corrupt size stream throws TOO_LARGE_STRING_SIZE instead of aborting.

Session id: 98f0cd33-ce9d-4a09-9be3-a4e86fb34a2b

@m-selmi m-selmi self-assigned this Jun 29, 2026
@m-selmi
m-selmi added this pull request to the merge queue Jul 9, 2026
Merged via the queue into ClickHouse:master with commit ddfae37 Jul 9, 2026
333 of 334 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 9, 2026
alexey-milovidov added a commit that referenced this pull request Jul 11, 2026
Clean merge, no conflicts; net PR diff unchanged (5 files, +89/-5).
Pulls in #108677, which fixes the 04402_map_functions_lowcardinality
flake behind the sole red required check.

Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…-map-lowcardinality-bucketed

Fix flaky test 04402_map_functions_lowcardinality
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Clean merge, no conflicts; net PR diff unchanged (5 files, +89/-5).
Pulls in ClickHouse#108677, which fixes the 04402_map_functions_lowcardinality
flake behind the sole red required check.

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

Labels

can be tested Allows running workflows for external contributors pr-ci 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