Skip to content

Commit

Permalink
Fix list/bag deep equality
Browse files Browse the repository at this point in the history
  • Loading branch information
alancai98 committed Aug 8, 2023
1 parent 191b10e commit 5e2b94d
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions partiql-value/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use std::hash::Hash;

use std::{slice, vec};

use crate::{Bag, Value};
use crate::{Bag, NullableEq, Value};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

#[derive(Default, Hash, PartialEq, Eq, Clone)]
#[derive(Default, Hash, Eq, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
/// Represents a PartiQL List value, e.g. [1, 2, 'one']
pub struct List(Vec<Value>);
Expand Down Expand Up @@ -149,6 +149,24 @@ impl Debug for List {
}
}

impl PartialEq for List {
fn eq(&self, other: &Self) -> bool {
let iter1 = self.iter();
let iter2 = other.iter();
for (v1, v2) in iter1.zip(iter2) {
match (v1, v2) {
(Value::Missing, Value::Missing) | (Value::Null, Value::Null) => continue,
(v1, v2) => {
if NullableEq::eq(v1, v2) != Value::Boolean(true) {
return false;
}
}
}
}
true
}
}

impl PartialOrd for List {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
let mut l = self.0.iter();
Expand Down

0 comments on commit 5e2b94d

Please sign in to comment.