parquet/file/
page_encoding_stats.rs1use crate::basic::{Encoding, PageType};
21use crate::errors::Result;
22use crate::format::{
23 Encoding as TEncoding, PageEncodingStats as TPageEncodingStats, PageType as TPageType,
24};
25
26#[derive(Clone, Debug, PartialEq, Eq)]
28pub struct PageEncodingStats {
29 pub page_type: PageType,
31 pub encoding: Encoding,
33 pub count: i32,
35}
36
37pub fn try_from_thrift(thrift_encoding_stats: &TPageEncodingStats) -> Result<PageEncodingStats> {
39 let page_type = PageType::try_from(thrift_encoding_stats.page_type)?;
40 let encoding = Encoding::try_from(thrift_encoding_stats.encoding)?;
41 let count = thrift_encoding_stats.count;
42
43 Ok(PageEncodingStats {
44 page_type,
45 encoding,
46 count,
47 })
48}
49
50pub fn to_thrift(encoding_stats: &PageEncodingStats) -> TPageEncodingStats {
52 let page_type = TPageType::from(encoding_stats.page_type);
53 let encoding = TEncoding::from(encoding_stats.encoding);
54 let count = encoding_stats.count;
55
56 TPageEncodingStats {
57 page_type,
58 encoding,
59 count,
60 }
61}
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66
67 #[test]
68 fn test_page_encoding_stats_from_thrift() {
69 let stats = PageEncodingStats {
70 page_type: PageType::DATA_PAGE,
71 encoding: Encoding::PLAIN,
72 count: 1,
73 };
74
75 assert_eq!(try_from_thrift(&to_thrift(&stats)).unwrap(), stats);
76 }
77}