Skip to content

Commit a397a95

Browse files
committed
fix
Signed-off-by: Robert Kruszewski <[email protected]>
1 parent 6d74885 commit a397a95

File tree

2 files changed

+14
-37
lines changed

2 files changed

+14
-37
lines changed

fuzz/src/array/compare.rs

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
use std::fmt::Debug;
5-
64
use vortex_array::accessor::ArrayAccessor;
7-
use vortex_array::arrays::BoolArray;
5+
use vortex_array::arrays::{BoolArray, NativeValue};
86
use vortex_array::compute::{Operator, scalar_cmp};
97
use vortex_array::validity::Validity;
108
use vortex_array::{Array, ArrayRef, IntoArray, ToCanonical};
119
use vortex_buffer::BitBuffer;
12-
use vortex_dtype::{
13-
DType, NativePType, Nullability, match_each_decimal_value_type, match_each_native_ptype,
14-
};
10+
use vortex_dtype::{DType, Nullability, match_each_decimal_value_type, match_each_native_ptype};
1511
use vortex_error::{VortexExpect, VortexResult, vortex_err};
1612
use vortex_scalar::Scalar;
1713

@@ -55,14 +51,14 @@ pub fn compare_canonical_array(
5551
let pval = primitive
5652
.typed_value::<P>()
5753
.vortex_expect("nulls handled before");
58-
Ok(compare_native_ptype(
54+
Ok(compare_to(
5955
primitive_array
6056
.as_slice::<P>()
6157
.iter()
6258
.copied()
6359
.zip(array.validity_mask().to_bit_buffer().iter())
64-
.map(|(b, v)| v.then_some(b)),
65-
pval,
60+
.map(|(b, v)| v.then_some(NativeValue(b))),
61+
NativeValue(pval),
6662
operator,
6763
result_nullability,
6864
))
@@ -157,30 +153,3 @@ fn compare_to<T: PartialOrd>(
157153
BoolArray::from_iter(values.map(|val| val.map(eval_fn))).into_array()
158154
}
159155
}
160-
161-
fn compare_native_ptype<T: NativePType>(
162-
values: impl Iterator<Item = Option<T>>,
163-
cmp_value: T,
164-
operator: Operator,
165-
nullability: Nullability,
166-
) -> ArrayRef {
167-
let eval_fn = |v: T| match operator {
168-
Operator::Eq => v.is_eq(cmp_value),
169-
Operator::NotEq => !v.is_eq(cmp_value),
170-
Operator::Gt => v.is_gt(cmp_value),
171-
Operator::Gte => v.is_ge(cmp_value),
172-
Operator::Lt => v.is_lt(cmp_value),
173-
Operator::Lte => v.is_le(cmp_value),
174-
};
175-
176-
if !nullability.is_nullable() {
177-
BoolArray::from_iter(
178-
values
179-
.map(|val| val.vortex_expect("non nullable"))
180-
.map(eval_fn),
181-
)
182-
.into_array()
183-
} else {
184-
BoolArray::from_iter(values.map(|val| val.map(eval_fn))).into_array()
185-
}
186-
}

vortex-array/src/arrays/primitive/native_value.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4+
use std::cmp::Ordering;
5+
46
use vortex_dtype::{NativePType, half};
57

6-
/// NativeValue serves as a wrapper type to allow us to implement Hash and Eq on all primitive types.
8+
/// NativeValue serves as a wrapper type to allow us to implement Hash, Eq and other traits on all primitive types.
79
///
810
/// Rust does not define Hash/Eq for any of the float types due to the presence of
911
/// NaN and +/- 0. We don't care about storing multiple NaNs or zeros in our dictionaries,
@@ -30,6 +32,12 @@ macro_rules! prim_value {
3032
};
3133
}
3234

35+
impl<T: NativePType> PartialOrd<NativeValue<T>> for NativeValue<T> {
36+
fn partial_cmp(&self, other: &NativeValue<T>) -> Option<Ordering> {
37+
Some(self.0.total_compare(other.0))
38+
}
39+
}
40+
3341
macro_rules! float_value {
3442
($typ:ty) => {
3543
impl core::hash::Hash for NativeValue<$typ> {

0 commit comments

Comments
 (0)