Skip to content

Conversation

@HashidaTKS
Copy link
Contributor

"Array.Values" always starts from first index of "ValueBuffer".
It should start from "Offset".

@github-actions
Copy link

@@ -0,0 +1,107 @@
using Apache.Arrow.Tests.Fixtures;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a license header?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your comment!
I added the license header.

{
var offsets = ValueOffsets;
var offset = Offset + index;
var offset = index;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this variable and use index directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified.

//Check all offset and length
for (var offset = 0; offset < totalLength; offset++)
{
for(var length = 1; length + offset <= totalLength; length++)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a space after for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I formatted all the changed files.

Add a license header
Format codes
public class ArrowArrayTests
{
[Fact]
public void SliceArray()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for testing Slice is that Slice changes Offset internally.

@HashidaTKS HashidaTKS requested a review from kou December 16, 2019 14:31
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.

+1

@eerhardt Do you want to review this too?

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int GetValueLength(int index)
{
var offsets = ValueOffsets;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this?
If we remove this, do we call public ReadOnlySpan<int> ValueOffsets twice?

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.

Overall this looks good. Just a few minor things to fix up.

var offset = Offset + index;

return offsets[offset + 1] - offsets[offset];
return ValueOffsets[index + 1] - ValueOffsets[index];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check the index for out of range?
Also - no need to call the property twice. Can cache the span in a local variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your comments.

  • I added a boundary check to this method and similar methods.
  • I modified to use local variable.

Assert.True(
baseArray.ValueOffsetsBuffer.Span.CastTo<int>().Slice(slicedArray.Offset, slicedArray.Length + 1)
.SequenceEqual(slicedArray.ValueOffsets));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we validate the Values as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added Values check and GetValue check

Fix GetDate
Add boundary check to GetValue and so on
Improve tests
@HashidaTKS
Copy link
Contributor Author

Looking back at the changes, I noticed Array.IsValid and DateArray.GetDate have the same issue and fixed them.

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int GetValueOffset(int index)
{
if (index < 0 || index >= Length)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting the value offset at index == Length is valid, right? That's how you can tell how long the last element is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I fixed it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting the value offset at index == Length is valid, right?

I think that this is invalid. Because it returns the offset of nonexistent value.

That's how you can tell how long the last element is.

I think that users should use GetValueLength() instead of computing value length by GetValueOffset() values. If advanced users want to compute by themselves, using ValueOffsets directly may be better.

Copy link
Contributor

@eerhardt eerhardt Dec 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more I look at this method, the less value I see in it. Maybe we should just remove the method all together and people can index into ValueOffsets directly. That’s all this method does.

It used to do the “Offset + index” calculation, but that is no longer necessary since the ValueOffsets does that for them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with removing this method.

Copy link
Contributor Author

@HashidaTKS HashidaTKS Dec 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with removing but I'm a little concerned about the impact on current users.
If we don't need to consider it, I'll remove this method.

Copy link
Member

@kou kou Dec 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about marking this method as "deprecated" in the next release, then remove this method in the future release?
(I'm not sure how to do this in C#. Documentation and warning message?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In .NET there is an [Obsolete] attribute you can apply to a method. Callers will receive a build time warning that the method is obsolete. We can add that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey. I'll add an [Obsolete] attribute.


return DateTimeOffset.FromUnixTimeMilliseconds(value * MillisecondsPerDay);
var value = GetValue(index);
return value.HasValue ?
Copy link
Contributor

@eerhardt eerhardt Dec 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it wouldn't be simpler to just write:

if (!value.HasValue)
{
    return value;  // or `return default;`
}

return DateTimeOffset.FromUnixTimeMilliseconds(value.Value * MillisecondsPerDay);

That way a reader doesn't have to reason about null as DateTimeOffset?

Copy link
Contributor Author

@HashidaTKS HashidaTKS Dec 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I fixed it.

@kou
Copy link
Member

kou commented Dec 25, 2019

I have a concern that GetValue() for the Length-th index: #6029 (comment)

But we can work on this as a follow-up task if it's needed. I'll merge this for now.

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.

3 participants