Skip to content

[C#][Integration] Validity buffer comparison is dependent on zeroed final bits #40870

@paleolimbot

Description

@paleolimbot

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:

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions