Skip to content

Commit 552a1e9

Browse files
Align vector ordering tests with ScalarValue NULL partial_cmp semantics
1 parent b79699a commit 552a1e9

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

datafusion/common/src/scalar/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,10 @@ impl PartialOrd for ScalarValue {
727727
if k1 == k2 { v1.partial_cmp(v2) } else { None }
728728
}
729729
(Dictionary(_, _), _) => None,
730-
// Null is handled by the early return above, but we need this for exhaustiveness
731-
(Null, _) => None,
730+
// Nulls are handled by the early return above
731+
(Null, _) | (_, Null) => unreachable!(
732+
"Nulls are already handled before entering ScalarValue::partial_cmp match"
733+
),
732734
}
733735
}
734736
}

datafusion/common/src/utils/mod.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,29 +1021,33 @@ mod tests {
10211021
fn vector_ord() {
10221022
assert!(vec![1, 0, 0, 0, 0, 0, 0, 1] < vec![1, 0, 0, 0, 0, 0, 0, 2]);
10231023
assert!(vec![1, 0, 0, 0, 0, 0, 1, 1] > vec![1, 0, 0, 0, 0, 0, 0, 2]);
1024-
assert!(
1024+
// Vectors containing Null values cannot be compared because
1025+
// ScalarValue::partial_cmp returns None for null comparisons
1026+
assert_eq!(
10251027
vec![
10261028
ScalarValue::Int32(Some(2)),
10271029
Null,
10281030
ScalarValue::Int32(Some(0)),
10291031
]
1030-
< vec![
1032+
.partial_cmp(&vec![
10311033
ScalarValue::Int32(Some(2)),
10321034
Null,
10331035
ScalarValue::Int32(Some(1)),
1034-
]
1036+
]),
1037+
None
10351038
);
1036-
assert!(
1039+
assert_eq!(
10371040
vec![
10381041
ScalarValue::Int32(Some(2)),
10391042
ScalarValue::Int32(None),
10401043
ScalarValue::Int32(Some(0)),
10411044
]
1042-
< vec![
1045+
.partial_cmp(&vec![
10431046
ScalarValue::Int32(Some(2)),
10441047
ScalarValue::Int32(None),
10451048
ScalarValue::Int32(Some(1)),
1046-
]
1049+
]),
1050+
None
10471051
);
10481052
}
10491053

0 commit comments

Comments
 (0)