Skip to content

Commit f352246

Browse files
committed
fix scalar equality ignores nullability
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent 99a7295 commit f352246

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

vortex-array/src/arrays/primitive/compute/sum.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::register_kernel;
2525
/// Helper to convert an Option<T> to a Scalar. None represents overflow (null result).
2626
fn option_to_scalar<T: NativePType + Into<PValue>>(opt: Option<T>) -> Scalar {
2727
match opt {
28-
Some(v) => Scalar::primitive(v, Nullability::NonNullable),
28+
Some(v) => Scalar::primitive(v, Nullability::Nullable),
2929
None => Scalar::null(T::PTYPE.into()),
3030
}
3131
}
@@ -55,7 +55,7 @@ impl SumKernel for PrimitiveVTable {
5555
array.as_slice::<T>(),
5656
accumulator.as_primitive().as_::<f64>().vortex_expect("cannot be null"),
5757
),
58-
Nullability::NonNullable,
58+
Nullability::Nullable,
5959
)
6060
}
6161
)
@@ -89,7 +89,7 @@ impl SumKernel for PrimitiveVTable {
8989
validity_mask,
9090
accumulator.as_primitive().as_::<f64>().vortex_expect("cannot be null"),
9191
),
92-
Nullability::NonNullable,
92+
Nullability::Nullable,
9393
)
9494
}
9595
)

vortex-scalar/src/scalar.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
use std::cmp::Ordering;
5+
use std::hash::Hash;
6+
use std::hash::Hasher;
57

68
use vortex_dtype::DType;
79
use vortex_dtype::NativeDType;
@@ -27,7 +29,7 @@ use crate::Utf8Scalar;
2729
///
2830
/// Scalars represent a single value with an associated [`DType`]. The value can be null, in which
2931
/// case the [`value`][Scalar::value] method returns `None`.
30-
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
32+
#[derive(Clone, Debug, Eq)]
3133
pub struct Scalar {
3234
/// The type of the scalar.
3335
pub(crate) dtype: DType,
@@ -38,6 +40,19 @@ pub struct Scalar {
3840
pub(crate) value: Option<ScalarValue>,
3941
}
4042

43+
impl PartialEq for Scalar {
44+
fn eq(&self, other: &Self) -> bool {
45+
self.dtype.eq_ignore_nullability(&other.dtype) && self.value == other.value
46+
}
47+
}
48+
49+
impl Hash for Scalar {
50+
fn hash<H: Hasher>(&self, state: &mut H) {
51+
self.dtype.as_nonnullable().hash(state);
52+
self.value.hash(state);
53+
}
54+
}
55+
4156
impl Scalar {
4257
// Constructors for null scalars.
4358

0 commit comments

Comments
 (0)