Skip to content

Allow repeated values in Arrow dictionaries - #125677

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
JayPokale:arrow-dictionary-duplicate-values
Oct 15, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
JayPokale:arrow-dictionary-duplicate-values

Conversation

@JayPokale

@JayPokale JayPokale commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #125139

The Arrow format doesn't require the values of a dictionary to be unique, but the native Arrow IPC reader rejected such files with Arrow dictionary contains duplicate values (for example generated_dictionary from the apache/arrow-testing integration corpus).

The check isn't needed by the reader: RecordBatchDecoder::decodeDictionary builds a LowCardinality with insertRangeFromDictionaryEncodedColumn, which inserts the values into the column's own unique dictionary and remaps the indexes, and the non-LowCardinality path gathers the values with IColumn::index. Both resolve repeated values (including repeated nulls) correctly. So the check is removed.

Tests:

  • 05395_arrow_dictionary_duplicate_values: a pyarrow-written file and stream with repeated string values and repeated nulls (top-level LowCardinality(Nullable(String))), repeated numbers (LowCardinality(Nullable(Int64))), and repeated values in a dictionary nested in a list (Array(Nullable(String))).
  • 04497_native_arrow_ipc_delta_dictionary_duplicate expected a delta dictionary that repeats a base value to be rejected; it now checks that the column is read correctly.
  • 04344_native_arrow_ipc_pruned_dictionary used a dictionary with a duplicate value as an example of a dictionary that fails to decode, to test that unrequested dictionaries are skipped. It now corrupts the dictionary's last string offset instead, so it still tests the same thing.

The Apache Arrow library based reader (ArrowColumnToCHColumn, used by Arrow Flight and Delta Lake) still rejects such dictionaries, because it shares the dictionary column with the LowCardinality result as is. That can be changed separately if needed.

Changelog category (leave one):

  • Improvement

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

The Arrow and ArrowStream input formats can read dictionary-encoded columns whose dictionary has repeated values, which the Arrow format allows.


Workflow [PR]
Sync PR [sync-upstream/pr/125677]

Version info

  • Merged into: 26.10.1.2451-master (included in 26.10 and later)

@clickhouse-gh clickhouse-gh Bot added the comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). label Oct 13, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 14, 2026
@alexey-milovidov alexey-milovidov self-assigned this Oct 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [629c7ee]

Summary: ✅


AI Review

Summary

PR #125677 allows repeated values, including repeated nulls, in Arrow and ArrowStream dictionaries by removing the uniqueness check. The existing decoder deduplicates LowCardinality keys and remaps indexes; nested dictionaries gather values directly. No actionable findings.

Missing context / blind spots
  • ⚠️ Runtime validation of head 629c7ee3060adff0ccbcd89b5a90c82666884039 remains pending in the targeted stateless CI job. Local execution was unavailable because this checkout has neither a ClickHouse binary nor PyArrow. All four changed regression tests passed 50 executions each under ASan/UBSan on preceding commit b4b75e3e9ad802cd1a31b941055d71434ed88f80 (report). A successful targeted run on the current head closes this gap.
Final Verdict

✅ Approve. No code changes requested; current-head CI should complete before merge.

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements external Author is not a member of the ClickHouse organization labels Oct 14, 2026
alexey-milovidov and others added 2 commits October 14, 2026 05:41
`02904_arrow_dictionary_indexes` still expected `INCORRECT_DATA` for a dictionary
with repeated values, which is now read. `04497_native_arrow_ipc_delta_dictionary_duplicate`
compared rows of two record batches in file order, but `clickhouse-local` with several
threads may output the chunks in a different order; read them with `max_threads = 1`.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125677&sha=8667522018aded3158f565a03a796afb148df782&name_0=PR
PR: ClickHouse#125677

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 629c7ee30 with master c4c9e46fb (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 55f3778c1; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 14 s compile time in total, 7 of them have a recent master baseline.

Job report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 15, 2026
Merged via the queue into ClickHouse:master with commit 28f5221 Oct 15, 2026
177 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 15, 2026
alexey-milovidov added a commit that referenced this pull request Oct 16, 2026
…e `05361_arrow_testing_corpus`

Master now checks negative value counts and sizes of Parquet column chunks in
`ReadManager` only for the columns whose data is read (see
`05331_parquet_v3_corrupt_column_chunk_sizes`). The eager check in
`Reader::prefilterAndInitRowGroups` added by this PR made that test fail,
because it rejected a file whose corrupted column is not read with `PREWHERE`.
Remove it in favor of the check from master.

After #125677, Arrow files with
dictionary-encoded columns from the corpus are read successfully, so update the
reference of `05361_arrow_testing_corpus`.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125134&sha=6f7f9f758f5282a512d993cb36abf144842c62d4&name_0=PR
PR: #125134

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 19, 2026
Resolve the conflicts of the cherry-pick of #132416 to 26.9. The fix applies in full; the differences
from the original diff come only from master-only neighbours that 26.9 does not have:

- `ArrowIPCBlockInputFormat.cpp`: 26.9 still checks that dictionary values are unique after registering
  them (master dropped the check in #125677). Keep the check and look the values up by the dictionary use,
  as the registry is now keyed by it.
- `RecordBatchDecoder.cpp`: 26.9 has no `TypeKind::RunEndEncoded` case in `collectDictionaryUses`
  (run-end encoding, #126207, is master-only), so there is no call to pass `below_union` to there.
  The struct case keeps the 26.9 helpers `tupleElementHint` / `childPath` (master renamed them in
  #125674) and passes `below_union` as the original change does.
- `RecordBatchDecoder.cpp`: include `base/scope_guard.h` for the two new `SCOPE_EXIT` uses. On master
  the include came with the big-endian reader (#126562); 26.9 does not include it, directly or
  transitively.
- `RecordBatchDecoder.h`: no `[[nodiscard]]` on the changed declarations, as on the rest of the 26.9
  file (master added them in #126158).

Co-authored-by: yakov <[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 comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). external Author is not a member of the ClickHouse organization pr-improvement Pull request with some product improvements 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.

Arrow: dictionaries with repeated values are rejected with Arrow dictionary contains duplicate values

3 participants