Skip to content

Commit

Permalink
apacheGH-41258: [C#][Integration] Fix comparison of sliced validity b…
Browse files Browse the repository at this point in the history
…uffers with non-zero offsets (apache#41259)

### Rationale for this change

After apache#41230 , the integration tests are failing on main .

### What changes are included in this PR?

The bit-by-bit comparison branch in the validity bitmap comparison is missing an offset on one side of the comparison. This PR adds that offset back in.

### Are these changes tested?

Via the integration test CI job.

### Are there any user-facing changes?

No
* GitHub Issue: apache#41258

Authored-by: Dewey Dunnington <[email protected]>
Signed-off-by: Dewey Dunnington <[email protected]>
  • Loading branch information
paleolimbot authored and vibhatha committed May 25, 2024
1 parent 789246a commit efe6a9d
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions csharp/test/Apache.Arrow.Tests/ArrowReaderVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private void CompareBinaryArrays<T>(BinaryArray actualArray)
Assert.Equal(expectedArray.Length, actualArray.Length);
Assert.Equal(expectedArray.NullCount, actualArray.NullCount);

CompareValidityBuffer(expectedArray.NullCount, _expectedArray.Length, expectedArray.NullBitmapBuffer, expectedArray.Offset, actualArray.NullBitmapBuffer);
CompareValidityBuffer(expectedArray.NullCount, _expectedArray.Length, expectedArray.NullBitmapBuffer, expectedArray.Offset, actualArray.NullBitmapBuffer, actualArray.Offset);

if (_strictCompare)
{
Expand Down Expand Up @@ -294,7 +294,7 @@ private void CompareVariadicArrays<T>(BinaryViewArray actualArray)
Assert.Equal(expectedArray.Offset, actualArray.Offset);
}

CompareValidityBuffer(expectedArray.NullCount, _expectedArray.Length, expectedArray.NullBitmapBuffer, expectedArray.Offset, actualArray.NullBitmapBuffer);
CompareValidityBuffer(expectedArray.NullCount, _expectedArray.Length, expectedArray.NullBitmapBuffer, expectedArray.Offset, actualArray.NullBitmapBuffer, actualArray.Offset);

Assert.True(expectedArray.Views.SequenceEqual(actualArray.Views));

Expand All @@ -318,7 +318,7 @@ private void CompareArrays(FixedSizeBinaryArray actualArray)
Assert.Equal(expectedArray.Length, actualArray.Length);
Assert.Equal(expectedArray.NullCount, actualArray.NullCount);

CompareValidityBuffer(expectedArray.NullCount, _expectedArray.Length, expectedArray.NullBitmapBuffer, expectedArray.Offset, actualArray.NullBitmapBuffer);
CompareValidityBuffer(expectedArray.NullCount, _expectedArray.Length, expectedArray.NullBitmapBuffer, expectedArray.Offset, actualArray.NullBitmapBuffer, actualArray.Offset);

if (_strictCompare)
{
Expand Down Expand Up @@ -347,7 +347,7 @@ private void CompareArrays<T>(PrimitiveArray<T> actualArray)
Assert.Equal(expectedArray.Length, actualArray.Length);
Assert.Equal(expectedArray.NullCount, actualArray.NullCount);

CompareValidityBuffer(expectedArray.NullCount, _expectedArray.Length, expectedArray.NullBitmapBuffer, expectedArray.Offset, actualArray.NullBitmapBuffer);
CompareValidityBuffer(expectedArray.NullCount, _expectedArray.Length, expectedArray.NullBitmapBuffer, expectedArray.Offset, actualArray.NullBitmapBuffer, actualArray.Offset);

if (_strictCompare)
{
Expand Down Expand Up @@ -379,7 +379,7 @@ private void CompareArrays(BooleanArray actualArray)
Assert.Equal(expectedArray.Length, actualArray.Length);
Assert.Equal(expectedArray.NullCount, actualArray.NullCount);

CompareValidityBuffer(expectedArray.NullCount, _expectedArray.Length, expectedArray.NullBitmapBuffer, expectedArray.Offset, actualArray.NullBitmapBuffer);
CompareValidityBuffer(expectedArray.NullCount, _expectedArray.Length, expectedArray.NullBitmapBuffer, expectedArray.Offset, actualArray.NullBitmapBuffer, actualArray.Offset);

if (_strictCompare)
{
Expand All @@ -406,7 +406,7 @@ private void CompareArrays(ListArray actualArray)
Assert.Equal(expectedArray.Length, actualArray.Length);
Assert.Equal(expectedArray.NullCount, actualArray.NullCount);

CompareValidityBuffer(expectedArray.NullCount, _expectedArray.Length, expectedArray.NullBitmapBuffer, expectedArray.Offset, actualArray.NullBitmapBuffer);
CompareValidityBuffer(expectedArray.NullCount, _expectedArray.Length, expectedArray.NullBitmapBuffer, expectedArray.Offset, actualArray.NullBitmapBuffer, actualArray.Offset);

if (_strictCompare)
{
Expand Down Expand Up @@ -442,7 +442,7 @@ private void CompareArrays(ListViewArray actualArray)
Assert.Equal(expectedArray.Length, actualArray.Length);
Assert.Equal(expectedArray.NullCount, actualArray.NullCount);

CompareValidityBuffer(expectedArray.NullCount, _expectedArray.Length, expectedArray.NullBitmapBuffer, expectedArray.Offset, actualArray.NullBitmapBuffer);
CompareValidityBuffer(expectedArray.NullCount, _expectedArray.Length, expectedArray.NullBitmapBuffer, expectedArray.Offset, actualArray.NullBitmapBuffer, actualArray.Offset);

if (_strictCompare)
{
Expand Down Expand Up @@ -475,15 +475,15 @@ private void CompareArrays(FixedSizeListArray actualArray)
Assert.Equal(expectedArray.Offset, actualArray.Offset);
}

CompareValidityBuffer(expectedArray.NullCount, _expectedArray.Length, expectedArray.NullBitmapBuffer, expectedArray.Offset, actualArray.NullBitmapBuffer);
CompareValidityBuffer(expectedArray.NullCount, _expectedArray.Length, expectedArray.NullBitmapBuffer, expectedArray.Offset, actualArray.NullBitmapBuffer, actualArray.Offset);

var listSize = ((FixedSizeListType)expectedArray.Data.DataType).ListSize;
var expectedValuesSlice = ArrowArrayFactory.Slice(
expectedArray.Values, expectedArray.Offset * listSize, expectedArray.Length * listSize);
actualArray.Values.Accept(new ArrayComparer(expectedValuesSlice, _strictCompare));
}

private void CompareValidityBuffer(int nullCount, int arrayLength, ArrowBuffer expectedValidityBuffer, int expectedBufferOffset, ArrowBuffer actualValidityBuffer)
private void CompareValidityBuffer(int nullCount, int arrayLength, ArrowBuffer expectedValidityBuffer, int expectedBufferOffset, ArrowBuffer actualValidityBuffer, int actualBufferOffset)
{
if (_strictCompare)
{
Expand All @@ -493,7 +493,7 @@ private void CompareValidityBuffer(int nullCount, int arrayLength, ArrowBuffer e
{
Assert.True(nullCount == 0 || arrayLength == 0);
}
else if (expectedBufferOffset % 8 == 0)
else if (expectedBufferOffset % 8 == 0 && expectedBufferOffset == actualBufferOffset)
{
int validityBitmapByteCount = BitUtility.ByteCount(arrayLength);
int byteOffset = BitUtility.ByteCount(expectedBufferOffset);
Expand Down Expand Up @@ -524,7 +524,7 @@ private void CompareValidityBuffer(int nullCount, int arrayLength, ArrowBuffer e
for (int i = 0; i < arrayLength; i++)
{
Assert.True(
BitUtility.GetBit(expectedSpan, expectedBufferOffset + i) == BitUtility.GetBit(actualSpan, i),
BitUtility.GetBit(expectedSpan, expectedBufferOffset + i) == BitUtility.GetBit(actualSpan, actualBufferOffset + i),
string.Format("Bit at index {0}/{1} is not equal", i, arrayLength));
}
}
Expand Down

0 comments on commit efe6a9d

Please sign in to comment.