Commits


Zachary Gramana authored and Eric Erhardt committed 8b5a50a0b41
ARROW-6603: [C#] Adds ArrayBuilder API to support writing null values + BooleanArray null support Takes an alternative approach to completing [ARROW-6603](https://issues.apache.org/jira/browse/ARROW-6603) that is in-line with the current API and with other Arrow implementations. More specifically, this PR finishes the previously stubbed out implementation already in the codebase (e.g. uses the existing `NullBitmapBuffer`). This issue also closes out [ARROW-5708](https://issues.apache.org/jira/browse/ARROW-5708) by adding support for nulls to `BooleanArray` as well as some additional testing. The biggest challenge was finding a mechanism capable of supporting both nullable and non-nullable types with minimal changes to existing code. This was accomplished with the addition of the following builder interface member: ```csharp public interface IArrowArrayBuilder<T, out TArray, out TBuilder> : IArrowArrayBuilder<TArray, TBuilder> where TArray : IArrowArray where TBuilder : IArrowArrayBuilder<TArray> { ... TBuilder AppendNull(); ... } ``` The bulk of the implementation work focuses on adding the implementation of `AppendNull` to `PrimitiveArrayBuilder` and `Binary.BuilderBase`, and removing hardcoded `0`'s passed as arguments to `nullCount` in the `ArrayData` constructors. `BooleanArray` also receives a new member: `bool? GetValue(int index)`. This was chosen to so as to conform to the principle of least astonishment, on the assumption that users will be prefer consistency with `PrimativeArray`'s `T GetValue(int index)` method. `BooleanArray.GetBoolean` itself now wraps `GetValue` and is marked with the `Obsolete` attribute along with the following recommendation: > GetBoolean does not support null values. Use GetValue instead (which this method invokes internally). This PR adds three new tests to `ArrayBuilderTests`: * The first includes a number of `null` scenarios using `TestArrayBuilder<T,U>(...)`, which was extended to verify both `NullCount` and the null bitmap. * The second includes a `StringArray.Builder` scenario with mixed `null` and `string.Empty` values. I implemented it such that `string.Empty` is considered a valid value (so it increments `Offset` without adding any bytes to `ValueBuffer`. When `null` is passed to `Append` it will just invoke `AppendNull` internally instead. * The third adds `BooleanArray.Builder` tests both with and without nulls. And it adds three new tests to `ArrowArrayTests` which focus on the behavior of `Slice`: * `SlicePrimitiveArrayWithNulls` * `SliceBooleanArray` (which also tests both with and without nulls) * `SliceStringArrayWithNullsAndEmptyStrings` All 164 (existing + new) tests passed locally at the time this was submitted Closes #7032 from zgramana/master Authored-by: Zachary Gramana <zachary.gramana@ge.com> Signed-off-by: Eric Erhardt <eric.erhardt@microsoft.com>