Repository navigation
fix: Allow a StructType with no fields - #514
Merged
CurtHagenlocher merged 3 commits intoNov 27, 2026
Merged
Conversation
The Arrow format allows a struct (and a union) with no children, but NestedType's list constructor refused an empty list as if it were null, the IPC reader asserted that a struct field had children, and the C data interface exporter threw for a nested type with zero children. An empty field list is now accepted, the IPC reader builds a struct or union with no children from a field with none, and the C exporter exports n_children = 0 with a null children pointer. Round-trips through the IPC stream and file formats and the C data interface, as a column and inside a list, are covered by tests; interop with pyarrow 24 was checked by hand in both directions. Closes apache#513. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Empty unions still fail IPC deserialization when optional type IDs are omitted and C schema import when exported with an empty type-ID list.
2 open issues
What changed in this PR
This PR addresses #513 by allowing zero-field structs in Apache.Arrow, supporting representations such as empty Avro records and interoperability with other Arrow implementations.
Changes:
- Allow empty field collections for structs and unions while still rejecting null.
- Handle childless types in IPC deserialization and C schema export.
- Add empty-struct tests for validity, slicing, concatenation, and round-trips.
| File | Description |
|---|---|
test/Apache.Arrow.Tests/EmptyStructTests.cs |
Adds empty-struct behavior and interoperability tests, plus empty-union construction coverage. |
src/Apache.Arrow/Types/NestedType.cs |
Permits empty field collections and documents the behavior. |
src/Apache.Arrow/Ipc/MessageSerializer.cs |
Supplies empty child arrays when reading childless structs and unions. |
src/Apache.Arrow/C/CArrowSchemaExporter.cs |
Exports zero-child nested types with a null children pointer. |
Review effort: Balanced
Addresses review on apache#514: - CArrowSchemaImporter parsed a union's type-id list with a do/while, so the "+us:" / "+ud:" that the exporter writes for a union with no children failed with InvalidDataException. An empty list now imports. - The IPC reader passed a union's typeIds straight to UnionType, but the schema makes typeIds optional: without it, the ids in the type vector are the children's offsets. Reading a union without the vector threw ArgumentNullException, with or without children; it now defaults to 0..n-1. Tests: C schema round-trip of an empty union in both modes, IPC round-trip of an empty union column, and a hand-built schema with the typeIds vector omitted, with zero and two children. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Interop with pyarrow was only checked by hand. EmptyStructPythonTests runs it in the PythonNet collection, which CI runs against pyarrow: - a batch with struct<>, list<struct<>> and an int column, pyarrow to C# and C# to pyarrow through the C data interface (pyarrow validates with full=True and compares schema and values); - the same batch through the IPC stream format, written by each side and read by the other; - sparse_union<> and dense_union<> through the C data interface, both directions. All eight fail against main's source and pass with this change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What's Changed
The Arrow format allows a struct, or a union, with no children. pyarrow's
struct<>is an example. Apache.Arrow refused these in three places, and this PR fixes all three:NestedType: the list constructor treated an empty field list likenulland threwArgumentNullException("fields"). It now throws only fornull.StructTypeandUnionTypeare the only types that use this constructor.MessageSerializer): a field with no children haschildFields == null. TheStruct_andUnioncases now build the type with no children instead of asserting thatchildFieldsis non-null.CArrowSchemaExporter): a nested type with zero children is now exported asn_children = 0with a nullchildrenpointer, which the C data interface allows. It used to throwNotSupportedException.Because the type change also allows a union with no children, two union paths needed fixing as well (from review):
CArrowSchemaImporter): the empty type-id list that the exporter writes (+us:/+ud:) failed to import, because the parser always read at least one code.typeIdsis optional inSchema.fbs, and without it the ids are the children's offsets. Reading a union without the vector threwArgumentNullException, with or without children. It now defaults to0..n-1.The new
EmptyStructTestscover:typeIds, with zero and with two childrenEmptyStructPythonTests(in thePythonNetcollection, which CI runs against pyarrow) checks interop with pyarrow in both directions:struct<>,list<struct<>>and an int column through the C data interface, pyarrow to C# and C# to pyarrow (pyarrow validates withfull=Trueand compares schema and values)sparse_union<>anddense_union<>through the C data interface, both directionsAll eight fail against main's source and pass with this change (locally with pyarrow 24, on net8.0, net462 and net472).
Closes #513.
🤖 Generated with Claude Code