vortex_dict/
stats.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use vortex::aliases::hash_map::HashMap;
use vortex::stats::{ArrayStatistics, ArrayStatisticsCompute, Stat, StatsSet};
use vortex_error::VortexResult;
use vortex_scalar::Scalar;

use crate::DictArray;

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

        if let Some(rc) = self.codes().statistics().compute(Stat::RunCount) {
            stats.insert(Stat::RunCount, rc);
        }
        if let Some(min) = self.values().statistics().compute(Stat::Min) {
            stats.insert(Stat::Min, min);
        }
        if let Some(max) = self.values().statistics().compute(Stat::Max) {
            stats.insert(Stat::Max, max);
        }
        if let Some(is_constant) = self.codes().statistics().compute(Stat::IsConstant) {
            stats.insert(Stat::IsConstant, is_constant);
        }
        if let Some(null_count) = self.codes().statistics().compute(Stat::NullCount) {
            stats.insert(Stat::NullCount, null_count);
        }

        // if dictionary is sorted
        if self
            .values()
            .statistics()
            .compute_is_sorted()
            .unwrap_or(false)
        {
            if let Some(codes_are_sorted) = self.codes().statistics().compute(Stat::IsSorted) {
                stats.insert(Stat::IsSorted, codes_are_sorted);
            }

            if let Some(codes_are_strict_sorted) =
                self.codes().statistics().compute(Stat::IsStrictSorted)
            {
                stats.insert(Stat::IsStrictSorted, codes_are_strict_sorted);
            }
        }

        Ok(StatsSet::from(stats))
    }
}