alamb commented on code in PR #6671:
URL: https://github.com/apache/arrow-rs/pull/6671#discussion_r1826570445
##########
arrow-string/src/length.rs:
##########
@@ -138,20 +141,12 @@ pub fn bit_length(array: &dyn Array) -> Result<ArrayRef,
ArrowError> {
Ok(bit_length_impl::<Int64Type>(list.offsets(), list.nulls()))
}
DataType::Utf8View => {
- let string_view_array = array
- .as_any()
- .downcast_ref::<StringViewArray>()
- .ok_or_else(|| ArrowError::ComputeError("Expected Utf8View
array".to_string()))?;
- let mut bit_lengths = Vec::with_capacity(array.len());
- for i in 0..array.len() {
- let bit_length = if string_view_array.is_valid(i) {
- (string_view_array.value(i).len() * 8) as i32
- } else {
- 0
- };
- bit_lengths.push(bit_length);
- }
-
+ let list = array.as_string_view();
+ let bit_lengths = list
+ .views()
+ .iter()
+ .map(|view| (*view as i32) * 8)
Review Comment:
I also still do think you need to handle the null cases (check for which
slots are null) as there might be a view of a non zero length there
##########
arrow-string/src/length.rs:
##########
@@ -138,20 +141,12 @@ pub fn bit_length(array: &dyn Array) -> Result<ArrayRef,
ArrowError> {
Ok(bit_length_impl::<Int64Type>(list.offsets(), list.nulls()))
}
DataType::Utf8View => {
- let string_view_array = array
- .as_any()
- .downcast_ref::<StringViewArray>()
- .ok_or_else(|| ArrowError::ComputeError("Expected Utf8View
array".to_string()))?;
- let mut bit_lengths = Vec::with_capacity(array.len());
- for i in 0..array.len() {
- let bit_length = if string_view_array.is_valid(i) {
- (string_view_array.value(i).len() * 8) as i32
- } else {
- 0
- };
- bit_lengths.push(bit_length);
- }
-
+ let list = array.as_string_view();
+ let bit_lengths = list
+ .views()
+ .iter()
+ .map(|view| (*view as i32) * 8)
Review Comment:
I think the length is currently treated as a `u32` elsewhere in the code
However the actual Arrow spec I think says use i32 so this is probably fine
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]