Skip to content

Conversation

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

github-actions bot commented Feb 1, 2020

@emkornfield
Copy link
Contributor

@eerhardt do you have time to review?

Copy link
Member

@kou kou left a 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?

Copy link
Contributor

@eerhardt eerhardt left a 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]
Copy link
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
Contributor Author

@kou @eerhardt

Thank you both!
I responded to feedback.

@HashidaTKS HashidaTKS requested review from eerhardt and kou February 4, 2020 03:11
public ReadOnlySpan<byte> Values => ValueBuffer.Span.CastTo<byte>();

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Obsolete("This method has been deprecated. Please use ValueOffsets instead.")]
Copy link
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
Contributor Author

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
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?

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

Copy link
Contributor Author

@HashidaTKS HashidaTKS Feb 4, 2020

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.

Copy link
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:

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?

Copy link
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
Contributor

eerhardt commented Feb 5, 2020

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.

@eerhardt eerhardt closed this in a1ba1cb Feb 5, 2020
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 free to 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