Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix list/bag/tuple deep equality #421

Merged
merged 3 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixes variable resolution lookup order and excessive lookups
- Fixes variable resolution of some ORDER BY variables
- Fixes nested list/bag/tuple type ordering for when `ASC NULLS LAST` and `DESC NULLS FIRST` are specified
- partiql-value fix deep equality of list, bags, and tuples

## [0.5.0] - 2023-06-06
### Changed
Expand Down
12 changes: 9 additions & 3 deletions partiql-eval/src/eval/expr/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use partiql_types::{
ArrayType, BagType, PartiqlType, StructType, TypeKind, TYPE_ANY, TYPE_BOOL, TYPE_NUMERIC_TYPES,
};
use partiql_value::Value::{Boolean, Missing, Null};
use partiql_value::{BinaryAnd, BinaryOr, NullableEq, NullableOrd, Value};
use partiql_value::{BinaryAnd, BinaryOr, EqualityValue, NullableEq, NullableOrd, Value};

use std::borrow::{Borrow, Cow};
use std::fmt::Debug;
Expand Down Expand Up @@ -170,8 +170,14 @@ impl BindEvalExpr for EvalOpBinary {
match self {
EvalOpBinary::And => logical!(AndCheck, |lhs, rhs| lhs.and(rhs)),
EvalOpBinary::Or => logical!(OrCheck, |lhs, rhs| lhs.or(rhs)),
EvalOpBinary::Eq => equality!(NullableEq::eq),
EvalOpBinary::Neq => equality!(NullableEq::neq),
EvalOpBinary::Eq => equality!(|lhs, rhs| {
let wrap = EqualityValue::<false, Value>;
NullableEq::eq(&wrap(lhs), &wrap(rhs))
}),
EvalOpBinary::Neq => equality!(|lhs, rhs| {
let wrap = EqualityValue::<false, Value>;
NullableEq::neq(&wrap(lhs), &wrap(rhs))
}),
EvalOpBinary::Gt => equality!(NullableOrd::gt),
EvalOpBinary::Gteq => equality!(NullableOrd::gteq),
EvalOpBinary::Lt => equality!(NullableOrd::lt),
Expand Down
13 changes: 8 additions & 5 deletions partiql-value/src/bag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::hash::{Hash, Hasher};

use std::{slice, vec};

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

Expand Down Expand Up @@ -163,10 +163,13 @@ impl PartialEq for Bag {
if self.len() != other.len() {
return false;
}

let lhs = self.0.iter().sorted();
let rhs = other.0.iter().sorted();
lhs.zip(rhs).all(|(l, r)| l == r)
for (v1, v2) in self.0.iter().sorted().zip(other.0.iter().sorted()) {
let wrap = EqualityValue::<true, Value>;
if NullableEq::eq(&wrap(v1), &wrap(v2)) != Value::Boolean(true) {
return false;
}
}
true
}
}

Expand Down
Loading
Loading