You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2023/01/17 08:40:16 UTC

[GitHub] [arrow-rs] viirya opened a new pull request, #3542: Enable casting between Utf8/LargeUtf8 and Binary/LargeBinary

viirya opened a new pull request, #3542:
URL: https://github.com/apache/arrow-rs/pull/3542

   # 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 #1179.
   
   # 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


[GitHub] [arrow-rs] viirya commented on a diff in pull request #3542: Enable casting between Utf8/LargeUtf8 and Binary/LargeBinary

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


##########
arrow-cast/src/cast.rs:
##########
@@ -3460,39 +3460,41 @@ fn cast_list_inner<OffsetSize: OffsetSizeTrait>(
     Ok(Arc::new(list) as ArrayRef)
 }
 
-/// Helper function to cast from `Utf8` to `LargeUtf8` and vice versa. If the `LargeUtf8` is too large for
-/// a `Utf8` array it will return an Error.
-fn cast_str_container<OffsetSizeFrom, OffsetSizeTo>(
-    array: &dyn Array,
-) -> Result<ArrayRef, ArrowError>
+/// Helper function to cast from one `ByteArrayType` to another and vice versa.
+/// If the target one (e.g., `LargeUtf8`) is too large for the source array it will return an Error.
+fn cast_byte_container<FROM, TO>(array: &dyn Array) -> Result<ArrayRef, ArrowError>

Review Comment:
   For above two cases, I changed it to do a `From` conversion first (metadata one, so should be quick), then do real cast (`cast_byte_container`) between same native types. So now this function restricts the input and output native types to be the same.



-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3542: Enable casting between Utf8/LargeUtf8 and Binary/LargeBinary

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


##########
arrow-cast/src/cast.rs:
##########
@@ -3460,39 +3460,41 @@ fn cast_list_inner<OffsetSize: OffsetSizeTrait>(
     Ok(Arc::new(list) as ArrayRef)
 }
 
-/// Helper function to cast from `Utf8` to `LargeUtf8` and vice versa. If the `LargeUtf8` is too large for
-/// a `Utf8` array it will return an Error.
-fn cast_str_container<OffsetSizeFrom, OffsetSizeTo>(
-    array: &dyn Array,
-) -> Result<ArrayRef, ArrowError>
+/// Helper function to cast from one `ByteArrayType` to another and vice versa.
+/// If the target one (e.g., `LargeUtf8`) is too large for the source array it will return an Error.
+fn cast_byte_container<FROM, TO>(array: &dyn Array) -> Result<ArrayRef, ArrowError>

Review Comment:
   For this method to be sound I think it needs to restrict the input and output native types to be the same.
   
   Something like
   
   ```
   fn cast_byte_container<FROM, TO, N>(array: &dyn Array) -> Result<ArrayRef, ArrowError>
       FROM: ByteArrayType<Native = N>,
       TO: ByteArrayType<Native = N>,
       FROM::Offset: OffsetSizeTrait + ToPrimitive,
       TO::Offset: OffsetSizeTrait + NumCast + ArrowNativeType,
   ```
   
   Perhaps we could also rename it to be something like `cast_byte_offsets` :thinking: 



-- 
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


[GitHub] [arrow-rs] viirya commented on a diff in pull request #3542: Enable casting between Utf8/LargeUtf8 and Binary/LargeBinary

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


##########
arrow-cast/src/cast.rs:
##########
@@ -3460,39 +3460,41 @@ fn cast_list_inner<OffsetSize: OffsetSizeTrait>(
     Ok(Arc::new(list) as ArrayRef)
 }
 
-/// Helper function to cast from `Utf8` to `LargeUtf8` and vice versa. If the `LargeUtf8` is too large for
-/// a `Utf8` array it will return an Error.
-fn cast_str_container<OffsetSizeFrom, OffsetSizeTo>(
-    array: &dyn Array,
-) -> Result<ArrayRef, ArrowError>
+/// Helper function to cast from one `ByteArrayType` to another and vice versa.
+/// If the target one (e.g., `LargeUtf8`) is too large for the source array it will return an Error.
+fn cast_byte_container<FROM, TO>(array: &dyn Array) -> Result<ArrayRef, ArrowError>

