Path: blob/main/crates/polars-arrow/src/array/equal/mod.rs
6939 views
use super::*;1use crate::offset::Offset;2use crate::types::NativeType;34mod binary;5mod binary_view;6mod boolean;7mod dictionary;8mod fixed_size_binary;9mod fixed_size_list;10mod list;11mod map;12mod null;13mod primitive;14mod struct_;15mod union;16mod utf8;1718impl PartialEq for dyn Array + '_ {19fn eq(&self, that: &dyn Array) -> bool {20equal(self, that)21}22}2324impl PartialEq<dyn Array> for std::sync::Arc<dyn Array + '_> {25fn eq(&self, that: &dyn Array) -> bool {26equal(&**self, that)27}28}2930impl PartialEq<dyn Array> for Box<dyn Array + '_> {31fn eq(&self, that: &dyn Array) -> bool {32equal(&**self, that)33}34}3536impl PartialEq<NullArray> for NullArray {37fn eq(&self, other: &Self) -> bool {38null::equal(self, other)39}40}4142impl PartialEq<&dyn Array> for NullArray {43fn eq(&self, other: &&dyn Array) -> bool {44equal(self, *other)45}46}4748impl<T: NativeType> PartialEq<&dyn Array> for PrimitiveArray<T> {49fn eq(&self, other: &&dyn Array) -> bool {50equal(self, *other)51}52}5354impl<T: NativeType> PartialEq<PrimitiveArray<T>> for &dyn Array {55fn eq(&self, other: &PrimitiveArray<T>) -> bool {56equal(*self, other)57}58}5960impl<T: NativeType> PartialEq<PrimitiveArray<T>> for PrimitiveArray<T> {61fn eq(&self, other: &Self) -> bool {62primitive::equal::<T>(self, other)63}64}6566impl PartialEq<BooleanArray> for BooleanArray {67fn eq(&self, other: &Self) -> bool {68equal(self, other)69}70}7172impl PartialEq<&dyn Array> for BooleanArray {73fn eq(&self, other: &&dyn Array) -> bool {74equal(self, *other)75}76}7778impl<O: Offset> PartialEq<Utf8Array<O>> for Utf8Array<O> {79fn eq(&self, other: &Self) -> bool {80utf8::equal(self, other)81}82}8384impl<O: Offset> PartialEq<&dyn Array> for Utf8Array<O> {85fn eq(&self, other: &&dyn Array) -> bool {86equal(self, *other)87}88}8990impl<O: Offset> PartialEq<Utf8Array<O>> for &dyn Array {91fn eq(&self, other: &Utf8Array<O>) -> bool {92equal(*self, other)93}94}9596impl<O: Offset> PartialEq<BinaryArray<O>> for BinaryArray<O> {97fn eq(&self, other: &Self) -> bool {98binary::equal(self, other)99}100}101102impl<O: Offset> PartialEq<&dyn Array> for BinaryArray<O> {103fn eq(&self, other: &&dyn Array) -> bool {104equal(self, *other)105}106}107108impl<O: Offset> PartialEq<BinaryArray<O>> for &dyn Array {109fn eq(&self, other: &BinaryArray<O>) -> bool {110equal(*self, other)111}112}113114impl PartialEq<FixedSizeBinaryArray> for FixedSizeBinaryArray {115fn eq(&self, other: &Self) -> bool {116fixed_size_binary::equal(self, other)117}118}119120impl PartialEq<&dyn Array> for FixedSizeBinaryArray {121fn eq(&self, other: &&dyn Array) -> bool {122equal(self, *other)123}124}125126impl<O: Offset> PartialEq<ListArray<O>> for ListArray<O> {127fn eq(&self, other: &Self) -> bool {128list::equal(self, other)129}130}131132impl<O: Offset> PartialEq<&dyn Array> for ListArray<O> {133fn eq(&self, other: &&dyn Array) -> bool {134equal(self, *other)135}136}137138impl PartialEq<FixedSizeListArray> for FixedSizeListArray {139fn eq(&self, other: &Self) -> bool {140fixed_size_list::equal(self, other)141}142}143144impl PartialEq<&dyn Array> for FixedSizeListArray {145fn eq(&self, other: &&dyn Array) -> bool {146equal(self, *other)147}148}149150impl PartialEq<StructArray> for StructArray {151fn eq(&self, other: &Self) -> bool {152struct_::equal(self, other)153}154}155156impl PartialEq<&dyn Array> for StructArray {157fn eq(&self, other: &&dyn Array) -> bool {158equal(self, *other)159}160}161162impl<K: DictionaryKey> PartialEq<DictionaryArray<K>> for DictionaryArray<K> {163fn eq(&self, other: &Self) -> bool {164dictionary::equal(self, other)165}166}167168impl<K: DictionaryKey> PartialEq<&dyn Array> for DictionaryArray<K> {169fn eq(&self, other: &&dyn Array) -> bool {170equal(self, *other)171}172}173174impl PartialEq<UnionArray> for UnionArray {175fn eq(&self, other: &Self) -> bool {176union::equal(self, other)177}178}179180impl PartialEq<&dyn Array> for UnionArray {181fn eq(&self, other: &&dyn Array) -> bool {182equal(self, *other)183}184}185186impl PartialEq<MapArray> for MapArray {187fn eq(&self, other: &Self) -> bool {188map::equal(self, other)189}190}191192impl PartialEq<&dyn Array> for MapArray {193fn eq(&self, other: &&dyn Array) -> bool {194equal(self, *other)195}196}197198/// Logically compares two [`Array`]s.199/// Two arrays are logically equal if and only if:200/// * their data types are equal201/// * each of their items are equal202pub fn equal(lhs: &dyn Array, rhs: &dyn Array) -> bool {203if lhs.dtype() != rhs.dtype() {204return false;205}206207use crate::datatypes::PhysicalType::*;208match lhs.dtype().to_physical_type() {209Null => {210let lhs = lhs.as_any().downcast_ref().unwrap();211let rhs = rhs.as_any().downcast_ref().unwrap();212null::equal(lhs, rhs)213},214Boolean => {215let lhs = lhs.as_any().downcast_ref().unwrap();216let rhs = rhs.as_any().downcast_ref().unwrap();217boolean::equal(lhs, rhs)218},219Primitive(primitive) => with_match_primitive_type_full!(primitive, |$T| {220let lhs = lhs.as_any().downcast_ref().unwrap();221let rhs = rhs.as_any().downcast_ref().unwrap();222primitive::equal::<$T>(lhs, rhs)223}),224Utf8 => {225let lhs = lhs.as_any().downcast_ref().unwrap();226let rhs = rhs.as_any().downcast_ref().unwrap();227utf8::equal::<i32>(lhs, rhs)228},229LargeUtf8 => {230let lhs = lhs.as_any().downcast_ref().unwrap();231let rhs = rhs.as_any().downcast_ref().unwrap();232utf8::equal::<i64>(lhs, rhs)233},234Binary => {235let lhs = lhs.as_any().downcast_ref().unwrap();236let rhs = rhs.as_any().downcast_ref().unwrap();237binary::equal::<i32>(lhs, rhs)238},239LargeBinary => {240let lhs = lhs.as_any().downcast_ref().unwrap();241let rhs = rhs.as_any().downcast_ref().unwrap();242binary::equal::<i64>(lhs, rhs)243},244List => {245let lhs = lhs.as_any().downcast_ref().unwrap();246let rhs = rhs.as_any().downcast_ref().unwrap();247list::equal::<i32>(lhs, rhs)248},249LargeList => {250let lhs = lhs.as_any().downcast_ref().unwrap();251let rhs = rhs.as_any().downcast_ref().unwrap();252list::equal::<i64>(lhs, rhs)253},254Struct => {255let lhs = lhs.as_any().downcast_ref::<StructArray>().unwrap();256let rhs = rhs.as_any().downcast_ref::<StructArray>().unwrap();257struct_::equal(lhs, rhs)258},259Dictionary(key_type) => {260match_integer_type!(key_type, |$T| {261let lhs = lhs.as_any().downcast_ref().unwrap();262let rhs = rhs.as_any().downcast_ref().unwrap();263dictionary::equal::<$T>(lhs, rhs)264})265},266FixedSizeBinary => {267let lhs = lhs.as_any().downcast_ref().unwrap();268let rhs = rhs.as_any().downcast_ref().unwrap();269fixed_size_binary::equal(lhs, rhs)270},271FixedSizeList => {272let lhs = lhs.as_any().downcast_ref().unwrap();273let rhs = rhs.as_any().downcast_ref().unwrap();274fixed_size_list::equal(lhs, rhs)275},276Union => {277let lhs = lhs.as_any().downcast_ref().unwrap();278let rhs = rhs.as_any().downcast_ref().unwrap();279union::equal(lhs, rhs)280},281Map => {282let lhs = lhs.as_any().downcast_ref().unwrap();283let rhs = rhs.as_any().downcast_ref().unwrap();284map::equal(lhs, rhs)285},286BinaryView => {287let lhs = lhs.as_any().downcast_ref().unwrap();288let rhs = rhs.as_any().downcast_ref().unwrap();289binary_view::equal::<[u8]>(lhs, rhs)290},291Utf8View => {292let lhs = lhs.as_any().downcast_ref().unwrap();293let rhs = rhs.as_any().downcast_ref().unwrap();294binary_view::equal::<str>(lhs, rhs)295},296}297}298299300