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

Add typed buffers to UnionArray (#3880) #3933

Merged
merged 4 commits into from
Mar 30, 2023

Conversation

tustvold
Copy link
Contributor

@tustvold tustvold commented Mar 24, 2023

Which issue does this PR close?

Part of #3880

Rationale for this change

It currently isn't possible to interact with a UnionArray's buffers in a type-safe way. This is at odds with the other array types, and causes issues migrating away from storing ArrayData under arrays.

What changes are included in this PR?

Are there any user-facing changes?

This changes the return type of UnionArray::value_offset to be correct

@github-actions github-actions bot added the arrow Changes to the arrow crate label Mar 24, 2023
if self.is_dense() {
self.data().buffers()[1].typed_data::<i32>()[self.offset() + index]
} else {
(self.offset() + index) as i32
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 can potentially overflow, so I opted to change value_offset to return usize as this is not only more correct, but is what most call-sites want anyway

@tustvold tustvold requested a review from viirya March 29, 2023 10:11
@viirya
Copy link
Member

viirya commented Mar 29, 2023

I'll review this today.

Copy link
Member

@viirya viirya 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 good to me. It is also more clear for UnionArray struct itself.

for (i, id) in expected_type_ids.iter().enumerate() {
assert_eq!(id, &array.type_id(i));
}

// Check offsets, sparse union should only have a single buffer, i.e. no offsets
assert_eq!(array.data().buffers().len(), 1);
Copy link
Member

Choose a reason for hiding this comment

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

👍

@tustvold tustvold merged commit 8d2f5dc into apache:master Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants