Repository navigation
Fix flaky test 02030_function_mapContainsKeyLike - #101538
Conversation
Wrap Map column output with mapSort() to make test output deterministic regardless of internal Map entry ordering. The test validates mapContainsKeyLike/mapExtractKeyLike function correctness via WHERE clause filtering — the Map column display in SELECT output is incidental. Under rare CI conditions, MergeTree may return Map entries in non-insertion order, causing result diffs. CIDB evidence: 5 result-differs failures in 60 days across 4 distinct PRs + master, all showing consistent Map key reversal (K1,K2 → K2,K1). Co-Authored-By: Claude Opus 4.6 <[email protected]>
Pre-PR Validation GateSession: a) Deterministic repro? b) Root cause explained? c) Fix matches root cause? d) Test intent preserved? e) Demonstrated in both directions? f) Fix is general, not a narrow patch? |
|
cc @Avogar — could you review this? It wraps Map column output with mapSort() in test 02030_function_mapContainsKeyLike to make the output deterministic — CIDB shows 5 rare result-differs failures in 60 days where MergeTree returns Map entries in reversed key order. |
|
Workflow [PR], commit [260087f] Summary: ✅ AI ReviewSummaryThis PR stabilizes ClickHouse Rules
Final Verdict
|
|
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. |
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]>
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]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
What this PR does
Fixes flaky test
02030_function_mapContainsKeyLikeby wrapping Map column output withmapSort()to produce deterministic output regardless of internal Map entry ordering.The problem: Under rare CI conditions, MergeTree returns Map entries in reversed order (e.g.,
{'K2':'V2','K1':'V1'}instead of{'K1':'V1','K2':'V2'}), causing test output to differ from the reference file.CIDB evidence: 5 result-differs failures across 60 days in 4 distinct PRs + 1 master hit. The only consistent setting across all failures is
max_insert_threads=3, but the exact trigger could not be isolated after 750+ targeted local reproduction attempts across multiple setting combinations.All failures show the same pattern: Map key-value pairs in MergeTree-stored columns are consistently reversed in all rows. Literal Maps (from
mapExtractKeyLike) are unaffected.The fix:
mapSort()normalizes Map entry order by sorting keys. This makes the test output deterministic without changing what the test validates — themapContainsKeyLikeandmapExtractKeyLikefunction correctness is tested through WHERE clause filtering and inline expressions, which are unaffected by this change.Verification: 100/100 passes with full randomization locally.
🤖 Generated with Claude Code
Version info
26.4.1.587