Skip to content

Commit

Permalink
Fix bug with null/missing equivalence, refactor neq, refactor eq/eqg …
Browse files Browse the repository at this point in the history
…logic
  • Loading branch information
alancai98 committed Aug 10, 2023
1 parent 2798b63 commit 498afb7
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 161 deletions.
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
12 changes: 4 additions & 8 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, NullableEq, Value};
use crate::{EqualityValue, List, NullSortedValue, NullableEq, Value};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -164,13 +164,9 @@ impl PartialEq for Bag {
return false;
}
for (v1, v2) in self.0.iter().sorted().zip(other.0.iter().sorted()) {
match (v1, v2) {
(Value::Missing, Value::Missing) | (Value::Null, Value::Null) => continue,
(v1, v2) => {
if NullableEq::eq(v1, v2) != Value::Boolean(true) {
return false;
}
}
let wrap = EqualityValue::<true, Value>;
if NullableEq::eq(&wrap(v1), &wrap(v2)) != Value::Boolean(true) {
return false;
}
}
true
Expand Down
Loading

0 comments on commit 498afb7

Please sign in to comment.