Skip to content

Commit

Permalink
ARROW-7514_make_getvalueoffset_obsolete
Browse files Browse the repository at this point in the history
Make BinaryArray.GetValueOffset obsolete
  • Loading branch information
Takashi Hashida committed Feb 1, 2020
1 parent bd08d0e commit 07d106c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 6 additions & 3 deletions csharp/src/Apache.Arrow/Arrays/BinaryArray.cs
Expand Up @@ -171,6 +171,7 @@ public TBuilder Clear()
public ReadOnlySpan<byte> Values => ValueBuffer.Span.CastTo<byte>();

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Obsolete]
public int GetValueOffset(int index)
{
if (index < 0 || index > Length)
Expand All @@ -193,10 +194,12 @@ public int GetValueLength(int index)

public ReadOnlySpan<byte> GetBytes(int index)
{
var offset = GetValueOffset(index);
var length = GetValueLength(index);
if (index < 0 || index >= Length)
{
throw new ArgumentOutOfRangeException(nameof(index));
}

return ValueBuffer.Span.Slice(offset, length);
return ValueBuffer.Span.Slice(ValueOffsets[index], GetValueLength(index));
}

}
Expand Down
6 changes: 6 additions & 0 deletions csharp/test/Apache.Arrow.Tests/ArrowArrayTests.cs
Expand Up @@ -46,6 +46,12 @@ public void ThrowsWhenGetValueAndOffsetIndexOutOfBounds()
Assert.Equal(2, array.GetValueOffset(2));
Assert.Throws<ArgumentOutOfRangeException>(() => array.GetValueOffset(3));

Assert.Throws<IndexOutOfRangeException>(() => array.ValueOffsets[-1]);
Assert.Equal(0, array.ValueOffsets[0]);
Assert.Equal(1, array.ValueOffsets[1]);
Assert.Equal(2, array.ValueOffsets[2]);
Assert.Throws<IndexOutOfRangeException>(() => array.ValueOffsets[3]);

}

[Fact]
Expand Down

0 comments on commit 07d106c

Please sign in to comment.