Skip to content

Commit d868e5b

Browse files
docs: clarify try_cmp behavior for NULL inputs
1 parent 500697e commit d868e5b

File tree

1 file changed

+8
-4
lines changed
  • datafusion/common/src/scalar

1 file changed

+8
-4
lines changed

datafusion/common/src/scalar/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4021,11 +4021,15 @@ impl ScalarValue {
40214021
arr1 == &right
40224022
}
40234023

4024-
/// Compare `self` with `other` and return an `Ordering`.
4024+
/// Compare two `ScalarValue`s.
40254025
///
4026-
/// This is the same as [`PartialOrd`] except that it returns
4027-
/// `Err` if the values cannot be compared, e.g., they have incompatible data types.
4028-
pub fn try_cmp(&self, other: &Self) -> Result<Ordering> {
4026+
/// Returns an error if:
4027+
/// * the values are of incompatible types, or
4028+
/// * either value is NULL.
4029+
///
4030+
/// This differs from `partial_cmp`, which returns `None` for NULL inputs
4031+
/// instead of an error.
4032+
pub fn try_cmp(&self, other: &Self) -> Result<Ordering> {
40294033
self.partial_cmp(other).ok_or_else(|| {
40304034
_internal_datafusion_err!("Uncomparable values: {self:?}, {other:?}")
40314035
})

0 commit comments

Comments
 (0)