Skip to content

Commit

Permalink
Reimplement PartialEq of GenericByteViewArray compares by logical val…
Browse files Browse the repository at this point in the history
…ue (#6689)

Signed-off-by: Tai Le Manh <[email protected]>
  • Loading branch information
tlm365 authored Nov 6, 2024
1 parent 9054bdf commit ee1757d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
25 changes: 1 addition & 24 deletions arrow-array/src/array/byte_view_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,6 @@ use super::ByteArrayType;
///
/// [`ByteView`]: arrow_data::ByteView
///
/// # Use the [`eq`] kernel to compare the logical content.
///
/// Comparing two `GenericByteViewArray` using PartialEq compares by structure
/// (the `u128`s) and contents of the buffers, not by logical content. As there
/// are many different buffer layouts to represent the same data (e.g. different
/// offsets, different buffer sizes, etc) two arrays with the same data may not
/// compare equal.
///
/// To compare the logical content of two `GenericByteViewArray`s, use the [`eq`]
/// kernel.
///
/// [`eq`]: https://docs.rs/arrow/latest/arrow/compute/kernels/cmp/fn.eq.html
///
/// # Layout: "views" and buffers
///
/// A `GenericByteViewArray` stores variable length byte strings. An array of
Expand Down Expand Up @@ -192,16 +179,6 @@ impl<T: ByteViewType + ?Sized> Clone for GenericByteViewArray<T> {
}
}

// PartialEq
impl<T: ByteViewType + ?Sized> PartialEq for GenericByteViewArray<T> {
fn eq(&self, other: &Self) -> bool {
other.data_type.eq(&self.data_type)
&& other.views.eq(&self.views)
&& other.buffers.eq(&self.buffers)
&& other.nulls.eq(&self.nulls)
}
}

impl<T: ByteViewType + ?Sized> GenericByteViewArray<T> {
/// Create a new [`GenericByteViewArray`] from the provided parts, panicking on failure
///
Expand Down Expand Up @@ -1065,6 +1042,6 @@ mod tests {
};
assert_eq!(array1, array1.clone());
assert_eq!(array2, array2.clone());
assert_ne!(array1, array2);
assert_eq!(array1, array2);
}
}
6 changes: 6 additions & 0 deletions arrow-array/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,12 @@ impl PartialEq for StructArray {
}
}

impl<T: ByteViewType + ?Sized> PartialEq for GenericByteViewArray<T> {
fn eq(&self, other: &Self) -> bool {
self.to_data().eq(&other.to_data())
}
}

/// Constructs an array using the input `data`.
/// Returns a reference-counted `Array` instance.
pub fn make_array(data: ArrayData) -> ArrayRef {
Expand Down

0 comments on commit ee1757d

Please sign in to comment.