|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +#pragma once |
| 21 | + |
| 22 | +/// \file iceberg/puffin/file_metadata.h |
| 23 | +/// Data structures for Puffin files. |
| 24 | + |
| 25 | +#include <cstdint> |
| 26 | +#include <optional> |
| 27 | +#include <string> |
| 28 | +#include <string_view> |
| 29 | +#include <unordered_map> |
| 30 | +#include <vector> |
| 31 | + |
| 32 | +#include "iceberg/iceberg_export.h" |
| 33 | +#include "iceberg/result.h" |
| 34 | + |
| 35 | +namespace iceberg::puffin { |
| 36 | + |
| 37 | +/// \brief Compression codecs supported by Puffin files. |
| 38 | +enum class PuffinCompressionCodec { |
| 39 | + /// \brief No compression |
| 40 | + kNone, |
| 41 | + /// \brief LZ4 single compression frame with content size present |
| 42 | + kLz4, |
| 43 | + /// \brief Zstandard single compression frame with content size present |
| 44 | + kZstd, |
| 45 | +}; |
| 46 | + |
| 47 | +/// \brief Get the codec name for a compression codec. |
| 48 | +ICEBERG_EXPORT std::string_view CodecName(PuffinCompressionCodec codec); |
| 49 | + |
| 50 | +/// \brief Get the compression codec from a codec name. |
| 51 | +ICEBERG_EXPORT Result<PuffinCompressionCodec> PuffinCompressionCodecFromName( |
| 52 | + std::string_view codec_name); |
| 53 | + |
| 54 | +/// \brief Returns a string representation of a PuffinCompressionCodec. |
| 55 | +ICEBERG_EXPORT std::string ToString(PuffinCompressionCodec codec); |
| 56 | + |
| 57 | +/// \brief Standard blob types defined by the Iceberg specification. |
| 58 | +struct StandardBlobTypes { |
| 59 | + /// \brief A serialized form of a "compact" Theta sketch produced by the |
| 60 | + /// Apache DataSketches library. |
| 61 | + static constexpr std::string_view kApacheDatasketchesThetaV1 = |
| 62 | + "apache-datasketches-theta-v1"; |
| 63 | + |
| 64 | + /// \brief A serialized deletion vector according to the Iceberg spec. |
| 65 | + static constexpr std::string_view kDeletionVectorV1 = "deletion-vector-v1"; |
| 66 | +}; |
| 67 | + |
| 68 | +/// \brief Standard file-level properties for Puffin files. |
| 69 | +struct StandardPuffinProperties { |
| 70 | + /// \brief Human-readable identification of the application writing the file, |
| 71 | + /// along with its version. |
| 72 | + static constexpr std::string_view kCreatedBy = "created-by"; |
| 73 | +}; |
| 74 | + |
| 75 | +/// \brief A blob in a Puffin file. |
| 76 | +struct ICEBERG_EXPORT Blob { |
| 77 | + /// \brief Type of the blob. See StandardBlobTypes for known types. |
| 78 | + std::string type; |
| 79 | + /// \brief List of field IDs the blob was computed for. |
| 80 | + std::vector<int32_t> input_fields; |
| 81 | + /// \brief ID of the Iceberg table's snapshot the blob was computed from. |
| 82 | + int64_t snapshot_id; |
| 83 | + /// \brief Sequence number of the Iceberg table's snapshot the blob was computed from. |
| 84 | + int64_t sequence_number; |
| 85 | + /// \brief The uncompressed blob data. |
| 86 | + std::vector<uint8_t> data; |
| 87 | + /// \brief Requested compression codec. If not set, the writer's default will be used. |
| 88 | + std::optional<PuffinCompressionCodec> requested_compression; |
| 89 | + /// \brief Additional properties of the blob. |
| 90 | + std::unordered_map<std::string, std::string> properties; |
| 91 | + |
| 92 | + /// \brief Compare two Blobs for equality. |
| 93 | + friend bool operator==(const Blob& lhs, const Blob& rhs) = default; |
| 94 | +}; |
| 95 | + |
| 96 | +/// \brief Returns a string representation of a Blob. |
| 97 | +ICEBERG_EXPORT std::string ToString(const Blob& blob); |
| 98 | + |
| 99 | +/// \brief Metadata about a blob stored in a Puffin file. |
| 100 | +struct ICEBERG_EXPORT BlobMetadata { |
| 101 | + /// \brief Type of the blob. See StandardBlobTypes for known types. |
| 102 | + std::string type; |
| 103 | + /// \brief List of field IDs the blob was computed for. |
| 104 | + std::vector<int32_t> input_fields; |
| 105 | + /// \brief ID of the Iceberg table's snapshot the blob was computed from. |
| 106 | + int64_t snapshot_id; |
| 107 | + /// \brief Sequence number of the Iceberg table's snapshot the blob was computed from. |
| 108 | + int64_t sequence_number; |
| 109 | + /// \brief Offset in the file where the blob data starts. |
| 110 | + int64_t offset; |
| 111 | + /// \brief Length of the blob data in the file. |
| 112 | + int64_t length; |
| 113 | + /// \brief Compression codec name (e.g. "lz4", "zstd"), or empty if not compressed. |
| 114 | + std::string compression_codec; |
| 115 | + /// \brief Additional properties of the blob. |
| 116 | + std::unordered_map<std::string, std::string> properties; |
| 117 | + |
| 118 | + /// \brief Compare two BlobMetadatas for equality. |
| 119 | + friend bool operator==(const BlobMetadata& lhs, const BlobMetadata& rhs) = default; |
| 120 | +}; |
| 121 | + |
| 122 | +/// \brief Returns a string representation of a BlobMetadata. |
| 123 | +ICEBERG_EXPORT std::string ToString(const BlobMetadata& blob_metadata); |
| 124 | + |
| 125 | +/// \brief Metadata about a Puffin file. |
| 126 | +struct ICEBERG_EXPORT FileMetadata { |
| 127 | + /// \brief List of blob metadata for all blobs in the file. |
| 128 | + std::vector<BlobMetadata> blobs; |
| 129 | + /// \brief File-level properties. |
| 130 | + std::unordered_map<std::string, std::string> properties; |
| 131 | + |
| 132 | + /// \brief Compare two FileMetadatas for equality. |
| 133 | + friend bool operator==(const FileMetadata& lhs, const FileMetadata& rhs) = default; |
| 134 | +}; |
| 135 | + |
| 136 | +/// \brief Returns a string representation of a FileMetadata. |
| 137 | +ICEBERG_EXPORT std::string ToString(const FileMetadata& file_metadata); |
| 138 | + |
| 139 | +} // namespace iceberg::puffin |
0 commit comments