iceberg/puffin/
blob.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
18use std::collections::HashMap;
19
20use typed_builder::TypedBuilder;
21
22/// A serialized form of a "compact" Theta sketch produced by the Apache DataSketches library.
23pub const APACHE_DATASKETCHES_THETA_V1: &str = "apache-datasketches-theta-v1";
24/// A serialized form of a deletion vector.
25pub const DELETION_VECTOR_V1: &str = "deletion-vector-v1";
26
27/// The blob
28#[derive(Debug, PartialEq, Clone, TypedBuilder)]
29pub struct Blob {
30    pub(crate) r#type: String,
31    pub(crate) fields: Vec<i32>,
32    pub(crate) snapshot_id: i64,
33    pub(crate) sequence_number: i64,
34    pub(crate) data: Vec<u8>,
35    pub(crate) properties: HashMap<String, String>,
36}
37
38impl Blob {
39    #[inline]
40    /// See blob types: https://iceberg.apache.org/puffin-spec/#blob-types
41    pub fn blob_type(&self) -> &str {
42        &self.r#type
43    }
44
45    #[inline]
46    /// List of field IDs the blob was computed for; the order of items is used to compute sketches stored in the blob.
47    pub fn fields(&self) -> &[i32] {
48        &self.fields
49    }
50
51    #[inline]
52    /// ID of the Iceberg table's snapshot the blob was computed from
53    pub fn snapshot_id(&self) -> i64 {
54        self.snapshot_id
55    }
56
57    #[inline]
58    /// Sequence number of the Iceberg table's snapshot the blob was computed from
59    pub fn sequence_number(&self) -> i64 {
60        self.sequence_number
61    }
62
63    #[inline]
64    /// The uncompressed blob data
65    pub fn data(&self) -> &[u8] {
66        &self.data
67    }
68
69    #[inline]
70    /// Arbitrary meta-information about the blob
71    pub fn properties(&self) -> &HashMap<String, String> {
72        &self.properties
73    }
74}