1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
1718//! Per-page encoding information.
1920use crate::basic::{Encoding, PageType};
21use crate::errors::Result;
22use crate::format::{
23 Encoding as TEncoding, PageEncodingStats as TPageEncodingStats, PageType as TPageType,
24};
2526/// PageEncodingStats for a column chunk and data page.
27#[derive(Clone, Debug, PartialEq, Eq)]
28pub struct PageEncodingStats {
29/// the page type (data/dic/...)
30pub page_type: PageType,
31/// encoding of the page
32pub encoding: Encoding,
33/// number of pages of this type with this encoding
34pub count: i32,
35}
3637/// Converts Thrift definition into `PageEncodingStats`.
38pub fn try_from_thrift(thrift_encoding_stats: &TPageEncodingStats) -> Result<PageEncodingStats> {
39let page_type = PageType::try_from(thrift_encoding_stats.page_type)?;
40let encoding = Encoding::try_from(thrift_encoding_stats.encoding)?;
41let count = thrift_encoding_stats.count;
4243Ok(PageEncodingStats {
44 page_type,
45 encoding,
46 count,
47 })
48}
4950/// Converts `PageEncodingStats` into Thrift definition.
51pub fn to_thrift(encoding_stats: &PageEncodingStats) -> TPageEncodingStats {
52let page_type = TPageType::from(encoding_stats.page_type);
53let encoding = TEncoding::from(encoding_stats.encoding);
54let count = encoding_stats.count;
5556 TPageEncodingStats {
57 page_type,
58 encoding,
59 count,
60 }
61}
6263#[cfg(test)]
64mod tests {
65use super::*;
6667#[test]
68fn test_page_encoding_stats_from_thrift() {
69let stats = PageEncodingStats {
70 page_type: PageType::DATA_PAGE,
71 encoding: Encoding::PLAIN,
72 count: 1,
73 };
7475assert_eq!(try_from_thrift(&to_thrift(&stats)).unwrap(), stats);
76 }
77}