Skip to content

Fix flaky test 03399_mapContains_functions - #101541

Merged
Avogar merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-03399-mapContains-flaky
Apr 7, 2026
Merged

Avogar merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-03399-mapContains-flaky

Conversation

@groeneai

@groeneai groeneai commented Apr 1, 2026 •

Copy link
Copy Markdown
Collaborator

Pin map_serialization_version and map_serialization_version_for_zero_level_parts to basic in the test's CREATE TABLE settings to prevent randomized with_buckets serialization from reordering Map keys by hash bucket.

The test verifies mapContainsValueLike / mapExtractValueLike function behavior, not Map serialization format. When CI randomizes map bucketing settings (with_buckets + constant strategy + min_avg_size=1), keys get stored in hash-bucket order instead of insertion order, causing the output to differ from the reference file.

Root cause: map_serialization_version_for_zero_level_parts='with_buckets' combined with map_buckets_strategy='constant' and map_buckets_min_avg_size=1 reorders Map keys by hash bucket in zero-level parts (directly from INSERT). Rows where the hash-bucket order differs from insertion order produce reversed keys (e.g., {'1-K2':'1-V2','1-K1':'1-V1'} instead of {'1-K1':'1-V1','1-K2':'1-V2'}).

CIDB evidence: 11 failures across 8 distinct PRs + master in 30 days.

Verification: 50/50 passes with full randomization after fix. Deterministic reproduction confirmed in both directions.

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):

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.4.1.586

Pin map_serialization_version and map_serialization_version_for_zero_level_parts
to 'basic' in the CREATE TABLE settings to prevent randomized 'with_buckets'
serialization from reordering Map keys by hash bucket.

The test verifies mapContainsValueLike/mapExtractValueLike function behavior,
not Map serialization format. When CI randomizes map bucketing settings
(with_buckets + constant strategy + min_avg_size=1), keys get reordered by
hash bucket, causing the output to differ from the reference file.

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

groeneai commented Apr 1, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR Validation Gate

Session: cron:clickhouse-ci-task-worker:20260401-174500

a) Deterministic repro? ✅ Yes.

CREATE TABLE t (id UInt32, map Map(String, String)) Engine=MergeTree() ORDER BY id
SETTINGS index_granularity=2, map_serialization_version='with_buckets',
  map_serialization_version_for_zero_level_parts='with_buckets',
  max_buckets_in_map=17, map_buckets_strategy='constant', map_buckets_min_avg_size=1;
INSERT INTO t VALUES (1, {'1-K1':'1-V1','1-K2':'1-V2'});
SELECT * FROM t;
-- Output: 1  {'1-K2':'1-V2','1-K1':'1-V1'}  (keys reversed)

b) Root cause explained? ✅ with_buckets Map serialization stores keys ordered by hash bucket (for lookup performance), not insertion order. When map_serialization_version_for_zero_level_parts='with_buckets' is randomized with map_buckets_strategy='constant' and map_buckets_min_avg_size=1, zero-level parts serialize keys in bucket order. For key pairs where the hash-bucket order differs from alphabetical order (e.g., 1-K1/1-K2, 6-K1/6-K2), the output shows reversed keys. Other key pairs (2-K1/2-K2, etc.) happen to hash into the correct order.

c) Fix matches root cause? ✅ Pins map_serialization_version='basic' and map_serialization_version_for_zero_level_parts='basic' in CREATE TABLE — directly prevents bucket-based reordering.

d) Test intent preserved? ✅ The test verifies mapContainsValueLike/mapExtractValueLike functions, not Map serialization. Pinning to basic doesn't affect function logic testing.

e) Both directions demonstrated? ✅

  • Without fix + trigger settings → rows 1, 6 show reversed keys
  • With fix → 50/50 passes with full CI randomization

@groeneai

groeneai commented Apr 1, 2026

Copy link
Copy Markdown
Collaborator Author

cc @Avogar — could you review this? It pins map serialization to 'basic' in the CREATE TABLE settings to prevent randomized bucketed Map serialization from reordering keys in the test output (the test verifies mapContainsValueLike/mapExtractValueLike, not serialization format).

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Apr 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ab326f7]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, azure, parallel) failure
03460_basic_projection_index FAIL cidb

AI Review

Summary

This PR makes 03399_mapContains_functions.sql deterministic by pinning map_serialization_version and map_serialization_version_for_zero_level_parts to basic for the test table, preventing randomized bucket-based key reordering from breaking expected output. The change is narrowly scoped to test setup and aligns with the stated intent (stabilize CI without altering function semantics). I did not find correctness, safety, or performance issues in the patch.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ➖
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Apr 1, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

@Avogar Avogar self-assigned this Apr 7, 2026
@Avogar
Avogar added this pull request to the merge queue Apr 7, 2026
Merged via the queue into ClickHouse:master with commit 820fa46 Apr 7, 2026
158 of 159 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 7, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Apr 7, 2026
Replace map_serialization_version settings pins in CREATE TABLE with
mapSort() wrapping in SELECT queries, making the test output
order-independent when CI randomizes map_serialization_version to
'with_buckets'. This aligns with the approach used in PRs ClickHouse#101541 and
ClickHouse#101887 per reviewer feedback.
pull Bot pushed a commit to Haofei/ClickHouse that referenced this pull request Jul 9, 2026
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]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
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]>
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.

5 participants