Skip to content

Commit

Permalink
apacheGH-41263: [C#][Integration] Ensure offset is considered in all …
Browse files Browse the repository at this point in the history
…branches of the bitmap comparison (apache#41264)

### Rationale for this change

The optimization for validity buffers was still failing after apache#41259 (sorry!).

### What changes are included in this PR?

There were still two problems:

- The offset of the actual array was not considered in the "optimized" branch
- When this offset *was* considered, it became clear that zero-length arrays were not going to work in that branch

### Are these changes tested?

I added the integration workflow to also run for C# additions. This might be a heavy CI job and I'm not sure if you want to keep it there (but running it is useful for this PR to ensure I actually fix things).

For future me (or maybe future others), the integration tests are pretty easy to check:

```
dotnet build
archery integration --run-c-data --with-csharp=true
```

### Are there any user-facing changes?

No.
* GitHub Issue: apache#41263

Authored-by: Dewey Dunnington <[email protected]>
Signed-off-by: Curt Hagenlocher <[email protected]>
  • Loading branch information
paleolimbot authored and tolleybot committed May 2, 2024
1 parent 11cd6e8 commit c584c7e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ on:
- 'js/**'
- 'cpp/**'
- 'java/**'
- 'csharp/**'
- 'format/**'
pull_request:
paths:
Expand All @@ -40,6 +41,7 @@ on:
- 'integration/**'
- 'js/**'
- 'cpp/**'
- 'csharp/**'
- 'java/**'
- 'format/**'

Expand Down
27 changes: 2 additions & 25 deletions csharp/test/Apache.Arrow.Tests/ArrowReaderVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,36 +497,13 @@ private void CompareValidityBuffer(int nullCount, int arrayLength, ArrowBuffer e
{
Assert.True(expectedValidityBuffer.Span.SequenceEqual(actualValidityBuffer.Span));
}
else if (actualValidityBuffer.IsEmpty)
else if (actualValidityBuffer.IsEmpty || expectedValidityBuffer.IsEmpty || arrayLength == 0)
{
Assert.True(nullCount == 0 || arrayLength == 0);
}
else if (expectedBufferOffset % 8 == 0 && expectedBufferOffset == actualBufferOffset)
{
int validityBitmapByteCount = BitUtility.ByteCount(arrayLength);
int byteOffset = BitUtility.ByteCount(expectedBufferOffset);
ReadOnlySpan<byte> expectedSpanPartial = expectedValidityBuffer.Span.Slice(byteOffset, validityBitmapByteCount - 1);
ReadOnlySpan<byte> actualSpanPartial = actualValidityBuffer.Span.Slice(0, validityBitmapByteCount - 1);

// Compare the first validityBitmapByteCount - 1 bytes
Assert.True(
expectedSpanPartial.SequenceEqual(actualSpanPartial),
string.Format("First {0} bytes of validity buffer do not match", validityBitmapByteCount - 1));

// Compare the last byte bitwise (because there is no guarantee about the value of
// bits outside the range [0, arrayLength])
ReadOnlySpan<byte> expectedSpanFull = expectedValidityBuffer.Span.Slice(byteOffset, validityBitmapByteCount);
ReadOnlySpan<byte> actualSpanFull = actualValidityBuffer.Span.Slice(0, validityBitmapByteCount);
for (int i = 8 * (validityBitmapByteCount - 1); i < arrayLength; i++)
{
Assert.True(
BitUtility.GetBit(expectedSpanFull, i) == BitUtility.GetBit(actualSpanFull, i),
string.Format("Bit at index {0}/{1} is not equal", i, arrayLength));
}
}
else
{
// Have to compare all values bitwise
// Compare all values bitwise
var expectedSpan = expectedValidityBuffer.Span;
var actualSpan = actualValidityBuffer.Span;
for (int i = 0; i < arrayLength; i++)
Expand Down

0 comments on commit c584c7e

Please sign in to comment.