Skip to main content

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::Result;
23use crate::error::invalid_data;
24
25mod blob;
26pub use blob::{APACHE_DATASKETCHES_THETA_V1, Blob, DELETION_VECTOR_V1};
27
28pub use crate::compression::CompressionCodec;
29
30/// Validates that the compression codec is supported for Puffin files.
31/// Returns an error if the codec is not supported.
32fn validate_puffin_compression(codec: CompressionCodec) -> Result<()> {
33    match codec {
34        CompressionCodec::None | CompressionCodec::Lz4 | CompressionCodec::Zstd(_) => Ok(()),
35        other => Err(invalid_data!(
36            "Compression codec {} is not supported for Puffin files. Only {}, {}, and {} are supported.",
37            other.name(),
38            CompressionCodec::None.name(),
39            CompressionCodec::Lz4.name(),
40            CompressionCodec::zstd_default().name()
41        )),
42    }
43}
44
45mod metadata;
46pub use metadata::{BlobMetadata, CREATED_BY_PROPERTY, FileMetadata};
47
48mod reader;
49pub use reader::PuffinReader;
50
51mod writer;
52pub use writer::PuffinWriter;
53
54#[cfg(test)]
55mod test_utils;
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_puffin_codec_validation() {
63        // Supported codecs
64        assert!(validate_puffin_compression(CompressionCodec::None).is_ok());
65        assert!(validate_puffin_compression(CompressionCodec::Lz4).is_ok());
66        assert!(validate_puffin_compression(CompressionCodec::zstd_default()).is_ok());
67        assert!(validate_puffin_compression(CompressionCodec::Zstd(5)).is_ok());
68
69        // Unsupported codecs
70        assert!(validate_puffin_compression(CompressionCodec::gzip_default()).is_err());
71    }
72}