Review Comment:
   `cast_byte_container` is used for Utf8 -> Binary too. As this is internal function, we just need not to use it for Binary -> Utf8.



-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3542: Enable casting between Utf8/LargeUtf8 and Binary/LargeBinary

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


##########
arrow-cast/src/cast.rs:
##########
@@ -3460,39 +3460,41 @@ fn cast_list_inner<OffsetSize: OffsetSizeTrait>(
     Ok(Arc::new(list) as ArrayRef)
 }
 
-/// Helper function to cast from `Utf8` to `LargeUtf8` and vice versa. If the `LargeUtf8` is too large for
-/// a `Utf8` array it will return an Error.
-fn cast_str_container<OffsetSizeFrom, OffsetSizeTo>(
-    array: &dyn Array,
-) -> Result<ArrayRef, ArrowError>
+/// Helper function to cast from one `ByteArrayType` to another and vice versa.
+/// If the target one (e.g., `LargeUtf8`) is too large for the source array it will return an Error.
+fn cast_byte_container<FROM, TO>(array: &dyn Array) -> Result<ArrayRef, ArrowError>

Review Comment:
   > Utf8 -> Binary too
   
   That seems unfortunate, as it will re-encode the offsets for no reason. Can we just use the `From` conversion for that case? It should be metadata only?
   
   Edit: It appears we don't have such conversions, one sec



-- 
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


[GitHub] [arrow-rs] ursabot commented on pull request #3542: Enable casting between Utf8/LargeUtf8 and Binary/LargeBinary

Posted by "ursabot (via GitHub)" <gi...@apache.org>.
ursabot commented on PR #3542:
URL: https://github.com/apache/arrow-rs/pull/3542#issuecomment-1403245625

   Benchmark runs are scheduled for baseline = d938cd9bf621c9bf3c3bd9e33c4c0a5eb4060534 and contender = bf21ad91b0603dc935158b40c4f940c24be32f82. bf21ad91b0603dc935158b40c4f940c24be32f82 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/48cbfd2dc3774fd6936873804e3382dd...d9b468d6f91a40ac9417a0ae9ba49465/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/845c636f7bde44b2a4a171e2a8546cc8...9ed588b6486f4536bb38e2e47c608145/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/185793d1aded4222b8e8da34555a0c4a...cecab770671d4985b652d459ba1c56ac/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/241a886abcad4e59a9dc922b7351c928...2cce84fa5d39404d87b519156a0a72e1/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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


[GitHub] [arrow-rs] viirya merged pull request #3542: Enable casting between Utf8/LargeUtf8 and Binary/LargeBinary

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


-- 
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


[GitHub] [arrow-rs] viirya commented on a diff in pull request #3542: Enable casting between Utf8/LargeUtf8 and Binary/LargeBinary

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


##########
arrow-cast/src/cast.rs:
##########
@@ -3460,39 +3460,41 @@ fn cast_list_inner<OffsetSize: OffsetSizeTrait>(
     Ok(Arc::new(list) as ArrayRef)
 }
 
-/// Helper function to cast from `Utf8` to `LargeUtf8` and vice versa. If the `LargeUtf8` is too large for
-/// a `Utf8` array it will return an Error.
-fn cast_str_container<OffsetSizeFrom, OffsetSizeTo>(
-    array: &dyn Array,
-) -> Result<ArrayRef, ArrowError>
+/// Helper function to cast from one `ByteArrayType` to another and vice versa.
+/// If the target one (e.g., `LargeUtf8`) is too large for the source array it will return an Error.
+fn cast_byte_container<FROM, TO>(array: &dyn Array) -> Result<ArrayRef, ArrowError>

Review Comment:
   We can merge #3592 now. After that, I can replace Utf8 -> Binary/LargeUtf8 -> LargeBinary with it.



-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3542: Enable casting between Utf8/LargeUtf8 and Binary/LargeBinary

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


