Skip to content

Commit a86560b

Browse files
committed
fix: allow for Null(DataType) equivalency comparison
The change made in `e2378a579790172800d91701c143f4522957a9de` modified the equivalency behaviors of Scalars in a way that mean Null(DataType::String) != Null(DataType::String) which I don't believe is correct since we can perform an equivalency on the DataType. This changes re-introduces that support with a test case that passes on v0.6.1 and fails on v0.7.0, v0.8.0, and `main`. Signed-off-by: R. Tyler Croy <[email protected]>
1 parent aef2c9b commit a86560b

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

kernel/src/expressions/scalars.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,14 @@ impl PartialOrd for Scalar {
265265
.then(|| v1.partial_cmp(v2))
266266
.flatten(),
267267
(Decimal(_, _, _), _) => None,
268+
(Null(a), Null(b)) => {
269+
if a == b {
270+
Some(Ordering::Equal)
271+
}
272+
else {
273+
None
274+
}
275+
},
268276
(Null(_), _) => None, // NOTE: NULL values are incomparable by definition
269277
(Struct(_), _) => None, // TODO: Support Struct?
270278
(Array(_), _) => None, // TODO: Support Array?
@@ -652,9 +660,9 @@ mod tests {
652660
assert_eq!(a.partial_cmp(&c), None);
653661
assert_eq!(c.partial_cmp(&a), None);
654662

655-
// assert that NULL values are incomparable
656-
let null = Scalar::Null(DataType::INTEGER);
657-
assert_eq!(null.partial_cmp(&null), None);
663+
let a = Scalar::Null(DataType::INTEGER);
664+
let b = Scalar::Null(DataType::STRING);
665+
assert_eq!(a.partial_cmp(&b), None);
658666
}
659667

660668
#[test]
@@ -667,8 +675,13 @@ mod tests {
667675
assert!(!a.eq(&c));
668676
assert!(!c.eq(&a));
669677

678+
let a = Scalar::Null(DataType::STRING);
679+
let b = Scalar::Null(DataType::STRING);
680+
assert_eq!(a, b);
681+
670682
// assert that NULL values are incomparable
671-
let null = Scalar::Null(DataType::INTEGER);
672-
assert!(!null.eq(&null));
683+
let a = Scalar::Null(DataType::INTEGER);
684+
let b = Scalar::Null(DataType::STRING);
685+
assert_ne!(a, b);
673686
}
674687
}

0 commit comments

Comments
 (0)