Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make stats return VortexResult #52

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/fastlanez
5 changes: 3 additions & 2 deletions vortex-alp/src/stats.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::collections::HashMap;
use vortex::error::VortexResult;

use crate::ALPArray;
use vortex::stats::{Stat, StatsCompute, StatsSet};

impl StatsCompute for ALPArray {
fn compute(&self, _stat: &Stat) -> StatsSet {
fn compute(&self, _stat: &Stat) -> VortexResult<StatsSet> {
// TODO(ngates): implement based on the encoded array
StatsSet::from(HashMap::new())
Ok(StatsSet::from(HashMap::new()))
}
}
5 changes: 3 additions & 2 deletions vortex-dict/src/stats.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use vortex::error::VortexResult;
use vortex::stats::{Stat, StatsCompute, StatsSet};

use crate::dict::DictArray;

impl StatsCompute for DictArray {
fn compute(&self, _stat: &Stat) -> StatsSet {
fn compute(&self, _stat: &Stat) -> VortexResult<StatsSet> {
let mut stats = StatsSet::new();

if let Some(rc) = self.codes().stats().get_or_compute(&Stat::RunCount) {
Expand Down Expand Up @@ -46,6 +47,6 @@ impl StatsCompute for DictArray {
}
}

stats
Ok(stats)
}
}
6 changes: 2 additions & 4 deletions vortex-fastlanes/src/bitpacking/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::any::Any;
use std::collections::HashMap;
use std::sync::{Arc, RwLock};

use vortex::array::{
Expand Down Expand Up @@ -161,9 +160,8 @@ impl ArrayDisplay for BitPackedArray {
}

impl StatsCompute for BitPackedArray {
fn compute(&self, _stat: &Stat) -> StatsSet {
// TODO(ngates): implement based on the encoded array
StatsSet::from(HashMap::new())
fn compute(&self, _stat: &Stat) -> VortexResult<StatsSet> {
Ok(StatsSet::default())
}
}

Expand Down
6 changes: 2 additions & 4 deletions vortex-fastlanes/src/for/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::any::Any;
use std::collections::HashMap;
use std::sync::{Arc, RwLock};

use vortex::array::{Array, ArrayRef, ArrowIterator, Encoding, EncodingId, EncodingRef};
Expand Down Expand Up @@ -123,9 +122,8 @@ impl ArrayDisplay for FoRArray {
}

impl StatsCompute for FoRArray {
fn compute(&self, _stat: &Stat) -> StatsSet {
// TODO(ngates): implement based on the encoded array
StatsSet::from(HashMap::new())
fn compute(&self, _stat: &Stat) -> VortexResult<StatsSet> {
Ok(StatsSet::default())
}
}

Expand Down
7 changes: 3 additions & 4 deletions vortex-ffor/src/stats.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::collections::HashMap;
use vortex::error::VortexResult;

use crate::FFORArray;
use vortex::stats::{Stat, StatsCompute, StatsSet};

impl StatsCompute for FFORArray {
fn compute(&self, _stat: &Stat) -> StatsSet {
// TODO(ngates): implement based on the encoded array
StatsSet::from(HashMap::new())
fn compute(&self, _stat: &Stat) -> VortexResult<StatsSet> {
Ok(StatsSet::default())
}
}
3 changes: 2 additions & 1 deletion vortex-ree/src/stats.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::REEArray;
use vortex::error::VortexResult;
use vortex::stats::{Stat, StatsCompute, StatsSet};

impl StatsCompute for REEArray {
fn compute(&self, _stat: &Stat) -> StatsSet {
fn compute(&self, _stat: &Stat) -> VortexResult<StatsSet> {
todo!()
}
}
7 changes: 4 additions & 3 deletions vortex-roaring/src/boolean/stats.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use vortex::array::Array;
use vortex::error::VortexResult;
use vortex::stats::{Stat, StatsCompute, StatsSet};

use crate::boolean::RoaringBoolArray;

impl StatsCompute for RoaringBoolArray {
fn compute(&self, stat: &Stat) -> StatsSet {
fn compute(&self, stat: &Stat) -> VortexResult<StatsSet> {
let cardinality = self.bitmap().cardinality() as usize;
if let Some(value) = match stat {
Stat::IsConstant => Some((cardinality == self.len() || cardinality == 0).into()),
Expand All @@ -26,9 +27,9 @@ impl StatsCompute for RoaringBoolArray {
Stat::NullCount => Some(0.into()),
_ => None,
} {
StatsSet::of(stat.clone(), value)
Ok(StatsSet::of(stat.clone(), value))
} else {
StatsSet::default()
Ok(StatsSet::default())
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions vortex-roaring/src/integer/stats.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use vortex::error::VortexResult;
use vortex::stats::{Stat, StatsCompute, StatsSet};

use crate::RoaringIntArray;

impl StatsCompute for RoaringIntArray {
fn compute(&self, stat: &Stat) -> StatsSet {
fn compute(&self, stat: &Stat) -> VortexResult<StatsSet> {
if let Some(value) = match stat {
Stat::IsConstant => Some((self.bitmap.cardinality() <= 1).into()),
Stat::IsSorted => Some(true.into()),
Expand All @@ -13,9 +14,9 @@ impl StatsCompute for RoaringIntArray {
Stat::NullCount => Some(0.into()),
_ => None,
} {
StatsSet::of(stat.clone(), value)
Ok(StatsSet::of(stat.clone(), value))
} else {
StatsSet::default()
Ok(StatsSet::default())
}
}
}
5 changes: 3 additions & 2 deletions vortex-zigzag/src/stats.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::collections::HashMap;
use vortex::error::VortexResult;

use vortex::stats::{Stat, StatsCompute, StatsSet};

use crate::zigzag::ZigZagArray;

impl StatsCompute for ZigZagArray {
fn compute(&self, _stat: &Stat) -> StatsSet {
fn compute(&self, _stat: &Stat) -> VortexResult<StatsSet> {
// TODO(ngates): implement based on the encoded array
StatsSet::from(HashMap::new())
Ok(StatsSet::from(HashMap::new()))
}
}
11 changes: 6 additions & 5 deletions vortex/src/array/bool/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ use std::collections::HashMap;

use crate::array::bool::BoolArray;
use crate::array::Array;
use crate::error::VortexResult;
use crate::stats::{Stat, StatsCompute, StatsSet};

impl StatsCompute for BoolArray {
fn compute(&self, _stat: &Stat) -> StatsSet {
fn compute(&self, _stat: &Stat) -> VortexResult<StatsSet> {
if self.len() == 0 {
return StatsSet::from(HashMap::from([
return Ok(StatsSet::from(HashMap::from([
(Stat::TrueCount, 0.into()),
(Stat::RunCount, 0.into()),
]));
])));
}

let mut prev_bit = self.buffer().value(0);
Expand All @@ -28,7 +29,7 @@ impl StatsCompute for BoolArray {
}
run_count += 1;

StatsSet::from(HashMap::from([
Ok(StatsSet::from(HashMap::from([
(Stat::Min, (true_count == self.len()).into()),
(Stat::Max, (true_count > 0).into()),
(
Expand All @@ -37,6 +38,6 @@ impl StatsCompute for BoolArray {
),
(Stat::RunCount, run_count.into()),
(Stat::TrueCount, true_count.into()),
]))
])))
}
}
8 changes: 5 additions & 3 deletions vortex/src/array/chunked/stats.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::array::chunked::ChunkedArray;
use crate::error::VortexResult;
use crate::stats::{Stat, StatsCompute, StatsSet};

impl StatsCompute for ChunkedArray {
fn compute(&self, stat: &Stat) -> StatsSet {
self.chunks()
fn compute(&self, stat: &Stat) -> VortexResult<StatsSet> {
Ok(self
.chunks()
.iter()
.map(|c| {
let s = c.stats();
Expand All @@ -14,6 +16,6 @@ impl StatsCompute for ChunkedArray {
.fold(StatsSet::new(), |mut acc, x| {
acc.merge(&x);
acc
})
}))
}
}
6 changes: 4 additions & 2 deletions vortex/src/array/constant/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ use std::collections::HashMap;
use crate::array::constant::ConstantArray;
use crate::array::Array;
use crate::dtype::{DType, Nullability};
use crate::error::VortexResult;
use crate::scalar::{BoolScalar, PScalar, Scalar};
use crate::stats::{Stat, StatsCompute, StatsSet};

impl StatsCompute for ConstantArray {
fn compute(&self, _stat: &Stat) -> StatsSet {
fn compute(&self, _stat: &Stat) -> VortexResult<StatsSet> {
let mut m = HashMap::from([
(Stat::Max, dyn_clone::clone_box(self.scalar())),
(Stat::Min, dyn_clone::clone_box(self.scalar())),
Expand All @@ -31,6 +32,7 @@ impl StatsCompute for ConstantArray {
.boxed(),
);
}
StatsSet::from(m)

Ok(StatsSet::from(m))
}
}
21 changes: 12 additions & 9 deletions vortex/src/array/primitive/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ use half::f16;
use num_traits::{NumCast, PrimInt};

use crate::array::primitive::PrimitiveArray;
use crate::error::VortexResult;
use crate::ptype::match_each_native_ptype;
use crate::scalar::ListScalarVec;
use crate::scalar::Scalar;
use crate::stats::{Stat, StatsCompute, StatsSet};

impl StatsCompute for PrimitiveArray {
fn compute(&self, stat: &Stat) -> StatsSet {
fn compute(&self, stat: &Stat) -> VortexResult<StatsSet> {
match_each_native_ptype!(self.ptype(), |$P| {
WrappedPrimitive::<$P>::new(self).compute(stat)
})
Expand All @@ -30,7 +31,7 @@ impl<'a, P> WrappedPrimitive<'a, P> {
macro_rules! integer_stats {
($T:ty) => {
impl StatsCompute for WrappedPrimitive<'_, $T> {
fn compute(&self, _stat: &Stat) -> StatsSet {
fn compute(&self, _stat: &Stat) -> VortexResult<StatsSet> {
integer_stats::<$T>(self.0)
}
}
Expand All @@ -49,7 +50,7 @@ integer_stats!(u64);
macro_rules! float_stats {
($T:ty) => {
impl StatsCompute for WrappedPrimitive<'_, $T> {
fn compute(&self, _stat: &Stat) -> StatsSet {
fn compute(&self, _stat: &Stat) -> VortexResult<StatsSet> {
float_stats::<$T>(self.0)
}
}
Expand All @@ -60,7 +61,9 @@ float_stats!(f16);
float_stats!(f32);
float_stats!(f64);

fn integer_stats<T: ArrowNativeType + NumCast + PrimInt>(array: &PrimitiveArray) -> StatsSet
fn integer_stats<T: ArrowNativeType + NumCast + PrimInt>(
array: &PrimitiveArray,
) -> VortexResult<StatsSet>
where
Box<dyn Scalar>: From<T>,
{
Expand Down Expand Up @@ -97,18 +100,18 @@ where
}
run_count += 1;

StatsSet::from(HashMap::from([
Ok(StatsSet::from(HashMap::from([
(Stat::Min, min.into()),
(Stat::Max, max.into()),
(Stat::IsConstant, (min == max).into()),
(Stat::BitWidthFreq, ListScalarVec(bit_widths).into()),
(Stat::IsSorted, is_sorted.into()),
(Stat::IsStrictSorted, (is_sorted && is_strict_sorted).into()),
(Stat::RunCount, run_count.into()),
]))
])))
}

fn float_stats<T: ArrowNativeType + NumCast>(array: &PrimitiveArray) -> StatsSet
fn float_stats<T: ArrowNativeType + NumCast>(array: &PrimitiveArray) -> VortexResult<StatsSet>
where
Box<dyn Scalar>: From<T>,
{
Expand Down Expand Up @@ -136,13 +139,13 @@ where
}
run_count += 1;

StatsSet::from(HashMap::from([
Ok(StatsSet::from(HashMap::from([
(Stat::Min, min.into()),
(Stat::Max, max.into()),
(Stat::IsConstant, (min == max).into()),
(Stat::IsSorted, is_sorted.into()),
(Stat::RunCount, run_count.into()),
]))
])))
}

#[cfg(test)]
Expand Down
3 changes: 2 additions & 1 deletion vortex/src/array/sparse/stats.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::array::sparse::SparseArray;
use crate::error::VortexResult;
use crate::stats::{Stat, StatsCompute, StatsSet};

impl StatsCompute for SparseArray {
fn compute(&self, _stat: &Stat) -> StatsSet {
fn compute(&self, _stat: &Stat) -> VortexResult<StatsSet> {
todo!()
}
}
3 changes: 2 additions & 1 deletion vortex/src/array/struct_/stats.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::array::struct_::StructArray;
use crate::error::VortexResult;
use crate::stats::{Stat, StatsCompute, StatsSet};

impl StatsCompute for StructArray {
fn compute(&self, _stat: &Stat) -> StatsSet {
fn compute(&self, _stat: &Stat) -> VortexResult<StatsSet> {
todo!()
}
}
3 changes: 2 additions & 1 deletion vortex/src/array/typed/stats.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::array::typed::TypedArray;
use crate::error::VortexResult;
use crate::stats::{Stat, StatsCompute, StatsSet};

impl StatsCompute for TypedArray {
fn compute(&self, _stat: &Stat) -> StatsSet {
fn compute(&self, _stat: &Stat) -> VortexResult<StatsSet> {
todo!()
}
}
6 changes: 3 additions & 3 deletions vortex/src/array/varbin/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl<T> StatsCompute for T
where
T: BinaryArray + Array,
{
fn compute(&self, _stat: &Stat) -> StatsSet {
fn compute(&self, _stat: &Stat) -> VortexResult<StatsSet> {
let mut min = vec![0xFF];
let mut max = vec![0x00];
let mut is_constant = true;
Expand All @@ -41,7 +41,7 @@ where
runs += 1;
}

StatsSet::from(HashMap::from([
Ok(StatsSet::from(HashMap::from([
(
Stat::Min,
if matches!(self.dtype(), DType::Utf8(_)) {
Expand All @@ -61,7 +61,7 @@ where
(Stat::RunCount, runs.into()),
(Stat::IsSorted, is_sorted.into()),
(Stat::IsConstant, is_constant.into()),
]))
])))
}
}

Expand Down
Loading