You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "ngli-me (via GitHub)" <gi...@apache.org> on 2024/10/20 02:20:49 UTC

[PR] Added casting from Binary/LargeBinary to Utf8View [arrow-rs]

ngli-me opened a new pull request, #6592:
URL: https://github.com/apache/arrow-rs/pull/6592

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #6531.
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking change` label.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added casting from Binary/LargeBinary to Utf8View [arrow-rs]

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold merged PR #6592:
URL: https://github.com/apache/arrow-rs/pull/6592


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added casting from Binary/LargeBinary to Utf8View [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #6592:
URL: https://github.com/apache/arrow-rs/pull/6592#discussion_r1809011612


##########
arrow-cast/src/cast/mod.rs:
##########
@@ -1414,6 +1417,13 @@ pub fn cast_with_options(
                 cast_binary_to_fixed_size_binary::<i64>(array, *size, cast_options)
             }
             BinaryView => Ok(Arc::new(BinaryViewArray::from(array.as_binary::<i64>()))),
+            Utf8View => {
+                let array = cast_binary_to_string::<i64>(array, cast_options)?;
+                Ok(Arc::new(StringViewArray::from(
+                    cast_byte_container::<LargeUtf8Type, Utf8Type>(array.as_ref())?

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



##########
arrow-cast/src/cast/mod.rs:
##########
@@ -5368,14 +5378,25 @@ mod tests {
     {
         let binary_array = GenericBinaryArray::<O>::from_iter(VIEW_TEST_DATA);
 
+        assert!(can_cast_types(
+            binary_array.data_type(),
+            &DataType::Utf8View
+        ));
+
         assert!(can_cast_types(
             binary_array.data_type(),
             &DataType::BinaryView
         ));
 
+        let string_view_array = cast(&binary_array, &DataType::Utf8View).unwrap();

Review Comment:
   I double checked that this is invoked with both `BinaryArray` and `LargeBinaryArray`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added casting from Binary/LargeBinary to Utf8View [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #6592:
URL: https://github.com/apache/arrow-rs/pull/6592#discussion_r1809022903


##########
arrow-cast/src/cast/mod.rs:
##########
@@ -1414,6 +1417,13 @@ pub fn cast_with_options(
                 cast_binary_to_fixed_size_binary::<i64>(array, *size, cast_options)
             }
             BinaryView => Ok(Arc::new(BinaryViewArray::from(array.as_binary::<i64>()))),
+            Utf8View => {
+                let array = cast_binary_to_string::<i64>(array, cast_options)?;
+                Ok(Arc::new(StringViewArray::from(
+                    cast_byte_container::<LargeUtf8Type, Utf8Type>(array.as_ref())?

Review Comment:
   I also made a PR to help document https://github.com/apache/arrow-rs/pull/6610



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added casting from Binary/LargeBinary to Utf8View [arrow-rs]

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #6592:
URL: https://github.com/apache/arrow-rs/pull/6592#discussion_r1808269455


##########
arrow-cast/src/cast/mod.rs:
##########
@@ -1414,6 +1417,13 @@ pub fn cast_with_options(
                 cast_binary_to_fixed_size_binary::<i64>(array, *size, cast_options)
             }
             BinaryView => Ok(Arc::new(BinaryViewArray::from(array.as_binary::<i64>()))),
+            Utf8View => {
+                let array = cast_binary_to_string::<i64>(array, cast_options)?;
+                Ok(Arc::new(StringViewArray::from(
+                    cast_byte_container::<LargeUtf8Type, Utf8Type>(array.as_ref())?

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



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org