Copilot commented on code in PR #514:
URL: https://github.com/apache/arrow-dotnet/pull/514#discussion_r4712914773
##########
src/Apache.Arrow/Ipc/MessageSerializer.cs:
##########
@@ -251,12 +250,12 @@ private static Types.IArrowType
GetFieldArrowType(Flatbuf.Field field, Field[] c
Flatbuf.FixedSizeList fixedSizeListMetadata =
field.Type<Flatbuf.FixedSizeList>().Value;
return new Types.FixedSizeListType(childFields[0],
fixedSizeListMetadata.ListSize);
case Flatbuf.Type.Struct_:
- Debug.Assert(childFields != null);
- return new Types.StructType(childFields);
+ // A struct or a union may have no children.
+ return new Types.StructType(childFields ??
System.Array.Empty<Field>());
case Flatbuf.Type.Union:
- Debug.Assert(childFields != null);
Flatbuf.Union unionMetadata =
field.Type<Flatbuf.Union>().Value;
- return new Types.UnionType(childFields,
unionMetadata.GetTypeIdsArray(), unionMetadata.Mode.ToArrow());
+ return new Types.UnionType(
+ childFields ?? System.Array.Empty<Field>(),
unionMetadata.GetTypeIdsArray(), unionMetadata.Mode.ToArrow());
Review Comment:
An empty union still fails IPC schema deserialization when its optional
`typeIds` vector is omitted (`format/Schema.fbs:156`). `GetTypeIdsArray()` then
returns null, and `UnionType` calls `typeIds.ToArray()`, throwing
`ArgumentNullException` despite the new empty-child fallback. Please supply
default child indices when the vector is absent (an empty array for a
zero-child union), and add a reader test with the vector omitted.
##########
src/Apache.Arrow/C/CArrowSchemaExporter.cs:
##########
@@ -280,7 +280,9 @@ private static long GetFlags(IArrowType datatype, bool
nullable = true)
numChildren = numFields;
if (numFields == 0)
{
- throw new NotSupportedException("Exporting nested data
types with zero children.");
+ // A struct or a union may have no children; the C data
interface allows a null children
+ // pointer when n_children is 0.
+ return null;
Review Comment:
This enables exporting empty unions, but importing the resulting schema
still fails. `FormatUnion` emits `+us:` or `+ud:` for an empty type-ID list,
while `CArrowSchemaImporter.cs:318–332` unconditionally executes its parsing
loop once and rejects the empty suffix with `InvalidDataException`. Please
update the importer to accept an empty type-ID list and add schema round-trip
tests for both union modes so the newly supported types can be exchanged in
both directions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]