zgramana commented on a change in pull request #7032: URL: https://github.com/apache/arrow/pull/7032#discussion_r418382595
########## File path: csharp/src/Apache.Arrow/Arrays/PrimitiveArrayBuilder.cs ########## @@ -99,55 +105,75 @@ public abstract class PrimitiveArrayBuilder<T, TArray, TBuilder> : IArrowArrayBu { protected TBuilder Instance => this as TBuilder; protected ArrowBuffer.Builder<T> ValueBuffer { get; } + protected BooleanArray.Builder ValidityBuffer { get; } public int Length => ValueBuffer.Length; - - // TODO: Implement support for null values (null bitmaps) + protected int NullCount { get; set; } internal PrimitiveArrayBuilder() { ValueBuffer = new ArrowBuffer.Builder<T>(); + ValidityBuffer = new BooleanArray.Builder(); } public TBuilder Resize(int length) { ValueBuffer.Resize(length); + ValidityBuffer.Resize(length + 1); return Instance; } public TBuilder Reserve(int capacity) { ValueBuffer.Reserve(capacity); + ValidityBuffer.Reserve(capacity + 1); return Instance; } public TBuilder Append(T value) { ValueBuffer.Append(value); + ValidityBuffer.Append(true); return Instance; } public TBuilder Append(ReadOnlySpan<T> span) { + var len = ValueBuffer.Length; ValueBuffer.Append(span); + ValidityBuffer.AppendRange(Enumerable.Repeat(true, ValueBuffer.Length - len)); return Instance; } public TBuilder AppendRange(IEnumerable<T> values) { + var len = ValueBuffer.Length; ValueBuffer.AppendRange(values); + ValidityBuffer.AppendRange(Enumerable.Repeat(true, ValueBuffer.Length - len)); + return Instance; + } + + public TBuilder AppendNull() + { + ValidityBuffer.Append(false); + NullCount++; + // Need this until this is refactored to use Review comment: `PrimitiveArrayBuilder` sidesteps the offset buffer entirely. In doing so, we end up having to take-up space in the `ValueBuffer`, even when we have `null` values, in order to keep `Length` correct, since: ```csharp public int Length => ValueBuffer.Length; ``` This comment was perhaps an overly-terse was to note this. My assumption was that this builder would eventually be refactored to use an offset buffer as seen in `BuilderBase`. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org