Skip to content

Fix flaky test 01550_create_map_type - #101887

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix/01550-create-map-type-flaky
Apr 7, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix/01550-create-map-type-flaky

Conversation

@groeneai

@groeneai groeneai commented Apr 6, 2026 •

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 to CHANGELOG.md):

...

What this PR does

With randomized map_serialization_version = with_buckets, Map keys may be stored in bucket order rather than insertion order. The test's WHERE a = map(...) comparison failed because the Map = operator compares internal binary representations — a stored bucketed map ≠ a literal basic-format map.

Instead of pinning serialization settings, uses mapSort() on both sides of the comparison to normalize key order, making the equality check order-independent while still allowing all serialization variants to be tested.

Version info

  • Merged into: 26.4.1.596

@groeneai

groeneai commented Apr 6, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR Validation Gate (session: cron:clickhouse-ci-task-worker:20260406-184500)

a) Deterministic repro: Yes — clickhouse-client --allow_merge_tree_settings --map_serialization_version with_buckets --map_serialization_version_for_zero_level_parts with_buckets --map_buckets_strategy constant --map_buckets_min_avg_size 1 then SELECT b FROM table_map WHERE a = map('name','lisi', 'gender', 'female') returns 0 rows (expected: gender).

b) Root cause: With bucketed serialization (strategy=constant, min_avg_size=1), even 2-key maps get bucketed. Keys are stored in bucket order (alphabetical: gender, name) instead of insertion order (name, gender). The Map = operator compares internal binary representations rather than logical semantics, so the stored bucketed map ≠ the literal basic-format map, causing WHERE to return 0 rows.

c) Fix matches root cause: Pins map_serialization_version = 'basic' on the one CREATE TABLE that uses WHERE a = map(...), preventing the representation mismatch. The underlying Map equality bug with bucketed serialization is a separate real bug (wrong query results) that should be tracked independently.

d) Test intent preserved: Yes — the test still exercises Map type creation, key access, equality filtering, aggregation, and type conversions. Only the serialization format is pinned to avoid the comparison bug.

e) Both directions: ✅ Without fix + CI settings → missing gender line (FAIL). With fix + CI settings → gender present (PASS). 50/50 randomized runs pass.

@groeneai

groeneai commented Apr 6, 2026

Copy link
Copy Markdown
Collaborator Author

cc @CurtizJ — could you review this? Pins map_serialization_version to basic on one MergeTree table in test 01550 that uses WHERE a = map(...) comparison. The equality operator returns wrong results with bucketed serialization (map_buckets_strategy=constant + map_buckets_min_avg_size=1).

@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, fix the test properly: allow different serializations, but compare up to the order of keys.

Use mapSort() to compare maps up to key order instead of pinning
map_serialization_version. With bucketed serialization, Map keys
may be stored in bucket order rather than insertion order, causing
direct equality (=) to return wrong results. mapSort() normalizes
both sides to the same key ordering before comparison.
@groeneai
groeneai force-pushed the fix/01550-create-map-type-flaky branch from 5f613e8 to 281529c Compare April 6, 2026 23:49
@groeneai

groeneai commented Apr 6, 2026

Copy link
Copy Markdown
Collaborator Author

@alexey-milovidov Updated. Replaced the map_serialization_version pinning with mapSort() on both sides of the comparison:

-- before (breaks when bucketed serialization reorders keys):
select b from table_map where a = map('name','lisi', 'gender', 'female');

-- after (normalizes key order before comparison):
select b from table_map where mapSort(a) = mapSort(map('name','lisi', 'gender', 'female'));

The CREATE TABLE is back to its original form — no pinned settings. All serialization variants are now allowed, and the comparison is order-independent.

Verified both directions locally:

  • Direct = with bucketed settings → 0 rows (broken)
  • mapSort() = mapSort() with bucketed settings → correct result
  • 50/50 randomized runs pass

(session: cron:clickhouse-ci-task-worker:20260406-234500)

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Apr 7, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Apr 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e8fa3e3]

Summary: ✅


AI Review

Summary

This PR updates tests/queries/0_stateless/01550_create_map_type.sql to make one Map equality assertion robust under randomized map_serialization_version (including with_buckets) by comparing mapSort(a) to mapSort(map(...)). The change is narrowly scoped, aligns with the stated flaky-test root cause, and looks correct.

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 7, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Apr 7, 2026
Merged via the queue into ClickHouse:master with commit 8db0f04 Apr 7, 2026
159 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 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.
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Apr 9, 2026
Use mapSort() to normalize Map key ordering in SELECT output.

The CI randomizer can set map_serialization_version='with_buckets'
on MergeTree tables. Bucketed serialization distributes Map keys
across hash buckets, which changes key display order on read. This
causes SELECT * on Map columns to produce output that doesn't match
the reference file.

PR ClickHouse#101887 already fixed the WHERE comparison (mapSort on both
sides). This extends the same approach to SELECT * queries and the
CAST expression that also display Map values.

Co-Authored-By: Claude Opus 4.6 <[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.

3 participants