tustvold commented on code in PR #5481:
URL: https://github.com/apache/arrow-rs/pull/5481#discussion_r1520462566


##########
arrow-array/src/types.rs:
##########
@@ -1544,6 +1546,101 @@ pub type BinaryType = GenericBinaryType<i32>;
 /// An arrow binary array with i64 offsets
 pub type LargeBinaryType = GenericBinaryType<i64>;
 
+mod bytes_view {
+    pub trait Sealed: Send + Sync {}
+    impl Sealed for str {}
+    impl Sealed for [u8] {}
+}
+
+/// A trait over the variable length bytes view array types
+pub trait BytesViewType: bytes_view::Sealed + 'static + PartialEq + 
AsRef<Self> {
+    /// If element in array is utf8 encoded string.
+    const IS_UTF8: bool;
+
+    /// Datatype of array elements
+    const DATA_TYPE: DataType = if Self::IS_UTF8 {
+        DataType::Utf8View
+    } else {
+        DataType::BinaryView
+    };
+
+    /// "Binary" or "String", for use in displayed or error messages
+    const PREFIX: &'static str;
+
+    /// Type for representing its equivalent rust type i.e
+    /// Utf8Array will have native type has &str
+    /// BinaryArray will have type as [u8]
+    type Native: bytes::ByteArrayNativeType + AsRef<Self::Native> + 
AsRef<[u8]> + ?Sized;
+
+    /// Type for owned corresponding to `Native`
+    type Owned: Debug + Clone + Sync + Send + AsRef<Self>;
+
+    /// # Safety
+    /// The caller must ensure `index < self.len()`.
+    unsafe fn from_bytes_unchecked(slice: &[u8]) -> &Self;
+
+    /// To bytes slice.
+    fn to_bytes(&self) -> &[u8];
+
+    /// To owned type
+    #[allow(clippy::wrong_self_convention)]
+    fn into_owned(&self) -> Self::Owned;
+
+    /// Verifies that the provided buffers are valid for this array type
+    fn validate(views: &[u128], buffers: &[Buffer]) -> Result<(), ArrowError>;
+}
+
+impl BytesViewType for str {

Review Comment:
   I think it would be more consistent to define a `BinaryViewType` and 
`StringViewType`. Whilst I can see the appeal of defining traits using the 
underlying representation, there are advantages to adding a layer of 
indirection via type structs, in particular these traits were significantly 
simpler in #4585 



##########
arrow-data/Cargo.toml:
##########
@@ -51,6 +51,7 @@ arrow-schema = { workspace = true }
 
 num = { version = "0.4", default-features = false, features = ["std"] }
 half = { version = "2.1", default-features = false }
+simdutf8 = { version = "0.1.4", default-features = false, features = ["std", 
"aarch64_neon"] }

Review Comment:
   As this is a new dependency I think I would prefer to split this out into a 
separate "performance enhancement" where we can asses the improvement/regression



##########
arrow-data/src/data.rs:
##########
@@ -1590,6 +1580,11 @@ pub struct DataTypeLayout {
 
     /// Can contain a null bitmask
     pub can_contain_null_mask: bool,
+
+    /// This field only applies to the view type,[`DataType::BinaryView`] and 
[`DataType::Utf8View`]

Review Comment:
   ```suggestion
       /// This field only applies to the view type [`DataType::BinaryView`] 
and [`DataType::Utf8View`]
   ```



##########
arrow-data/src/equal/bytes_view.rs:
##########
@@ -0,0 +1,71 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::{ArrayData, BytesView};
+
+pub(super) fn bytes_view_equal(
+    lhs: &ArrayData,
+    rhs: &ArrayData,
+    lhs_start: usize,
+    rhs_start: usize,
+    len: usize,
+) -> bool {
+    let lhs_views = &lhs.buffer::<u128>(0)[lhs_start..lhs_start + len];
+    let lhs_buffers = &lhs.buffers()[1..];
+    let rhs_views = &rhs.buffer::<u128>(0)[rhs_start..rhs_start + len];
+    let rhs_buffers = &rhs.buffers()[1..];
+
+    for (idx, (l, r)) in lhs_views.iter().zip(rhs_views).enumerate() {
+        // Only checking one null mask here because by the time the control 
flow reaches
+        // this point, the equality of the two masks would have already been 
verified.
+        if lhs.is_null(idx) {
+            continue;
+        }
+
+        let l_len_prefix = *l as u64;

Review Comment:
   This has been changed from #4585 and I believe is incorrect. In particular 
it will potentially incorrectly return not equal for non-inline strings



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