Skip to content

Commit

Permalink
apacheGH-41302: [C#][Integration] Fix writing list and binary arrays …
Browse files Browse the repository at this point in the history
…with zero length offsets to IPC format (apache#41303)

### Rationale for this change

Fixes the integration test failures caused by apache#41230

### What changes are included in this PR?

Only try to access the offset values if the array length is non-zero when writing list and binary arrays to IPC format.

### Are these changes tested?

Yes, I've manually run the integration tests with C# and Java to verify they pass (when also including the changes from apache#41264), and also added new unit tests for this.

### Are there any user-facing changes?

This may also be a bug that affects users but it isn't in a released version.
* GitHub Issue: apache#41302

Authored-by: Adam Reeve <[email protected]>
Signed-off-by: Curt Hagenlocher <[email protected]>
  • Loading branch information
adamreeve authored and rok committed May 8, 2024
1 parent 4a68231 commit 06be8db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
18 changes: 14 additions & 4 deletions csharp/src/Apache.Arrow/Ipc/ArrowStreamWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,13 @@ public void Visit(ListArray array)
_buffers.Add(CreateBitmapBuffer(array.NullBitmapBuffer, array.Offset, array.Length));
_buffers.Add(CreateBuffer(GetZeroBasedValueOffsets(array.ValueOffsetsBuffer, array.Offset, array.Length)));

int valuesOffset = array.ValueOffsets[0];
int valuesLength = array.ValueOffsets[array.Length] - valuesOffset;
int valuesOffset = 0;
int valuesLength = 0;
if (array.Length > 0)
{
valuesOffset = array.ValueOffsets[0];
valuesLength = array.ValueOffsets[array.Length] - valuesOffset;
}

var values = array.Values;
if (valuesOffset > 0 || valuesLength < values.Length)
Expand Down Expand Up @@ -206,8 +211,13 @@ public void Visit(BinaryArray array)
_buffers.Add(CreateBitmapBuffer(array.NullBitmapBuffer, array.Offset, array.Length));
_buffers.Add(CreateBuffer(GetZeroBasedValueOffsets(array.ValueOffsetsBuffer, array.Offset, array.Length)));

int valuesOffset = array.ValueOffsets[0];
int valuesLength = array.ValueOffsets[array.Length] - valuesOffset;
int valuesOffset = 0;
int valuesLength = 0;
if (array.Length > 0)
{
valuesOffset = array.ValueOffsets[0];
valuesLength = array.ValueOffsets[array.Length] - valuesOffset;
}

_buffers.Add(CreateSlicedBuffer<byte>(array.ValueBuffer, valuesOffset, valuesLength));
}
Expand Down
12 changes: 0 additions & 12 deletions csharp/test/Apache.Arrow.Tests/ArrowFileWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,5 @@ public async Task WriteListArrayWithEmptyOffsets()

await ValidateRecordBatchFile(stream, recordBatch, strictCompare: false);
}

private static void Shuffle(int[] values, Random random)
{
var length = values.Length;
for (int i = 0; i < length - 1; ++i)
{
var j = random.Next(i, length);
var tmp = values[i];
values[i] = values[j];
values[j] = tmp;
}
}
}
}

0 comments on commit 06be8db

Please sign in to comment.