Skip to content

Commit 2191aa0

Browse files
committed
Explicit abset Precision variant instead of Option<Precision>
Signed-off-by: Adam Gutglick <adam@spiraldb.com>
1 parent 008c1d9 commit 2191aa0

22 files changed

Lines changed: 326 additions & 333 deletions

File tree

vortex-array/src/aggregate_fn/accumulator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl<V: AggregateFnVTable> DynAccumulator for Accumulator<V> {
122122
// 0. Legacy stats bridge: if this aggregate is still cached under a legacy Stat slot,
123123
// consume that exact stat before kernel dispatch or decode.
124124
if let Some(stat) = Stat::from_aggregate_fn(&self.aggregate_fn)
125-
&& let Some(Precision::Exact(partial)) = batch.statistics().get(stat)
125+
&& let Precision::Exact(partial) = batch.statistics().get(stat)
126126
{
127127
vortex_ensure!(
128128
partial.dtype() == &self.partial_dtype,

vortex-array/src/aggregate_fn/fns/is_constant/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn arrays_value_equal(a: &ArrayRef, b: &ArrayRef, ctx: &mut ExecutionCtx) -> Vor
8989
/// 5. Is all valid AND has minimum and maximum statistics that are equal.
9090
pub fn is_constant(array: &ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<bool> {
9191
// Short-circuit using cached array statistics.
92-
if let Some(Precision::Exact(value)) = array.statistics().get_as::<bool>(Stat::IsConstant) {
92+
if let Precision::Exact(value) = array.statistics().get_as::<bool>(Stat::IsConstant) {
9393
return Ok(value);
9494
}
9595

@@ -133,14 +133,14 @@ pub fn is_constant(array: &ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<boo
133133
}
134134

135135
// We already know here that the array is all valid, so we check for min/max stats.
136-
let min = array.statistics().get(Stat::Min);
137-
let max = array.statistics().get(Stat::Max);
136+
let min_stat = array.statistics().get(Stat::Min);
137+
let max_stat = array.statistics().get(Stat::Max);
138138

139-
if let Some((min, max)) = min.zip(max)
140-
&& min.is_exact()
139+
if let Precision::Exact(min) = min_stat.as_ref()
140+
&& let Precision::Exact(max) = max_stat.as_ref()
141141
&& min == max
142142
&& (Stat::NaNCount.dtype(array.dtype()).is_none()
143-
|| array.statistics().get_as::<u64>(Stat::NaNCount) == Some(Precision::exact(0u64)))
143+
|| array.statistics().get_as::<u64>(Stat::NaNCount) == Precision::exact(0u64))
144144
{
145145
array
146146
.statistics()

vortex-array/src/aggregate_fn/fns/is_sorted/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn is_sorted_impl(array: &ArrayRef, strict: bool, ctx: &mut ExecutionCtx) -> Vor
7777
};
7878

7979
// Short-circuit using cached array statistics.
80-
if let Some(Precision::Exact(value)) = array.statistics().get_as::<bool>(stat) {
80+
if let Precision::Exact(value) = array.statistics().get_as::<bool>(stat) {
8181
return Ok(value);
8282
}
8383

vortex-array/src/aggregate_fn/fns/min_max/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,8 @@ static NAMES: LazyLock<FieldNames> = LazyLock::new(|| FieldNames::from(["min", "
4646
/// This will update the stats set of the array as a side effect.
4747
pub fn min_max(array: &ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Option<MinMaxResult>> {
4848
// Short-circuit using cached array statistics.
49-
let cached_min = array
50-
.statistics()
51-
.get(Stat::Min)
52-
.and_then(Precision::as_exact);
53-
let cached_max = array
54-
.statistics()
55-
.get(Stat::Max)
56-
.and_then(Precision::as_exact);
49+
let cached_min = array.statistics().get(Stat::Min).as_exact();
50+
let cached_max = array.statistics().get(Stat::Max).as_exact();
5751
if let Some((min, max)) = cached_min.zip(cached_max) {
5852
let non_nullable_dtype = array.dtype().as_nonnullable();
5953
return Ok(Some(MinMaxResult {

vortex-array/src/aggregate_fn/fns/nan_count/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::scalar::ScalarValue;
3232
/// See [`NanCount`] for details.
3333
pub fn nan_count(array: &ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<usize> {
3434
// Short-circuit using cached array statistics.
35-
if let Some(Precision::Exact(nan_count_scalar)) = array.statistics().get(Stat::NaNCount) {
35+
if let Precision::Exact(nan_count_scalar) = array.statistics().get(Stat::NaNCount) {
3636
return usize::try_from(&nan_count_scalar)
3737
.map_err(|e| vortex_err!("Failed to convert NaN count stat to usize: {e}"));
3838
}

vortex-array/src/aggregate_fn/fns/null_count/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::scalar::ScalarValue;
2525

2626
/// Return the number of null values in an array.
2727
pub fn null_count(array: &ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<usize> {
28-
if let Some(Precision::Exact(null_count_scalar)) = array.statistics().get(Stat::NullCount) {
28+
if let Precision::Exact(null_count_scalar) = array.statistics().get(Stat::NullCount) {
2929
return usize::try_from(&null_count_scalar)
3030
.map_err(|e| vortex_err!("Failed to convert null count stat to usize: {e}"));
3131
}
@@ -170,7 +170,7 @@ mod tests {
170170
assert_eq!(null_count(&array, &mut ctx)?, 2);
171171
assert_eq!(
172172
array.statistics().get_as::<u64>(Stat::NullCount),
173-
Some(Precision::exact(2u64))
173+
Precision::exact(2u64)
174174
);
175175
Ok(())
176176
}

vortex-array/src/aggregate_fn/fns/sum/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use crate::scalar::Scalar;
4141
/// See [`Sum`] for details.
4242
pub fn sum(array: &ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Scalar> {
4343
// Short-circuit using cached array statistics.
44-
if let Some(Precision::Exact(sum_scalar)) = array.statistics().get(Stat::Sum) {
44+
if let Precision::Exact(sum_scalar) = array.statistics().get(Stat::Sum) {
4545
return Ok(sum_scalar);
4646
}
4747

@@ -379,7 +379,7 @@ mod tests {
379379

380380
// For non-float types, try statistics short-circuit with accumulator.
381381
if !matches!(&sum_dtype, DType::Primitive(p, _) if p.is_float())
382-
&& let Some(Precision::Exact(sum_scalar)) = array.statistics().get(Stat::Sum)
382+
&& let Precision::Exact(sum_scalar) = array.statistics().get(Stat::Sum)
383383
{
384384
return add_scalars(&sum_dtype, &sum_scalar, accumulator);
385385
}

vortex-array/src/aggregate_fn/fns/uncompressed_size_in_bytes/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ pub fn uncompressed_size_in_bytes(array: &ArrayRef, ctx: &mut ExecutionCtx) -> V
6363
}
6464

6565
fn uncompressed_size_in_bytes_u64(array: &ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<u64> {
66-
if let Some(Precision::Exact(size_scalar)) =
67-
array.statistics().get(Stat::UncompressedSizeInBytes)
68-
{
66+
if let Precision::Exact(size_scalar) = array.statistics().get(Stat::UncompressedSizeInBytes) {
6967
return u64::try_from(&size_scalar)
7068
.map_err(|e| vortex_err!("Failed to convert uncompressed size stat to u64: {e}"));
7169
}
@@ -597,7 +595,7 @@ mod tests {
597595

598596
assert_eq!(
599597
array.statistics().get(Stat::UncompressedSizeInBytes),
600-
Some(Precision::exact(u64::try_from(size)?))
598+
Precision::exact(u64::try_from(size)?)
601599
);
602600
Ok(())
603601
}

vortex-array/src/array/erased.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,7 @@ impl ArrayRef {
327327
/// Returns the number of valid elements in the array.
328328
pub fn valid_count(&self, ctx: &mut ExecutionCtx) -> VortexResult<usize> {
329329
let len = self.len();
330-
if let Some(Precision::Exact(invalid_count)) =
331-
self.statistics().get_as::<usize>(Stat::NullCount)
330+
if let Precision::Exact(invalid_count) = self.statistics().get_as::<usize>(Stat::NullCount)
332331
{
333332
return Ok(len - invalid_count);
334333
}

vortex-array/src/arrays/dict/take.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,18 @@ pub(crate) fn propagate_take_stats(
151151
target.statistics().with_mut_typed_stats_set(|mut st| {
152152
if indices_all_valid {
153153
let is_constant = source.statistics().get_as::<bool>(Stat::IsConstant);
154-
if is_constant == Some(Precision::Exact(true)) {
154+
if matches!(is_constant, Precision::Exact(true)) {
155155
// Any combination of elements from a constant array is still const
156156
st.set(Stat::IsConstant, Precision::exact(true));
157157
}
158158
}
159159
let inexact_min_max = [Stat::Min, Stat::Max]
160160
.into_iter()
161-
.filter_map(|stat| {
162-
source
163-
.statistics()
164-
.get(stat)
165-
.and_then(|v| v.map(|s| s.into_value()).into_inexact().transpose())
166-
.map(|sv| (stat, sv))
161+
.filter_map(|stat| match source.statistics().get(stat).into_inexact() {
162+
Precision::Exact(scalar) | Precision::Inexact(scalar) => {
163+
scalar.into_value().map(|sv| (stat, Precision::Inexact(sv)))
164+
}
165+
Precision::Absent => None,
167166
})
168167
.collect::<SmallVec<_>>();
169168
st.combine_sets(

0 commit comments

Comments
 (0)