-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy pathmod.rs
More file actions
64 lines (55 loc) · 1.83 KB
/
Copy pathmod.rs
File metadata and controls
64 lines (55 loc) · 1.83 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
//! Traits and utilities to compute and access array statistics.
use arrow_buffer::BooleanBufferBuilder;
use arrow_buffer::MutableBuffer;
use arrow_buffer::bit_iterator::BitIterator;
use enum_iterator::last;
pub use expr::stat;
pub use stats_set::*;
mod array;
pub mod expr;
pub mod flatbuffers;
mod stats_set;
pub use array::*;
use vortex_error::VortexExpect;
use crate::expr::stats::Stat;
/// Statistics that are used for pruning files (i.e., we want to ensure they are computed when compressing/writing).
/// Sum is included for boolean arrays.
pub const PRUNING_STATS: &[Stat] = &[
Stat::Min,
Stat::Max,
Stat::Sum,
Stat::NullCount,
Stat::NaNCount,
];
pub fn as_stat_bitset_bytes(stats: &[Stat]) -> Vec<u8> {
let max_stat = u8::from(last::<Stat>().vortex_expect("last stat")) as usize + 1;
// TODO(ngates): use vortex-buffer::BitBuffer
let mut stat_bitset = BooleanBufferBuilder::new_from_buffer(
MutableBuffer::from_len_zeroed(max_stat.div_ceil(8)),
max_stat,
);
for stat in stats {
stat_bitset.set_bit(u8::from(*stat) as usize, true);
}
stat_bitset
.finish()
.into_inner()
.into_vec()
.unwrap_or_else(|b| b.to_vec())
}
pub fn stats_from_bitset_bytes(bytes: &[u8]) -> Vec<Stat> {
BitIterator::new(bytes, 0, bytes.len() * 8)
.enumerate()
.filter_map(|(i, b)| b.then_some(i))
// Filter out indices failing conversion, these are stats written by newer version of library
.filter_map(|i| {
let Ok(stat) = u8::try_from(i) else {
tracing::debug!("invalid stat encountered: {i}");
return None;
};
Stat::try_from(stat).ok()
})
.collect::<Vec<_>>()
}