Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-parquet/src/parquet/statistics/boolean.rs
6940 views
1
use polars_parquet_format::Statistics as ParquetStatistics;
2
3
use crate::parquet::error::{ParquetError, ParquetResult};
4
5
#[derive(Debug, Clone, PartialEq)]
6
pub struct BooleanStatistics {
7
pub null_count: Option<i64>,
8
pub distinct_count: Option<i64>,
9
pub max_value: Option<bool>,
10
pub min_value: Option<bool>,
11
}
12
13
impl BooleanStatistics {
14
pub fn deserialize(v: &ParquetStatistics) -> ParquetResult<Self> {
15
if let Some(ref v) = v.max_value {
16
if v.len() != size_of::<bool>() {
17
return Err(ParquetError::oos(
18
"The max_value of statistics MUST be plain encoded",
19
));
20
}
21
};
22
if let Some(ref v) = v.min_value {
23
if v.len() != size_of::<bool>() {
24
return Err(ParquetError::oos(
25
"The min_value of statistics MUST be plain encoded",
26
));
27
}
28
};
29
30
Ok(Self {
31
null_count: v.null_count,
32
distinct_count: v.distinct_count,
33
max_value: v
34
.max_value
35
.as_ref()
36
.and_then(|x| x.first())
37
.map(|x| *x != 0),
38
min_value: v
39
.min_value
40
.as_ref()
41
.and_then(|x| x.first())
42
.map(|x| *x != 0),
43
})
44
}
45
46
pub fn serialize(&self) -> ParquetStatistics {
47
ParquetStatistics {
48
null_count: self.null_count,
49
distinct_count: self.distinct_count,
50
max_value: self.max_value.map(|x| vec![x as u8]),
51
min_value: self.min_value.map(|x| vec![x as u8]),
52
max: None,
53
min: None,
54
is_max_value_exact: None,
55
is_min_value_exact: None,
56
}
57
}
58
}
59
60