Skip to content

ARROW-7514: [C#] Make GetValueOffset Obsolete - #6333

Closed
HashidaTKS wants to merge 3 commits into
apache:masterfrom
HashidaTKS:ARROW-7514_make_getvalueoffset_obsolete
Closed

ARROW-7514: [C#] Make GetValueOffset Obsolete#6333
HashidaTKS wants to merge 3 commits into
apache:masterfrom
HashidaTKS:ARROW-7514_make_getvalueoffset_obsolete

Conversation

@HashidaTKS

Copy link
Copy Markdown
Contributor
  • 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.

Make BinaryArray.GetValueOffset obsolete
@github-actions

Copy link
Copy Markdown

@emkornfield

Copy link
Copy Markdown
Contributor

@eerhardt do you have time to review?

@koukou left a comment

Copy link
Copy Markdown
Member

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?

@eerhardteerhardt left a comment

Copy link
Copy Markdown
Contributor

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]

Copy link
Copy Markdown
Contributor

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
@HashidaTKS

Copy link
Copy Markdown
ContributorAuthor

@kou@eerhardt

Thank you both!
I responded to feedback.

kou
kou approved these changes Feb 4, 2020
public ReadOnlySpan<byte> Values => ValueBuffer.Span.CastTo<byte>();

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Obsolete("This method has been deprecated. Please use ValueOffsets instead.")]

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
ContributorAuthor

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));
}

Copy link
Copy Markdown
Member

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?

varoffset=ValueOffsets[index];varlength=GetValueLength(index);returnValueBuffer.Span.Slice(offset,length);

@HashidaTKSHashidaTKSFeb 4, 2020

Copy link
Copy Markdown
ContributorAuthor

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.

varlength=GetValueLength(index);returnValueBuffer.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.

Copy link
Copy Markdown
Member

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:

privatevoidValidateIndex(intindex){if(index<0||index>=Length){thrownewArgumentOutOfRangeException(nameof(index));}}

and use it in GetValueLength and GetBytes?

ValidateIndex(index);varoffsets=ValueOffsets;varoffset=offsets[index];varlength=offsets[index+1]-offset;returnValueBuffer.Span.Slice(offset,length);

@eerhardt What do you think about this case?

Copy link
Copy Markdown
Contributor

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
@eerhardt

Copy link
Copy Markdown
Contributor

I'm going to merge this to move this PR forward. If we want to tweak the GetBytes implementation separately, I think we can do that in a separate PR.

kszucs pushed a commit that referenced this pull request Feb 7, 2020
* 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>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@HashidaTKS@emkornfield@eerhardt@kou