CurtHagenlocher commented on code in PR #514:
URL: https://github.com/apache/arrow-dotnet/pull/514#discussion_r4713099761


##########
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:
   Fixed in 6bd2b06. The importer's type-id loop was a `do`/`while`, so it 
always parsed at least one code. It's now a `while`, so `+us:` and `+ud:` 
import as a union with no children. Added 
`AnEmptyUnionTypeRoundTripsThroughTheCDataInterface` for both modes, which 
export and then import the type.



##########
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:
   Fixed in 6bd2b06. When the vector is absent, the reader now defaults to the 
child offsets 0..n-1, per `Schema.fbs` ("By default ids in the type vector 
refer to the offsets in the children"). For a union with no children that is an 
empty array. This also fixes a union *with* children and no `typeIds`, which 
threw `ArgumentNullException` before this PR too. 
`AUnionWithoutTypeIds_TakesTheChildOffsets` builds a schema flatbuffer with the 
vector omitted, for 0 and 2 children, and reads it through 
`MessageSerializer.GetSchema`. I also added an IPC stream round-trip of an 
empty union column in both modes.



-- 
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]

Reply via email to