vortex_dict/
stats.rs

1use vortex_array::Array;
2use vortex_array::stats::{Precision, Stat, StatsSet};
3use vortex_array::vtable::StatisticsVTable;
4use vortex_error::VortexResult;
5
6use crate::{DictArray, DictEncoding};
7
8impl StatisticsVTable<&DictArray> for DictEncoding {
9    fn compute_statistics(&self, array: &DictArray, stat: Stat) -> VortexResult<StatsSet> {
10        let mut stats = StatsSet::default();
11
12        match stat {
13            Stat::Min => {
14                if let Some(min) = array.values().statistics().compute_stat(Stat::Min)? {
15                    stats.set(Stat::Min, Precision::exact(min));
16                }
17            }
18            Stat::Max => {
19                if let Some(max) = array.values().statistics().compute_stat(Stat::Max)? {
20                    stats.set(Stat::Max, Precision::exact(max));
21                }
22            }
23            Stat::IsConstant => {
24                if let Some(is_constant) = array.codes().statistics().compute_is_constant() {
25                    stats.set(Stat::IsConstant, Precision::exact(is_constant));
26                }
27            }
28            Stat::NullCount => {
29                if let Some(null_count) =
30                    array.codes().statistics().compute_stat(Stat::NullCount)?
31                {
32                    stats.set(Stat::NullCount, Precision::exact(null_count));
33                }
34            }
35            Stat::IsSorted | Stat::IsStrictSorted => {
36                // if dictionary is sorted
37                if array
38                    .values()
39                    .statistics()
40                    .compute_is_sorted()
41                    .unwrap_or(false)
42                {
43                    if let Some(codes_are_sorted) =
44                        array.codes().statistics().compute_stat(Stat::IsSorted)?
45                    {
46                        stats.set(Stat::IsSorted, Precision::exact(codes_are_sorted));
47                    }
48
49                    if let Some(codes_are_strict_sorted) = array
50                        .codes()
51                        .statistics()
52                        .compute_stat(Stat::IsStrictSorted)?
53                    {
54                        stats.set(
55                            Stat::IsStrictSorted,
56                            Precision::exact(codes_are_strict_sorted),
57                        );
58                    }
59                }
60            }
61            _ => {}
62        }
63
64        Ok(stats)
65    }
66}