Skip to content
This repository was archived by the owner on Oct 21, 2024. It is now read-only.

Commit 07d106c

Browse files
author
Takashi Hashida
committed
ARROW-7514_make_getvalueoffset_obsolete
Make BinaryArray.GetValueOffset obsolete
1 parent bd08d0e commit 07d106c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

csharp/src/Apache.Arrow/Arrays/BinaryArray.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public BinaryArray(IArrowType dataType, int length,
171171
public ReadOnlySpan<byte> Values => ValueBuffer.Span.CastTo<byte>();
172172

173173
[MethodImpl(MethodImplOptions.AggressiveInlining)]
174+
[Obsolete]
174175
public int GetValueOffset(int index)
175176
{
176177
if (index < 0 || index > Length)
@@ -193,10 +194,12 @@ public int GetValueLength(int index)
193194

194195
public ReadOnlySpan<byte> GetBytes(int index)
195196
{
196-
var offset = GetValueOffset(index);
197-
var length = GetValueLength(index);
197+
if (index < 0 || index >= Length)
198+
{
199+
throw new ArgumentOutOfRangeException(nameof(index));
200+
}
198201

199-
return ValueBuffer.Span.Slice(offset, length);
202+
return ValueBuffer.Span.Slice(ValueOffsets[index], GetValueLength(index));
200203
}
201204

202205
}

csharp/test/Apache.Arrow.Tests/ArrowArrayTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ public void ThrowsWhenGetValueAndOffsetIndexOutOfBounds()
4646
Assert.Equal(2, array.GetValueOffset(2));
4747
Assert.Throws<ArgumentOutOfRangeException>(() => array.GetValueOffset(3));
4848

49+
Assert.Throws<IndexOutOfRangeException>(() => array.ValueOffsets[-1]);
50+
Assert.Equal(0, array.ValueOffsets[0]);
51+
Assert.Equal(1, array.ValueOffsets[1]);
52+
Assert.Equal(2, array.ValueOffsets[2]);
53+
Assert.Throws<IndexOutOfRangeException>(() => array.ValueOffsets[3]);
54+
4955
}
5056

5157
[Fact]

0 commit comments

Comments
 (0)