Skip to content

Fix flaky 04217_array_concat_json_extract_keys_index under bucketed Map serialization - #104629

Merged
Avogar merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-04217-map-bucket-randomization
May 13, 2026
Merged

Avogar merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-04217-map-bucket-randomization

Conversation

@groeneai

@groeneai groeneai commented May 11, 2026 •

Copy link
Copy Markdown
Collaborator

The stateless test 04217_array_concat_json_extract_keys_index fails on CI when the runner randomizes map_serialization_version_for_zero_level_parts = 'with_buckets' together with map_buckets_strategy = 'constant' and a small map_buckets_min_avg_size (observed culprit settings reported by --diagnose-random-settings on PR #104473 and PR #103016).

Under with_buckets serialization, Map entries are written to disk grouped by hash bucket, so iteration order during SELECT reflects bucket order rather than insertion order. The test's last query prints three Map(LowCardinality(String), String) columns via SELECT *, and the resource column shows up as {'job':'g','d':'e'} instead of {'d':'e','job':'g'}.

Fix by wrapping each Map column in mapSort so the rendered output is deterministic regardless of the underlying on-disk format. This is the idiomatic pattern used in 04060_coalescing_merge_tree_array_tuple_with_column_param.sql. The test still exercises every randomized serialization configuration — only the SELECT output is sorted, the WHERE clause and the arrayConcat(mapKeys(...)) index path that the test was originally added to cover (issue #88558 / PR #94515) are untouched.

Verified locally:

  • Original .sql + bucketed settings (with_buckets + constant + min_avg_size=1): resource column reorders, output differs from reference.
  • New .sql + same bucketed settings: mapSort produces {'d':'e','job':'g'} stably.
  • New .sql under the test runner with full randomization, 50/50 passes.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104473
Related PR comment: #104473 (comment)

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.5.1.610

…ap serialization

The test outputs three `Map(LowCardinality(String), String)` columns with
`SELECT *`. When CI randomizes
`map_serialization_version_for_zero_level_parts = 'with_buckets'` together
with `map_buckets_strategy = 'constant'` and a small
`map_buckets_min_avg_size`, `Map` entries are written to disk grouped by
hash bucket, so the iteration order reflects bucket order rather than
insertion order and the second column (`resource`) prints as
`{'job':'g','d':'e'}` instead of `{'d':'e','job':'g'}`.

Fix by wrapping each `Map` column in `mapSort` so the rendered output is
deterministic regardless of the underlying on-disk format. This is the
same idiomatic fix used in
`04060_coalescing_merge_tree_array_tuple_with_column_param.sql`. The test
still exercises every randomized serialization configuration: only the
`SELECT` output is sorted, the `WHERE` clause and the
`arrayConcat(mapKeys(...))` index path that the test was added to cover
(issue ClickHouse#88558 / PR ClickHouse#94515) are untouched.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104473
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation

  • (a) Deterministic reproduction: With map_serialization_version_for_zero_level_parts = 'with_buckets', map_buckets_strategy = 'constant', map_buckets_min_avg_size = 1 applied to the t_88558_map table, the resource column's SELECT * output reorders from {'d':'e','job':'g'} to {'job':'g','d':'e'} on every run.
  • (b) Root cause: with_buckets writes Map entries to disk grouped by hash bucket, so iteration order during SELECT reflects bucket order rather than insertion order. The first three queries print JSON-encoded strings (immutable), so they are unaffected — only the last query, which prints Map columns directly, observes the reorder.
  • (c) Fix matches root cause: mapSort makes the rendered output deterministic regardless of physical bucket layout. This is the same fix already used by tests/queries/0_stateless/04060_coalescing_merge_tree_array_tuple_with_column_param.sql for the identical class of randomization-induced flakiness.
  • (d) Test intent preserved: The WHERE clause and the arrayConcat(mapKeys(attribute), mapKeys(scope), mapKeys(resource)) index path that this test was originally added to cover (issue NOT_FOUND_COLUMN_IN_BLOCK (arrayConcat(JSONExtractKeys)) #88558 / PR Support multiple set index conditions over the same expression #94515) are completely untouched. Only the output formatting is normalized.
  • (e) Both directions verified locally:
    • Original .sql + bucketed settings → {'cluster':'b','c':'1'}\t{'job':'g','d':'e'}\t{} (FAIL vs reference).
    • New .sql + bucketed settings → {'c':'1','cluster':'b'}\t{'d':'e','job':'g'}\t{} (matches reference).
    • New .sql under the test runner with full randomization, --test-runs 50: 50/50 passes.
  • (f) Fix is general: mapSort produces a stable order for any bucket configuration the randomizer can pick (constant / sqrt / linear strategy, any max_buckets_in_map, any map_buckets_min_avg_size). Verified against three bucket configurations (min_avg_size=1, min_avg_size=2 max_buckets=90, min_avg_size=1 max_buckets=200) — all produce identical sorted output.

Session: cron:clickhouse-ci-task-worker:20260511-181500

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @alexey-milovidov @Avogar — could you review this? It pins the rendered output of the three Map columns via mapSort so the test stays deterministic when CI randomizes map_serialization_version_for_zero_level_parts = 'with_buckets'. Follows the same pattern as the prior 04060 fix; WHERE clause and arrayConcat(mapKeys(...)) index path are untouched.

Per @alexey-milovidov's directive on #104473 (comment).

@groeneai groeneai mentioned this pull request May 11, 2026
1 task done
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label May 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1885ec6]

Summary: ❌

job_name test_name status info comment
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/check_report_messages.py FAIL IGNORED

AI Review

Summary

This PR makes 04217_array_concat_json_extract_keys_index deterministic under randomized bucketed Map serialization by sorting each selected Map with mapSort before output comparison. The change is narrow, preserves the tested arrayConcat(mapKeys(...)) index predicate path, 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 ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label May 11, 2026
@Avogar Avogar self-assigned this May 13, 2026
@Avogar
Avogar added this pull request to the merge queue May 13, 2026
Merged via the queue into ClickHouse:master with commit d47ca00 May 13, 2026
163 of 165 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 May 13, 2026
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