parquet/file/
column_crypto_metadata.rs1use std::io::Write;
8
9use crate::errors::{ParquetError, Result};
10use crate::file::metadata::HeapSize;
11use crate::parquet_thrift::{
12 ElementType, FieldType, ReadThrift, ThriftCompactInputProtocol, ThriftCompactOutputProtocol,
13 WriteThrift, WriteThriftField, read_thrift_vec,
14};
15use crate::{thrift_struct, thrift_union};
16
17thrift_struct!(
21pub struct EncryptionWithColumnKey {
23 1: required list<string> path_in_schema
25
26 2: optional binary key_metadata
28}
29);
30
31impl HeapSize for EncryptionWithColumnKey {
32 fn heap_size(&self) -> usize {
33 self.path_in_schema.heap_size() + self.key_metadata.heap_size()
34 }
35}
36
37thrift_union!(
38union ColumnCryptoMetaData {
40 1: ENCRYPTION_WITH_FOOTER_KEY
41 2: (EncryptionWithColumnKey) ENCRYPTION_WITH_COLUMN_KEY
42}
43);
44
45impl HeapSize for ColumnCryptoMetaData {
46 fn heap_size(&self) -> usize {
47 match self {
48 Self::ENCRYPTION_WITH_FOOTER_KEY => 0,
49 Self::ENCRYPTION_WITH_COLUMN_KEY(path) => path.heap_size(),
50 }
51 }
52}
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57 use crate::parquet_thrift::tests::test_roundtrip;
58
59 #[test]
60 fn test_column_crypto_roundtrip() {
61 test_roundtrip(ColumnCryptoMetaData::ENCRYPTION_WITH_FOOTER_KEY);
62
63 let path_in_schema = vec!["foo".to_owned(), "bar".to_owned(), "really".to_owned()];
64 let key_metadata = vec![1u8; 32];
65 test_roundtrip(ColumnCryptoMetaData::ENCRYPTION_WITH_COLUMN_KEY(
66 EncryptionWithColumnKey {
67 path_in_schema: path_in_schema.clone(),
68 key_metadata: None,
69 },
70 ));
71 test_roundtrip(ColumnCryptoMetaData::ENCRYPTION_WITH_COLUMN_KEY(
72 EncryptionWithColumnKey {
73 path_in_schema,
74 key_metadata: Some(key_metadata),
75 },
76 ));
77 }
78}