##########
arrow-cast/src/cast.rs:
##########
@@ -3460,39 +3460,41 @@ fn cast_list_inner<OffsetSize: OffsetSizeTrait>(
     Ok(Arc::new(list) as ArrayRef)
 }
 
-/// Helper function to cast from `Utf8` to `LargeUtf8` and vice versa. If the `LargeUtf8` is too large for
-/// a `Utf8` array it will return an Error.
-fn cast_str_container<OffsetSizeFrom, OffsetSizeTo>(
-    array: &dyn Array,
-) -> Result<ArrayRef, ArrowError>
+/// Helper function to cast from one `ByteArrayType` to another and vice versa.
+/// If the target one (e.g., `LargeUtf8`) is too large for the source array it will return an Error.
+fn cast_byte_container<FROM, TO>(array: &dyn Array) -> Result<ArrayRef, ArrowError>
 where
-    OffsetSizeFrom: OffsetSizeTrait + ToPrimitive,
-    OffsetSizeTo: OffsetSizeTrait + NumCast + ArrowNativeType,
+    FROM: ByteArrayType,
+    TO: ByteArrayType,
+    FROM::Offset: OffsetSizeTrait + ToPrimitive,
+    TO::Offset: OffsetSizeTrait + NumCast + ArrowNativeType,

Review Comment:
   ```suggestion
       TO::Offset: OffsetSizeTrait + NumCast,
   ```
   I think ArrowNativeType is implied by OffsetSizeTrait



-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3542: Enable casting between Utf8/LargeUtf8 and Binary/LargeBinary

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


##########
arrow-cast/src/cast.rs:
##########
@@ -3460,39 +3460,41 @@ fn cast_list_inner<OffsetSize: OffsetSizeTrait>(
     Ok(Arc::new(list) as ArrayRef)
 }
 
-/// Helper function to cast from `Utf8` to `LargeUtf8` and vice versa. If the `LargeUtf8` is too large for
-/// a `Utf8` array it will return an Error.
-fn cast_str_container<OffsetSizeFrom, OffsetSizeTo>(
-    array: &dyn Array,
-) -> Result<ArrayRef, ArrowError>
+/// Helper function to cast from one `ByteArrayType` to another and vice versa.
+/// If the target one (e.g., `LargeUtf8`) is too large for the source array it will return an Error.
+fn cast_byte_container<FROM, TO>(array: &dyn Array) -> Result<ArrayRef, ArrowError>

Review Comment:
   > Utf8 -> Binary too
   
   That seems unfortunate, as it will re-encode the offsets for no reason. Can we just use the `From` conversion for that case? It should be metadata only?



-- 
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


[GitHub] [arrow-rs] viirya commented on a diff in pull request #3542: Enable casting between Utf8/LargeUtf8 and Binary/LargeBinary

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


##########
arrow-cast/src/cast.rs:
##########
@@ -3460,39 +3460,41 @@ fn cast_list_inner<OffsetSize: OffsetSizeTrait>(
     Ok(Arc::new(list) as ArrayRef)
 }
 
-/// Helper function to cast from `Utf8` to `LargeUtf8` and vice versa. If the `LargeUtf8` is too large for
-/// a `Utf8` array it will return an Error.
-fn cast_str_container<OffsetSizeFrom, OffsetSizeTo>(
-    array: &dyn Array,
-) -> Result<ArrayRef, ArrowError>
+/// Helper function to cast from one `ByteArrayType` to another and vice versa.
+/// If the target one (e.g., `LargeUtf8`) is too large for the source array it will return an Error.
+fn cast_byte_container<FROM, TO>(array: &dyn Array) -> Result<ArrayRef, ArrowError>

Review Comment:
   It uses `From` conversion for Utf8 -> Binary and LargeUtf8 -> LargeBinary now. Note that due to Utf8 -> LargeBinary and LargeUtf8 -> Binary, we still cannot ask same native types for `cast_byte_container`. But I think this is minor.



-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3542: Enable casting between Utf8/LargeUtf8 and Binary/LargeBinary

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


##########
arrow-cast/src/cast.rs:
##########
@@ -3460,39 +3460,41 @@ fn cast_list_inner<OffsetSize: OffsetSizeTrait>(
     Ok(Arc::new(list) as ArrayRef)
 }
 
