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 support for BinaryView in arrow_string::length #6359

Merged
merged 4 commits into from
Sep 10, 2024

Conversation

Omega359
Copy link
Contributor

@Omega359 Omega359 commented Sep 5, 2024

Which issue does this PR close?

Closes #6358

Rationale for this change

Adding additional functionality

What changes are included in this PR?

Code, test.

Are there any user-facing changes?

No.

@github-actions github-actions bot added the arrow Changes to the arrow crate label Sep 5, 2024
@@ -85,6 +85,14 @@ pub fn length(array: &dyn Array) -> Result<ArrayRef, ArrowError> {
DataType::FixedSizeBinary(len) | DataType::FixedSizeList(_, len) => Ok(Arc::new(
Int32Array::new(vec![*len; array.len()].into(), array.nulls().cloned()),
)),
DataType::BinaryView => {
let list = array.as_binary_view();
let v = list.views().iter().map(|v| *v as i32).collect::<Vec<_>>();
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @Omega359 -- I have a test suggestion but the code in this PR looks good.

Thank you for making it small and easy to review

@@ -224,6 +232,18 @@ mod tests {
length_binary_helper!(i64, Int64Array, length, value, result)
}

#[test]
fn length_test_binary_view() {
let value: Vec<&[u8]> = vec![b"zero", &[0xff, 0xf8], b"two"];
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a test value that has more than 12 bytes (which ends up running a different code path)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks again @Omega359

b"zero",
&[0xff, 0xf8],
b"two",
b"this is a longer string to test binary array with",
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

@alamb alamb merged commit 704f90b into apache:master Sep 10, 2024
17 checks passed
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.

Add support for BinaryView in arrow_string::length
2 participants