Skip to main content

mito2/cache/
cache_size.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Cache size of different cache value.
16
17use parquet::file::metadata::ParquetMetaData;
18
19/// Returns estimated size of [ParquetMetaData].
20pub fn parquet_meta_size(meta: &ParquetMetaData) -> usize {
21    meta.memory_size()
22}
23
24#[cfg(test)]
25mod tests {
26    use std::sync::Arc;
27
28    use parquet::basic::{Repetition, Type as PhysicalType};
29    use parquet::file::metadata::{ColumnIndexBuilder, FileMetaData, ParquetMetaDataBuilder};
30    use parquet::schema::types::{SchemaDescriptor, Type as SchemaType};
31
32    use super::*;
33
34    #[test]
35    fn parquet_meta_size_counts_byte_array_column_index_buffers() {
36        let field = Arc::new(
37            SchemaType::primitive_type_builder("tag", PhysicalType::BYTE_ARRAY)
38                .with_repetition(Repetition::OPTIONAL)
39                .build()
40                .unwrap(),
41        );
42        let schema = Arc::new(
43            SchemaType::group_type_builder("schema")
44                .with_fields(vec![field])
45                .build()
46                .unwrap(),
47        );
48        let schema_descr = Arc::new(SchemaDescriptor::new(schema));
49        let file_metadata = FileMetaData::new(2, 3, None, None, schema_descr, None);
50
51        let mut column_index = ColumnIndexBuilder::new(PhysicalType::BYTE_ARRAY);
52        for page in 0..3u8 {
53            column_index.append(false, vec![page; 4096], vec![page + 1; 4096], 0);
54        }
55        let metadata = ParquetMetaDataBuilder::new(file_metadata)
56            .set_column_index(Some(vec![vec![column_index.build().unwrap()]]))
57            .build();
58
59        let min_max_bytes = 3 * 4096 * 2;
60        assert!(
61            parquet_meta_size(&metadata) >= min_max_bytes,
62            "metadata size should include the byte-array page-index min/max buffers"
63        );
64    }
65}