Skip to content

Read Arrow structs with empty or repeated field names as unnamed Tuple - #125674

Merged
alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
JayPokale:arrow-struct-invalid-field-names
Oct 24, 2026
Merged

alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
JayPokale:arrow-struct-invalid-field-names

Conversation

@JayPokale

@JayPokale JayPokale commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #125141

Arrow allows struct fields with empty or repeated names, but a named Tuple cannot have them, so schema inference failed with Names of tuple elements cannot be empty. The native Arrow IPC reader now reads such a struct as an unnamed Tuple, and matches its fields by position everywhere it used their names:

  • SchemaConverter marks the struct with ArrowType::positional_fields when it parses the schema (using DataTypeTuple::hasValidElementNames, which exposes the existing check: non-empty, unique, not null), and fieldToCHType returns an unnamed Tuple for it.
  • RecordBatchDecoder takes the requested type of each field by position (structFieldHint), also when the requested Tuple is named, and identifies the field by its 1-based position in the dictionary-use paths (structFieldPath), so two equally named fields sharing a dictionary keep their own requested types.
  • The raw-byte rewrite after decoding (reinterpretRawBytes) matches the fields of an unnamed decoded Tuple by position too.
  • Structs with valid names, and maps, are unchanged.

The Apache Arrow library based reader (ArrowColumnToCHColumn, used by Arrow Flight, Delta Lake and Parquet) is not changed: it maps struct fields by name, including through Parquet column names, and still rejects such structs.

The test reads a small file written with pyarrow that has a struct with two empty field names, a struct with a repeated name, a normal struct and a map, in both the Arrow and ArrowStream formats, with inferred, unnamed and named requested types. It also checks a fixed_size_binary(16) field with an empty name requested as UInt128 in a named Tuple, and two fields named x that share one date32 dictionary, requested as Tuple(Int64, Date32) (the second one is still range-checked as Date32).

The top-level duplicate column names in the same arrow-testing file are a separate issue (#125140) and are not changed here.

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 read struct columns whose fields have empty or repeated names as an unnamed Tuple instead of failing schema inference.


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

Version info

  • Merged into: 26.11.1.715-master (included in 26.11 and later)

@clickhouse-gh clickhouse-gh Bot added comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). external Author is not a member of the ClickHouse organization labels Oct 13, 2026
@nihalzp nihalzp added the can be tested Allows running workflows for external contributors label Oct 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e884a5f]

Summary: ✅


AI Review

Summary

The PR reads Arrow structs with invalid tuple element names as unnamed Tuple values, preserving positional matching through decoding, dictionary uses, raw-byte conversion, and nested case-insensitive matching. The previously reported issues are addressed in the current code, with focused regression coverage. No new actionable findings.

Missing context / blind spots
  • ⚠️ The Arrow-enabled stateless jobs for commit e884a5f15e9ba7947a8c88f31e43fc3fbfa7fca6 are pending, and no local ClickHouse binary is available. A passing run of 05394_arrow_struct_invalid_field_names would confirm the runtime behavior; this review verified the implementation and regression cases from source.
Final Verdict

Status: ✅ Approve. No additional code changes requested.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Oct 14, 2026
…hints and dictionary uses

The library reader is left as it was: it also serves Parquet, where struct fields are mapped by name.
A struct with empty or repeated field names is read as an unnamed `Tuple`, which `prepareArrowColumnForCast`
matches by position, but `alignStructFieldNamesCaseInsensitive` stopped at it. A named struct nested inside then
kept its original field names, so with `input_format_arrow_case_insensitive_column_matching` its differently-cased
fields became default values. Descend by position there too.
@clickhouse-gh

clickhouse-gh Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e884a5f15 with master 0ddba953e (stripped binary size, per-symbol sizes and ThinLTO time; 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

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

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member

This is great, thank you!

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 24, 2026
Merged via the queue into ClickHouse:master with commit b29e69a Oct 24, 2026
178 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 24, 2026
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]>
cursor Bot pushed a commit that referenced this pull request Nov 19, 2026
Resolve the conflicts of the cherry-pick of #132416 to 26.10. The fix applies in full; the differences
from the original diff come only from master-only neighbours that 26.10 does not have:

- `RecordBatchDecoder.cpp`: 26.10 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.10 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.10 does not include it, directly or
  transitively.
- `RecordBatchDecoder.h`: no `[[nodiscard]]` on the changed declarations, as on the rest of the 26.10
  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: struct fields with empty names break schema inference

4 participants