-
Notifications
You must be signed in to change notification settings - Fork 4.1k
[C#][Integration] Validity buffer comparison is dependent on zeroed final bits #40870
Description
Describe the bug, including details regarding any error messages, version, and platform.
I ran across this when implementing integration tests for nanoarrow (#39302), where I'd forgotten to zero the last few bits of each validity buffer when reading the testing integration JSON. This resulted in a failing check for nanoarrow -> C# because the check for validity buffer equivalence is just based on the bytes, not strictly the values of the relevant bits.
I will fix the zeroed final byte for the purposes of #39302; however, I wonder if it is worth updating the bit of code that does this comparison since I don't believe there's any guarantee about the values of bits outside the range [0, length] in the bitmap.
To double check this I at one point replaced:
arrow/csharp/test/Apache.Arrow.Tests/ArrowReaderVerifier.cs
Lines 438 to 441 in a9b2cc2
| Assert.True( | |
| expectedValidityBuffer.Span.Slice(0, validityBitmapByteCount).SequenceEqual(actualValidityBuffer.Span.Slice(0, validityBitmapByteCount)), | |
| "Validity buffers do not match."); | |
| } |
with
ReadOnlySpan<byte> expectedSpan = expectedValidityBuffer.Span.Slice(0, validityBitmapByteCount);
ReadOnlySpan<byte> actualSpan = actualValidityBuffer.Span.Slice(0, validityBitmapByteCount);
for (int i = 0; i < arrayLength; i++)
{
Assert.True(
BitUtility.GetBit(expectedSpan, i) == BitUtility.GetBit(actualSpan, i),
string.Format("bit at index {0}/{1} is not equal", i, arrayLength));
}I'm happy to give this PR a shot if that is an acceptable change!
Component(s)
C#, Integration