Skip to content

Commit 019c756

Browse files
committed
Use aggregate APIs for remaining statistics consumers
Signed-off-by: Connor Tsui <[email protected]>
1 parent 54d91e0 commit 019c756

5 files changed

Lines changed: 18 additions & 36 deletions

File tree

‎vortex-btrblocks/src/schemes/patches.rs‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use vortex_array::ArrayRef;
55
use vortex_array::ExecutionCtx;
66
use vortex_array::IntoArray;
7+
use vortex_array::aggregate_fn::fns::is_constant::is_constant;
78
use vortex_array::arrays::ConstantArray;
89
use vortex_array::arrays::PrimitiveArray;
910
use vortex_array::arrays::primitive::PrimitiveArrayExt;
@@ -23,11 +24,7 @@ pub fn compress_patches(patches: Patches, ctx: &mut ExecutionCtx) -> VortexResul
2324

2425
// Check if the values are constant.
2526
let values = patches.values();
26-
let values = if values
27-
.statistics()
28-
.compute_is_constant(ctx)
29-
.unwrap_or_default()
30-
{
27+
let values = if is_constant(values, ctx).unwrap_or_default() {
3128
ConstantArray::new(values.execute_scalar(0, ctx)?, values.len()).into_array()
3229
} else {
3330
values.clone()

‎vortex-compressor/src/stats/float.rs‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use vortex_array::dtype::PType;
1616
use vortex_array::dtype::half::f16;
1717
use vortex_error::VortexExpect;
1818
use vortex_error::VortexResult;
19-
use vortex_error::vortex_err;
2019
use vortex_error::vortex_panic;
2120
use vortex_mask::AllOr;
2221
use vortex_utils::aliases::hash_set::HashSet;
@@ -196,10 +195,7 @@ where
196195
});
197196
}
198197

199-
let null_count = array
200-
.statistics()
201-
.compute_null_count(ctx)
202-
.ok_or_else(|| vortex_err!("Failed to compute null_count"))?;
198+
let null_count = array.invalid_count(ctx)?;
203199
let value_count = array.len() - null_count;
204200

205201
// Keep a HashMap of T, then convert the keys into PValue afterward since value is

‎vortex-compressor/src/stats/integer.rs‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ use std::hash::Hash;
88
use num_traits::PrimInt;
99
use rustc_hash::FxBuildHasher;
1010
use vortex_array::ExecutionCtx;
11+
use vortex_array::aggregate_fn::NumericalAggregateOpts;
12+
use vortex_array::aggregate_fn::fns::min_max::min_max;
1113
use vortex_array::arrays::PrimitiveArray;
1214
use vortex_array::arrays::primitive::NativeValue;
1315
use vortex_array::dtype::IntegerPType;
14-
use vortex_array::expr::stats::Stat;
1516
use vortex_array::match_each_integer_ptype;
1617
use vortex_array::scalar::PValue;
1718
use vortex_array::scalar::Scalar;
@@ -363,16 +364,10 @@ where
363364
let null_count = validity.false_count();
364365
let value_count = validity.true_count();
365366

366-
let array_ref = array.as_ref();
367-
let min = array_ref
368-
.statistics()
369-
.compute_as::<T>(Stat::Min, ctx)
370-
.vortex_expect("min should be computed");
371-
372-
let max = array_ref
373-
.statistics()
374-
.compute_as::<T>(Stat::Max, ctx)
375-
.vortex_expect("max should be computed");
367+
let extrema = min_max(array.as_ref(), ctx, NumericalAggregateOpts::skip_nans())?
368+
.vortex_expect("nonempty integer array with valid values has extrema");
369+
let min = T::try_from(&extrema.min)?;
370+
let max = T::try_from(&extrema.max)?;
376371

377372
// Initialize loop state.
378373
let head_idx = validity

‎vortex-compressor/src/stats/varbinview.rs‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use vortex_array::ExecutionCtx;
77
use vortex_array::arrays::VarBinViewArray;
88
use vortex_error::VortexExpect;
99
use vortex_error::VortexResult;
10-
use vortex_error::vortex_err;
1110
use vortex_utils::aliases::hash_set::HashSet;
1211

1312
use super::GenerateStatsOptions;
@@ -50,10 +49,7 @@ impl StringStats {
5049
opts: GenerateStatsOptions,
5150
ctx: &mut ExecutionCtx,
5251
) -> VortexResult<Self> {
53-
let null_count = input
54-
.statistics()
55-
.compute_null_count(ctx)
56-
.ok_or_else(|| vortex_err!("Failed to compute null_count"))?;
52+
let null_count = input.invalid_count(ctx)?;
5753
let value_count = input.len() - null_count;
5854
let estimated_distinct_count = opts
5955
.count_distinct_values

‎vortex-tui/src/browse/ui/layouts.rs‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,18 +213,16 @@ fn render_array(app: &AppState, area: Rect, buf: &mut Buffer, is_stats_table: bo
213213
.style(Style::new().bold())
214214
.height(1);
215215

216-
let rows = array.statistics().with_iter(|iter| {
217-
iter.map(|(stat, value)| {
218-
let value = value.clone().into_scalar(
219-
stat.dtype(array.dtype())
220-
.vortex_expect("stat invalid for dtype"),
221-
);
222-
let stat = Cell::from(Text::from(format!("{stat}")));
216+
let results = array.aggregations().snapshot_results();
217+
let rows = results
218+
.iter()
219+
.filter(|(_, value)| !value.is_absent())
220+
.map(|(aggregate, value)| {
221+
let aggregate = Cell::from(Text::from(format!("{aggregate}")));
223222
let value = Cell::from(Text::from(format!("{value}")));
224-
Row::new(vec![stat, value])
223+
Row::new(vec![aggregate, value])
225224
})
226-
.collect::<Vec<_>>()
227-
});
225+
.collect::<Vec<_>>();
228226

229227
let layout = Layout::default()
230228
.direction(Direction::Horizontal)

0 commit comments

Comments
 (0)