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

Added casting from Binary/LargeBinary to Utf8View #6592

Merged
merged 2 commits into from
Oct 24, 2024

Conversation

ngli-me
Copy link
Contributor

@ngli-me ngli-me commented Oct 20, 2024

Which issue does this PR close?

Closes #6531.

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Oct 20, 2024
Utf8View => {
let array = cast_binary_to_string::<i64>(array, cast_options)?;
Ok(Arc::new(StringViewArray::from(
cast_byte_container::<LargeUtf8Type, Utf8Type>(array.as_ref())?
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this could result in offset overflow, is this cast required?

Copy link
Contributor

Choose a reason for hiding this comment

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

I played around with this and found that StringViewArray::from works directly from a LargeStringArray and pushed a commit I think helps.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also made a PR to help document #6610

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.

Thank you @ngli-me and @tustvold 🙏

Utf8View => {
let array = cast_binary_to_string::<i64>(array, cast_options)?;
Ok(Arc::new(StringViewArray::from(
cast_byte_container::<LargeUtf8Type, Utf8Type>(array.as_ref())?
Copy link
Contributor

Choose a reason for hiding this comment

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

I played around with this and found that StringViewArray::from works directly from a LargeStringArray and pushed a commit I think helps.

assert!(can_cast_types(
binary_array.data_type(),
&DataType::BinaryView
));

let string_view_array = cast(&binary_array, &DataType::Utf8View).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

I double checked that this is invoked with both BinaryArray and LargeBinaryArray

@tustvold tustvold merged commit 1295b00 into apache:master Oct 24, 2024
26 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.

Support Binary --> Utf8View casting
3 participants