Repository navigation
fix: Reject struct arrays with different fields in ArrayDataConcatenator - #516
Open
dragonknightk wants to merge 1 commit into
Open
dragonknightk wants to merge 1 commit into
dragonknightk wants to merge 1 commit into
Conversation
## What's Changed `ArrowArrayConcatenator.Concatenate` checked only the type id and buffer count before concatenating struct arrays. It then combined the children by position and typed the result with the first input's `StructType`, so mismatched fields were dropped, mislabeled, or silently swapped. Now `Concatenate` throws `ArgumentException` when the struct inputs differ in field count, name, order or nullability, the same way it already does for `FixedSizeList` sizes and decimal scales. The check runs for every struct level, so structs nested in lists and other structs are covered. Child types are still checked when the children are concatenated. Field metadata is not compared. A map's entries struct is still not checked for field names or nullability, so maps that differ only there still concatenate. A struct inside a map value is checked like any other struct. Union arrays follow the same pattern and are not changed here. The new tests cover each kind of mismatch above, a third input that differs from the first two, and a mismatch in a struct nested in a list. Maps whose value nullability differs still concatenate, and maps whose value structs differ in field names are rejected. The mismatch cases fail on the old code. Closes issue 500 Signed-off-by: dragonknightk <37928252+dragonknightk@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Nested struct compatibility checks miss empty inputs, allowing concatenation to produce inconsistent parent and child schemas across lists, list views, and map values.
1 open issue
What changed in this PR
This PR addresses #500 by adding struct-field compatibility checks to array concatenation, preventing mismatched fields from being silently dropped or mislabeled.
Changes:
- Reject struct inputs with different field counts, names, order, or nullability.
- Preserve the map-entry name/nullability exemption while checking nested value structs.
- Add regression tests for field mismatches, later inputs, nested lists, and map behavior.
| File | Description |
|---|---|
| test/Apache.Arrow.Tests/ArrowArrayConcatenatorTests.cs | Adds struct mismatch and map compatibility regression tests. |
| src/Apache.Arrow/Arrays/ArrayDataConcatenator.cs | Adds struct-field validation and preserves the map-entry exemption. |
Review effort: Balanced
| } | ||
|
|
||
| ArrayData combinedChild = ConcatenateChildrenOrEmpty(children); | ||
| ArrayData combinedChild = ConcatenateChildrenOrEmpty(children, compareStructFieldNamesAndNullability: !(type is MapType)); |
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
ArrowArrayConcatenator.Concatenatechecked only the type id and buffer count before concatenating struct arrays. It then combined the children by position and typed the result with the first input'sStructType, so mismatched fields were dropped, mislabeled, or silently swapped.Now
ConcatenatethrowsArgumentExceptionwhen the struct inputs differ in field count, name, order or nullability, the same way it already does forFixedSizeListsizes and decimal scales. The check runs for every struct level, so structs nested in lists and other structs are covered. Child types are still checked when the children are concatenated. Field metadata is not compared. A map's entries struct is still not checked for field names or nullability, so maps that differ only there still concatenate. A struct inside a map value is checked like any other struct.Union arrays follow the same pattern and are not changed here.
The new tests cover each kind of mismatch above, a third input that differs from the first two, and a mismatch in a struct nested in a list. Maps whose value nullability differs still concatenate, and maps whose value structs differ in field names are rejected. The mismatch cases fail on the old code.
Closes #500.
AI Disclosure
Human-led contribution. Grok Bot, working for dragonknightk, assisted with this change, including the code, tests, and description. All submitted content was reviewed by a human before submission.