Skip to content

Commit 80847ef

Browse files
committed
fewer
Signed-off-by: Robert Kruszewski <github@robertk.io>
1 parent 83b431f commit 80847ef

2 files changed

Lines changed: 12 additions & 27 deletions

File tree

vortex-compressor/src/stats/bool.rs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
//! Bool compression statistics.
55
66
use vortex_array::arrays::BoolArray;
7-
use vortex_error::VortexExpect;
87
use vortex_error::VortexResult;
98
use vortex_mask::AllOr;
109

11-
use super::GenerateStatsOptions;
12-
1310
/// Array of booleans and relevant stats for compression.
1411
#[derive(Clone, Debug)]
1512
pub struct BoolStats {
@@ -24,24 +21,12 @@ pub struct BoolStats {
2421
}
2522

2623
impl BoolStats {
27-
/// Generates stats with default options.
28-
pub fn generate(input: &BoolArray) -> Self {
29-
Self::generate_opts(input, GenerateStatsOptions::default())
30-
}
31-
32-
/// Generates stats with provided options.
33-
///
34-
/// For booleans, all stats are cheap to compute so the options are currently ignored.
35-
pub fn generate_opts(input: &BoolArray, opts: GenerateStatsOptions) -> Self {
36-
Self::generate_opts_fallible(input, opts)
37-
.vortex_expect("BoolStats::generate_opts should not fail")
38-
}
39-
4024
/// Generates stats, returning an error on failure.
41-
fn generate_opts_fallible(
42-
input: &BoolArray,
43-
_opts: GenerateStatsOptions,
44-
) -> VortexResult<Self> {
25+
///
26+
/// # Errors
27+
///
28+
/// Returns an error if getting validity mask fails or values exceed `u32` bounds.
29+
pub fn generate(input: &BoolArray) -> VortexResult<Self> {
4530
if input.is_empty() {
4631
return Ok(Self {
4732
src: input.clone(),
@@ -125,7 +110,7 @@ mod tests {
125110
BitBuffer::from(vec![true, true, true]),
126111
Validity::NonNullable,
127112
);
128-
let stats = BoolStats::generate(&array);
113+
let stats = BoolStats::generate(&array)?;
129114
assert_eq!(stats.value_count, 3);
130115
assert_eq!(stats.null_count, 0);
131116
assert_eq!(stats.true_count, 3);
@@ -139,7 +124,7 @@ mod tests {
139124
BitBuffer::from(vec![false, false, false]),
140125
Validity::NonNullable,
141126
);
142-
let stats = BoolStats::generate(&array);
127+
let stats = BoolStats::generate(&array)?;
143128
assert_eq!(stats.value_count, 3);
144129
assert_eq!(stats.null_count, 0);
145130
assert_eq!(stats.true_count, 0);
@@ -153,7 +138,7 @@ mod tests {
153138
BitBuffer::from(vec![true, false, true]),
154139
Validity::NonNullable,
155140
);
156-
let stats = BoolStats::generate(&array);
141+
let stats = BoolStats::generate(&array)?;
157142
assert_eq!(stats.value_count, 3);
158143
assert_eq!(stats.null_count, 0);
159144
assert_eq!(stats.true_count, 2);
@@ -167,7 +152,7 @@ mod tests {
167152
BitBuffer::from(vec![true, false, true]),
168153
Validity::from_iter([true, false, true]),
169154
);
170-
let stats = BoolStats::generate(&array);
155+
let stats = BoolStats::generate(&array)?;
171156
assert_eq!(stats.value_count, 2);
172157
assert_eq!(stats.null_count, 1);
173158
assert_eq!(stats.true_count, 2);

vortex-compressor/src/stats/cache.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ impl ArrayAndStats {
100100
/// Returns bool stats, generating them lazily on first access.
101101
pub fn bool_stats(&mut self) -> &BoolStats {
102102
let array = self.array.clone();
103-
let opts = self.opts;
104103

105-
self.cache
106-
.get_or_insert_with::<BoolStats>(|| BoolStats::generate_opts(&array.to_bool(), opts))
104+
self.cache.get_or_insert_with::<BoolStats>(|| {
105+
BoolStats::generate(&array.to_bool()).vortex_expect("BoolStats shouldn't fail")
106+
})
107107
}
108108

109109
/// Returns integer stats, generating them lazily on first access.

0 commit comments

Comments
 (0)