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