XiangpengHao commented on code in PR #6044:
URL: https://github.com/apache/arrow-rs/pull/6044#discussion_r1676846101


##########
arrow-row/src/variable.rs:
##########
@@ -243,6 +244,88 @@ pub fn decode_binary<I: OffsetSizeTrait>(
     unsafe { GenericBinaryArray::from(builder.build_unchecked()) }
 }
 
+fn decode_binary_view_inner(
+    rows: &mut [&[u8]],
+    options: SortOptions,
+    check_utf8: bool,
+) -> BinaryViewArray {
+    let len = rows.len();
+
+    let mut null_count = 0;
+
+    let nulls = MutableBuffer::collect_bool(len, |x| {
+        let valid = rows[x][0] != null_sentinel(options);
+        null_count += !valid as usize;
+        valid
+    });
+
+    let values_capacity: usize = rows.iter().map(|row| decoded_len(row, 
options)).sum();
+    let mut values = MutableBuffer::new(values_capacity);
+    let mut views = BufferBuilder::<u128>::new(len);
+
+    for row in rows {
+        let start_offset = values.len();
+        let offset = decode_blocks(row, options, |b| 
values.extend_from_slice(b));
+        if row[0] == null_sentinel(options) {
+            debug_assert_eq!(offset, 1);
+            debug_assert_eq!(start_offset, values.len());
+            views.append(0);
+        } else {
+            let view = make_view(
+                unsafe { values.get_unchecked(start_offset..) },
+                0,
+                start_offset as u32,
+            );
+            views.append(view);
+        }
+        *row = &row[offset..];
+    }
+
+    if options.descending {
+        values.as_slice_mut().iter_mut().for_each(|o| *o = !*o);
+        for view in views.as_slice_mut() {
+            let len = *view as u32;
+            if len <= 12 {
+                let mut bytes = view.to_le_bytes();
+                bytes
+                    .iter_mut()
+                    .skip(4)
+                    .take(len as usize)
+                    .for_each(|o| *o = !*o);
+                *view = u128::from_le_bytes(bytes);
+            } else {
+                let mut byte_view = ByteView::from(*view);
+                let mut prefix = byte_view.prefix.to_le_bytes();
+                prefix.iter_mut().for_each(|o| *o = !*o);
+                byte_view.prefix = u32::from_le_bytes(prefix);
+                *view = byte_view.into();
+            }
+        }
+    }
+
+    if check_utf8 {
+        // the values contains all data, no matter if it is short or long
+        // we can validate utf8 in one go.
+        std::str::from_utf8(values.as_slice()).unwrap();

Review Comment:
   I think the `StringArray` checks utf8 here:
   
https://github.com/apache/arrow-rs/blob/master/arrow-row/src/variable.rs#L258-L260
   



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

Reply via email to