Skip to content

Commit aa45cfc

Browse files
committed
fix[array]: min_max return type non nullable
Signed-off-by: Joe Isaacs <[email protected]>
1 parent 91ca489 commit aa45cfc

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

vortex-array/src/arrays/decimal/compute/min_max.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
use itertools::Itertools;
5-
use vortex_dtype::{DType, NativeDecimalType};
5+
use vortex_dtype::Nullability::NonNullable;
6+
use vortex_dtype::{DecimalDType, NativeDecimalType};
67
use vortex_error::VortexResult;
78
use vortex_mask::Mask;
8-
use vortex_scalar::{DecimalValue, Scalar, ScalarValue, match_each_decimal_value_type};
9+
use vortex_scalar::{DecimalValue, Scalar, match_each_decimal_value_type};
910

1011
use crate::arrays::{DecimalArray, DecimalVTable};
1112
use crate::compute::{MinMaxKernel, MinMaxKernelAdapter, MinMaxResult};
@@ -27,36 +28,38 @@ where
2728
D: Into<DecimalValue> + NativeDecimalType,
2829
{
2930
Ok(match array.validity_mask() {
30-
Mask::AllTrue(_) => compute_min_max(array.buffer::<D>().iter(), array.dtype()),
31+
Mask::AllTrue(_) => compute_min_max(array.buffer::<D>().iter(), array.decimal_dtype()),
3132
Mask::AllFalse(_) => None,
3233
Mask::Values(v) => compute_min_max(
3334
array
3435
.buffer::<D>()
3536
.iter()
3637
.zip(v.bit_buffer().iter())
3738
.filter_map(|(v, m)| m.then_some(v)),
38-
array.dtype(),
39+
array.decimal_dtype(),
3940
),
4041
})
4142
}
4243

43-
fn compute_min_max<'a, T>(iter: impl Iterator<Item = &'a T>, dtype: &DType) -> Option<MinMaxResult>
44+
fn compute_min_max<'a, T>(
45+
iter: impl Iterator<Item = &'a T>,
46+
decimal_dtype: DecimalDType,
47+
) -> Option<MinMaxResult>
4448
where
4549
T: Into<DecimalValue> + NativeDecimalType + Ord + Copy + 'a,
4650
{
47-
let non_nullable_dtype = dtype.as_nonnullable();
4851
match iter.minmax_by(|a, b| a.cmp(b)) {
4952
itertools::MinMaxResult::NoElements => None,
5053
itertools::MinMaxResult::OneElement(&x) => {
51-
let scalar = Scalar::new(non_nullable_dtype, ScalarValue::from(x.into()));
54+
let scalar = Scalar::decimal(x.into(), decimal_dtype, NonNullable);
5255
Some(MinMaxResult {
5356
min: scalar.clone(),
5457
max: scalar,
5558
})
5659
}
5760
itertools::MinMaxResult::MinMax(&min, &max) => Some(MinMaxResult {
58-
min: Scalar::new(non_nullable_dtype.clone(), ScalarValue::from(min.into())),
59-
max: Scalar::new(non_nullable_dtype, ScalarValue::from(max.into())),
61+
min: Scalar::decimal(min.into(), decimal_dtype, NonNullable),
62+
max: Scalar::decimal(max.into(), decimal_dtype, NonNullable),
6063
}),
6164
}
6265
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
use itertools::Itertools;
55
use vortex_dtype::Nullability::NonNullable;
6-
use vortex_dtype::{DType, NativePType, match_each_native_ptype};
6+
use vortex_dtype::{NativePType, match_each_native_ptype};
77
use vortex_error::VortexResult;
88
use vortex_mask::Mask;
9-
use vortex_scalar::{PValue, Scalar, ScalarValue};
9+
use vortex_scalar::{PValue, Scalar};
1010

1111
use crate::arrays::{PrimitiveArray, PrimitiveVTable};
1212
use crate::compute::{MinMaxKernel, MinMaxKernelAdapter, MinMaxResult};
@@ -29,20 +29,19 @@ where
2929
PValue: From<T>,
3030
{
3131
Ok(match array.validity_mask() {
32-
Mask::AllTrue(_) => compute_min_max(array.as_slice::<T>().iter(), array.dtype()),
32+
Mask::AllTrue(_) => compute_min_max(array.as_slice::<T>().iter()),
3333
Mask::AllFalse(_) => None,
3434
Mask::Values(v) => compute_min_max(
3535
array
3636
.as_slice::<T>()
3737
.iter()
3838
.zip(v.bit_buffer().iter())
3939
.filter_map(|(v, m)| m.then_some(v)),
40-
array.dtype(),
4140
),
4241
})
4342
}
4443

45-
fn compute_min_max<'a, T>(iter: impl Iterator<Item = &'a T>, dtype: &DType) -> Option<MinMaxResult>
44+
fn compute_min_max<'a, T>(iter: impl Iterator<Item = &'a T>) -> Option<MinMaxResult>
4645
where
4746
T: NativePType,
4847
PValue: From<T>,

0 commit comments

Comments
 (0)