Skip to content

Commit 1c8ff91

Browse files
Takashi Hashidakszucs
authored andcommitted
ARROW-7514: [C#] Make GetValueOffset Obsolete
* Add an [Obsolete] attribute to `BinaryArray.GetValueOffset` * `ListArray.GetValueOffset` already has the [Obsolete] attribute, so it is not changed * Avoid using `GetValueOffset` in the product source code As a precaution, I added tests for `ValueOffsets` and left tests for `GetValueOffset`. Closes #6333 from HashidaTKS/ARROW-7514_make_getvalueoffset_obsolete and squashes the following commits: 1dbaf39 <Takashi Hashida> ARROW-7514_make_getvalueoffset_obsolete 92b14c0 <Takashi Hashida> ARROW-7514_make_getvalueoffset_obsolete 07d106c <Takashi Hashida> ARROW-7514_make_getvalueoffset_obsolete Authored-by: Takashi Hashida <t-hashida@amiya.co.jp> Signed-off-by: Eric Erhardt <eric.erhardt@microsoft.com>
1 parent eca2b6d commit 1c8ff91

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
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("This method has been deprecated. Please use ValueOffsets[index] instead.")]
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/src/Apache.Arrow/Arrays/ListArray.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private ListArray(ArrayData data, IArrowArray values) : base(data)
123123
public override void Accept(IArrowArrayVisitor visitor) => Accept(this, visitor);
124124

125125

126-
[Obsolete]
126+
[Obsolete("This method has been deprecated. Please use ValueOffsets[index] instead.")]
127127
public int GetValueOffset(int index)
128128
{
129129
if (index < 0 || index > Length)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,19 @@ public void ThrowsWhenGetValueAndOffsetIndexOutOfBounds()
4040
Assert.Equal(1, array.GetValueLength(1));
4141
Assert.Throws<ArgumentOutOfRangeException>(() => array.GetValueLength(2));
4242

43+
#pragma warning disable 618
4344
Assert.Throws<ArgumentOutOfRangeException>(() => array.GetValueOffset(-1));
4445
Assert.Equal(0, array.GetValueOffset(0));
4546
Assert.Equal(1, array.GetValueOffset(1));
4647
Assert.Equal(2, array.GetValueOffset(2));
4748
Assert.Throws<ArgumentOutOfRangeException>(() => array.GetValueOffset(3));
49+
#pragma warning restore 618
50+
51+
Assert.Throws<IndexOutOfRangeException>(() => array.ValueOffsets[-1]);
52+
Assert.Equal(0, array.ValueOffsets[0]);
53+
Assert.Equal(1, array.ValueOffsets[1]);
54+
Assert.Equal(2, array.ValueOffsets[2]);
55+
Assert.Throws<IndexOutOfRangeException>(() => array.ValueOffsets[3]);
4856

4957
}
5058

0 commit comments

Comments
 (0)