-
Notifications
You must be signed in to change notification settings - Fork 3.9k
ARROW-7514: [C#] Make GetValueOffset Obsolete #6333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ARROW-7514: [C#] Make GetValueOffset Obsolete #6333
Conversation
Make BinaryArray.GetValueOffset obsolete
|
@eerhardt do you have time to review? |
kou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update test code to suppress obsolete warnings?
eerhardt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update test code to suppress obsolete warnings?
👍
| public ReadOnlySpan<byte> Values => ValueBuffer.Span.CastTo<byte>(); | ||
|
|
||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| [Obsolete] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably best to add a message to the [Obsolete] attribute telling users what they should use instead.
Respond to feedback Add a message to Obsolete attributes Avoid Obsolete warnings
| public ReadOnlySpan<byte> Values => ValueBuffer.Span.CastTo<byte>(); | ||
|
|
||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| [Obsolete("This method has been deprecated. Please use ValueOffsets instead.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about ValueOffsets[index] instead of ValueOffsets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
I fixed it.
| if (index < 0 || index >= Length) | ||
| { | ||
| throw new ArgumentOutOfRangeException(nameof(index)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check is duplicated of the check in GetValueLength.
How about this?
var offset = ValueOffsets[index];
var length = GetValueLength(index);
return ValueBuffer.Span.Slice(offset, length);There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially, I implemented as below to avoid duplication of checks.
However, I thought the intention was a little difficult to understand, so it was implemented like current.
var length = GetValueLength(index);
return ValueBuffer.Span.Slice(ValueOffsets[index], length);Also, if we don't care about the type of exception, we can simply remove the check.
In that case, this method throws IndexOutOfRangeException which ValueOffsets[index] throws.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand.
How about adding a new helper private method to validate index:
private void ValidateIndex(int index)
{
if (index < 0 || index >= Length)
{
throw new ArgumentOutOfRangeException(nameof(index));
}
}and use it in GetValueLength and GetBytes?
ValidateIndex(index);
var offsets = ValueOffsets;
var offset = offsets[index];
var length = offsets[index + 1] - offset;
return ValueBuffer.Span.Slice(offset, length);@eerhardt What do you think about this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if we don't care about the type of exception, we can simply remove the check.
In that case, this method throws IndexOutOfRangeException which ValueOffsets[index] throws.
Typically we do care about the type of exception. Bubbling up an IndexOutOfRangeException looks like a bug in our library - similar to if you let something NullReferenceException. See the Design Guidelines for more info about this.
Instead, it is better to throw an ArgumentOutOfRangeException.
I think a helper like ValidateIndex makes the most sense. Also note that as currently written you are validating the index twice - once in GetBytes and then again when GetBytes calls GetValueLength. Not a huge issue, just something I noticed.
Change a message of Obsolete attributes
|
I'm going to merge this to move this PR forward. If we want to tweak the |
* 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>
BinaryArray.GetValueOffsetListArray.GetValueOffsetalready has the [Obsolete] attribute, so it is not changedGetValueOffsetin the product source codeAs a precaution, I added tests for
ValueOffsetsand left tests forGetValueOffset.