zgramana commented on a change in pull request #7032:
URL: https://github.com/apache/arrow/pull/7032#discussion_r418388163
##########
File path: csharp/src/Apache.Arrow/Arrays/BooleanArray.cs
##########
@@ -153,17 +182,25 @@ private void CheckIndex(int index)
new[] { nullBitmapBuffer, valueBuffer }))
{ }
- public BooleanArray(ArrayData data)
+ public BooleanArray(ArrayData data)
: base(data)
{
data.EnsureDataType(ArrowTypeId.Boolean);
}
public override void Accept(IArrowArrayVisitor visitor) =>
Accept(this, visitor);
+ [Obsolete("GetBoolean does not support null values. Use GetValue
instead (which this method invokes internally).")]
public bool GetBoolean(int index)
{
- return BitUtility.GetBit(Values, index);
+ return GetValue(index).GetValueOrDefault();
+ }
+
+ public bool? GetValue(int index)
+ {
+ return BitUtility.GetBit(Nulls, Offset + index)
Review comment:
There is a unit test, and it was passing; however, the line of code
above is too simplistic and only handled the first byte/offsets [0..7]. The
proper line of code would be:
```csharp
return BitUtility.GetBit(Values, index + (Offset - (int)(Math.Floor(Offset /
8.0) * 8.0) ));
```
The addition of `Nulls` was an attempt to provide a convenience property
similar to `Values`, but by also properly incorporating `Offset` in the
`Span.Slice` range as it was previously ignored. I wanted to make have `Nulls`
work this way in order to keep this more complicated code in one place.
However, using `Nulls` and `Values` when working with a sliced `StringArray`
makes life trickier for the caller, and perhaps resulted in minutely worse
performance in common usage patterns, so I just removed `Nulls` and reverted
the change to `Values` and now use the `NullBitmapBuffer.Span` directly.
----------------------------------------------------------------
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:
[email protected]