adamreeve commented on code in PR #41144:
URL: https://github.com/apache/arrow/pull/41144#discussion_r1560404277


##########
csharp/src/Apache.Arrow/Arrays/ArrayData.cs:
##########
@@ -125,5 +155,69 @@ public ArrayData Clone(MemoryAllocator allocator = default)
                 Children?.Select(b => b.Clone(allocator))?.ToArray(),
                 Dictionary?.Clone(allocator));
         }
+
+        private int ComputeNullCount()
+        {
+            if (DataType.TypeId == ArrowTypeId.Union)
+            {
+                return ((UnionType)DataType).Mode switch
+                {
+                    UnionMode.Sparse => ComputeSparseUnionNullCount(),
+                    UnionMode.Dense => ComputeDenseUnionNullCount(),
+                    _ => throw new InvalidOperationException("unknown union 
mode in null count computation")
+                };
+            }
+
+            if (Buffers == null || Buffers.Length == 0 || Buffers[0].IsEmpty)
+            {
+                return 0;
+            }
+
+            // Note: Dictionary arrays may be logically null if there is a 
null in the dictionary values,
+            // but this isn't accounted for by the IArrowArray.IsNull 
implementation,
+            // so we maintain consistency with that behaviour here.

Review Comment:
   The C++ implementation actually has a separate `ComputeLogicalNullCount` 
method on `ArrayData` and `Array` that handles union arrays, dictionary arrays 
and run end encoded arrays, and there the `null_count` for union arrays always 
returns 0. The C# `UnionArray.IsValid` method depends on the `NullCount` value 
though, so I figured it made sense to compute the actual null count for union 
arrays.



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