-/// Helper function to cast from `Utf8` to `LargeUtf8` and vice versa. If the `LargeUtf8` is too large for
-/// a `Utf8` array it will return an Error.
-fn cast_str_container<OffsetSizeFrom, OffsetSizeTo>(
-    array: &dyn Array,
-) -> Result<ArrayRef, ArrowError>
+/// Helper function to cast from one `ByteArrayType` to another and vice versa.
+/// If the target one (e.g., `LargeUtf8`) is too large for the source array it will return an Error.
+fn cast_byte_container<FROM, TO>(array: &dyn Array) -> Result<ArrayRef, ArrowError>

Review Comment:
   > Utf8 -> Binary too
   
   That seems unfortunate, as it will re-encode the offsets for no reason. Can we just use the `From` conversion for that case? It should be metadata only?
   
   Edit: It appears we don't have such conversions, one sec
   
   Edit Edit: https://github.com/apache/arrow-rs/pull/3592



-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3542: Enable casting between Utf8/LargeUtf8 and Binary/LargeBinary

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


##########
arrow-cast/src/cast.rs:
##########
@@ -3460,39 +3460,41 @@ fn cast_list_inner<OffsetSize: OffsetSizeTrait>(
     Ok(Arc::new(list) as ArrayRef)
 }
 
-/// Helper function to cast from `Utf8` to `LargeUtf8` and vice versa. If the `LargeUtf8` is too large for
-/// a `Utf8` array it will return an Error.
-fn cast_str_container<OffsetSizeFrom, OffsetSizeTo>(
-    array: &dyn Array,
-) -> Result<ArrayRef, ArrowError>
+/// Helper function to cast from one `ByteArrayType` to another and vice versa.
+/// If the target one (e.g., `LargeUtf8`) is too large for the source array it will return an Error.
+fn cast_byte_container<FROM, TO>(array: &dyn Array) -> Result<ArrayRef, ArrowError>

Review Comment:
   For this method to be sound I think it needs to restrict the input and output native types to be the same.
   
   Perhaps something like
   
   ```
   fn cast_byte_container<FROM, TO, N>(array: &dyn Array) -> Result<ArrayRef, ArrowError>
       FROM: ByteArrayType<Native = N>,
       TO: ByteArrayType<Native = N>,
       FROM::Offset: OffsetSizeTrait + ToPrimitive,
       TO::Offset: OffsetSizeTrait + NumCast + ArrowNativeType,
   ```
   
   Perhaps we could also rename it to be something like `cast_byte_offsets` :thinking: 



-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3542: Enable casting between Utf8/LargeUtf8 and Binary/LargeBinary

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


##########
arrow-cast/src/cast.rs:
##########
@@ -3460,39 +3460,41 @@ fn cast_list_inner<OffsetSize: OffsetSizeTrait>(
     Ok(Arc::new(list) as ArrayRef)
 }
 
-/// Helper function to cast from `Utf8` to `LargeUtf8` and vice versa. If the `LargeUtf8` is too large for
-/// a `Utf8` array it will return an Error.
-fn cast_str_container<OffsetSizeFrom, OffsetSizeTo>(
-    array: &dyn Array,
-) -> Result<ArrayRef, ArrowError>
+/// Helper function to cast from one `ByteArrayType` to another and vice versa.
+/// If the target one (e.g., `LargeUtf8`) is too large for the source array it will return an Error.
+fn cast_byte_container<FROM, TO>(array: &dyn Array) -> Result<ArrayRef, ArrowError>

Review Comment:
   For this method to be sound I think it needs to restrict the input and output native types to be the same.
   
   Something like
   
   ```
   fn cast_byte_container<FROM, TO, N>(array: &dyn Array) -> Result<ArrayRef, ArrowError>
       FROM: ByteArrayType<Native = N>,
       TO: ByteArrayType<Native = N>,
       FROM::Offset: OffsetSizeTrait + ToPrimitive,
       TO::Offset: OffsetSizeTrait + NumCast + ArrowNativeType,
   ```
   



-- 
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