iceberg/puffin/mod.rs
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.
17
18//! Iceberg Puffin implementation.
19
20#![deny(missing_docs)]
21
22use crate::{Error, ErrorKind, Result};
23
24mod blob;
25pub use blob::{APACHE_DATASKETCHES_THETA_V1, Blob, DELETION_VECTOR_V1};
26
27pub use crate::compression::CompressionCodec;
28
29/// Compression codecs supported by the Puffin spec.
30const SUPPORTED_PUFFIN_CODECS: &[CompressionCodec] = &[
31 CompressionCodec::None,
32 CompressionCodec::Lz4,
33 CompressionCodec::Zstd,
34];
35
36/// Validates that the compression codec is supported for Puffin files.
37/// Returns an error if the codec is not supported.
38fn validate_puffin_compression(codec: CompressionCodec) -> Result<()> {
39 if !SUPPORTED_PUFFIN_CODECS.contains(&codec) {
40 let supported_names: Vec<String> = SUPPORTED_PUFFIN_CODECS
41 .iter()
42 .map(|c| format!("{c:?}"))
43 .collect();
44 return Err(Error::new(
45 ErrorKind::DataInvalid,
46 format!(
47 "Compression codec {codec:?} is not supported for Puffin files. Only {} are supported.",
48 supported_names.join(", ")
49 ),
50 ));
51 }
52 Ok(())
53}
54
55mod metadata;
56pub use metadata::{BlobMetadata, CREATED_BY_PROPERTY, FileMetadata};
57
58mod reader;
59pub use reader::PuffinReader;
60
61mod writer;
62pub use writer::PuffinWriter;
63
64#[cfg(test)]
65mod test_utils;
66
67#[cfg(test)]
68mod tests {
69 use super::*;
70
71 #[test]
72 fn test_puffin_codec_validation() {
73 // All codecs in SUPPORTED_PUFFIN_CODECS should be valid
74 for codec in SUPPORTED_PUFFIN_CODECS {
75 assert!(validate_puffin_compression(*codec).is_ok());
76 }
77
78 // Gzip should not be supported for Puffin files
79 assert!(validate_puffin_compression(CompressionCodec::Gzip).is_err());
80 }
81}