Skip to content
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

fix(cpp): Fix offset handling in ViewArrayAs Range Helpers #702

Merged
merged 5 commits into from
Jan 8, 2025

Conversation

WillAyd
Copy link
Contributor

@WillAyd WillAyd commented Jan 7, 2025

closes #701

@@ -157,6 +158,7 @@ class ViewArrayAs {
array_view->buffer_views[1].data.data,
array_view->offset,
},
array_view->offset,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an easy fix but maybe not the API we want, since we are providing the offset to both the Range and the Get class template (?)

Copy link
Member

Choose a reason for hiding this comment

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

This seems like the right thing to put here (at least one of Range or Get need it?)

@@ -157,6 +158,7 @@ class ViewArrayAs {
array_view->buffer_views[1].data.data,
array_view->offset,
},
array_view->offset,
Copy link
Member

Choose a reason for hiding this comment

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

This seems like the right thing to put here (at least one of Range or Get need it?)

@@ -79,7 +80,7 @@ struct RandomAccessRange {
};

const_iterator begin() const { return {0, this}; }
const_iterator end() const { return {size, this}; }
const_iterator end() const { return {size - offset, this}; }
Copy link
Member

Choose a reason for hiding this comment

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

I would have expected this to be:

  const_iterator begin() const { return {offset, this}; }
  const_iterator end() const { return {offset + size, this}; }

...or to have it be [0, size] and to have the offset handled by range->get().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not quite what you asked for but I think I've simplified this a bit by taking the offset out of the Get class and making it so that the range bounds start at the offset and end at size

Comment on lines 227 to 232
ArrowStringView expected[] = {"baz"_asv, "qux"_asv};
int i = 0;
for (auto slot : nanoarrow::ViewArrayAsFixedSizeBytes(array.get(), FixedSize)) {
EXPECT_EQ(slot, expected[i]);
i++;
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you use ::testing::ElementsAre("baz"_asv, "qux"_asv)? (Not sure if the templates work for string views but they might)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah that's cool

@WillAyd
Copy link
Contributor Author

WillAyd commented Jan 7, 2025

Hmm I think I might be missing something simple with the offest. So when we have an array of {"foo", "bar", "baz", "qux"} and an offset of 2, does that mean that the length of the array is supposed to be reported as 2 as well, or is it still 4?

@paleolimbot
Copy link
Member

Hmm I think I might be missing something simple with the offest.

I think you also need to decrement the length (i.e., offset + length in your example should remain the same)

@WillAyd WillAyd changed the title fix(cpp): ViewArrayAsBytes and offset fix(cpp): Fix offset handling in ViewArrayAs Range Helpers Jan 7, 2025
Copy link
Member

@paleolimbot paleolimbot left a comment

Choose a reason for hiding this comment

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

This looks great...thank you!

@WillAyd WillAyd merged commit 7a80870 into apache:main Jan 8, 2025
36 checks passed
@WillAyd WillAyd deleted the offset-array-bug branch January 8, 2025 20:16
@WillAyd
Copy link
Contributor Author

WillAyd commented Jan 8, 2025

Awesome - thanks for the help on review

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.

How to iterate arrays with an offset? Possible ViewArrayAsBytes bug
2 participants