iceberg-cpp
Loading...
Searching...
No Matches
manifest_list.h
Go to the documentation of this file.
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
23
24#include <cstdint>
25#include <optional>
26#include <string>
27#include <string_view>
28#include <utility>
29
31#include "iceberg/constants.h"
34#include "iceberg/result.h"
37#include "iceberg/type.h"
38
39namespace iceberg {
40
44struct ICEBERG_EXPORT PartitionFieldSummary {
47 bool contains_null = true;
50 std::optional<bool> contains_nan;
54 std::optional<std::vector<uint8_t>> lower_bound;
58 std::optional<std::vector<uint8_t>> upper_bound;
59
60 inline static const SchemaField kContainsNull =
61 SchemaField::MakeRequired(509, "contains_null", iceberg::boolean(),
62 "True if any file has a null partition value");
63 inline static const SchemaField kContainsNaN =
64 SchemaField::MakeOptional(518, "contains_nan", iceberg::boolean(),
65 "True if any file has a nan partition value");
66 inline static const SchemaField kLowerBound = SchemaField::MakeOptional(
67 510, "lower_bound", iceberg::binary(), "Partition lower bound for all files");
68 inline static const SchemaField kUpperBound = SchemaField::MakeOptional(
69 511, "upper_bound", iceberg::binary(), "Partition upper bound for all files");
70
71 bool operator==(const PartitionFieldSummary& other) const = default;
72
73 static const std::shared_ptr<StructType>& Type();
74};
75
78enum class ManifestContent {
80 kData = 0,
82 kDeletes = 1,
83};
84
86struct ICEBERG_EXPORT ManifestFile {
89 std::string manifest_path;
92 int64_t manifest_length = 0;
96 int32_t partition_spec_id = PartitionSpec::kInitialSpecId;
100 ManifestContent content = ManifestContent::kData;
104 int64_t sequence_number = TableMetadata::kInitialSequenceNumber;
108 int64_t min_sequence_number = TableMetadata::kInitialSequenceNumber;
113 std::optional<int64_t> added_snapshot_id;
117 std::optional<int32_t> added_files_count;
121 std::optional<int32_t> existing_files_count;
125 std::optional<int32_t> deleted_files_count;
129 std::optional<int64_t> added_rows_count;
133 std::optional<int64_t> existing_rows_count;
137 std::optional<int64_t> deleted_rows_count;
142 std::vector<PartitionFieldSummary> partitions;
145 std::vector<uint8_t> key_metadata;
148 std::optional<int64_t> first_row_id;
149
151 bool has_added_files() const { return added_files_count.value_or(1) > 0; }
152
154 bool has_existing_files() const { return existing_files_count.value_or(1) > 0; }
155
157 bool has_deleted_files() const { return deleted_files_count.value_or(1) > 0; }
158
159 static constexpr int32_t kManifestPathFieldId = 500;
160 inline static const SchemaField kManifestPath = SchemaField::MakeRequired(
161 kManifestPathFieldId, "manifest_path", string(), "Location URI with FS scheme");
162
163 static constexpr int32_t kManifestLengthFieldId = 501;
164 inline static const SchemaField kManifestLength = SchemaField::MakeRequired(
165 kManifestLengthFieldId, "manifest_length", int64(), "Total file size in bytes");
166
167 static constexpr int32_t kPartitionSpecIdFieldId = 502;
168 inline static const SchemaField kPartitionSpecId = SchemaField::MakeRequired(
169 kPartitionSpecIdFieldId, "partition_spec_id", int32(), "Spec ID used to write");
170
171 static constexpr int32_t kContentFieldId = 517;
172 inline static const SchemaField kContent = SchemaField::MakeOptional(
173 kContentFieldId, "content", int32(), "Contents of the manifest: 0=data, 1=deletes");
174
175 static constexpr int32_t kSequenceNumberFieldId = 515;
176 inline static const SchemaField kSequenceNumber =
177 SchemaField::MakeOptional(kSequenceNumberFieldId, "sequence_number", int64(),
178 "Sequence number when the manifest was added");
179
180 static constexpr int32_t kMinSequenceNumberFieldId = 516;
181 inline static const SchemaField kMinSequenceNumber =
182 SchemaField::MakeOptional(kMinSequenceNumberFieldId, "min_sequence_number", int64(),
183 "Lowest sequence number in the manifest");
184
185 static constexpr int32_t kAddedSnapshotIdFieldId = 503;
186 inline static const SchemaField kAddedSnapshotId =
187 SchemaField::MakeRequired(kAddedSnapshotIdFieldId, "added_snapshot_id", int64(),
188 "Snapshot ID that added the manifest");
189
190 static constexpr int32_t kAddedFilesCountFieldId = 504;
191 inline static const SchemaField kAddedFilesCount = SchemaField::MakeOptional(
192 kAddedFilesCountFieldId, "added_files_count", int32(), "Added entry count");
193
194 static constexpr int32_t kExistingFilesCountFieldId = 505;
195 inline static const SchemaField kExistingFilesCount =
196 SchemaField::MakeOptional(kExistingFilesCountFieldId, "existing_files_count",
197 int32(), "Existing entry count");
198
199 static constexpr int32_t kDeletedFilesCountFieldId = 506;
200 inline static const SchemaField kDeletedFilesCount = SchemaField::MakeOptional(
201 kDeletedFilesCountFieldId, "deleted_files_count", int32(), "Deleted entry count");
202
203 static constexpr int32_t kAddedRowsCountFieldId = 512;
204 inline static const SchemaField kAddedRowsCount = SchemaField::MakeOptional(
205 kAddedRowsCountFieldId, "added_rows_count", int64(), "Added rows count");
206
207 static constexpr int32_t kExistingRowsCountFieldId = 513;
208 inline static const SchemaField kExistingRowsCount = SchemaField::MakeOptional(
209 kExistingRowsCountFieldId, "existing_rows_count", int64(), "Existing rows count");
210
211 static constexpr int32_t kDeletedRowsCountFieldId = 514;
212 inline static const SchemaField kDeletedRowsCount = SchemaField::MakeOptional(
213 kDeletedRowsCountFieldId, "deleted_rows_count", int64(), "Deleted rows count");
214
215 static constexpr int32_t kPartitionSummaryFieldId = 507;
216 inline static const SchemaField kPartitions = SchemaField::MakeOptional(
217 kPartitionSummaryFieldId, "partitions",
218 list(SchemaField::MakeRequired(508, std::string(ListType::kElementName),
219 struct_({
220 PartitionFieldSummary::kContainsNull,
221 PartitionFieldSummary::kContainsNaN,
222 PartitionFieldSummary::kLowerBound,
223 PartitionFieldSummary::kUpperBound,
224 }))),
225 "Summary for each partition");
226
227 static constexpr int32_t kKeyMetadataFieldId = 519;
228 inline static const SchemaField kKeyMetadata = SchemaField::MakeOptional(
229 kKeyMetadataFieldId, "key_metadata", binary(), "Encryption key metadata blob");
230
231 static constexpr int32_t kFirstRowIdFieldId = 520;
232 inline static const SchemaField kFirstRowId = SchemaField::MakeOptional(
233 kFirstRowIdFieldId, "first_row_id", int64(),
234 "Starting row ID to assign to new rows in ADDED data files");
235
236 bool operator==(const ManifestFile& other) const {
237 return manifest_path == other.manifest_path;
238 }
239
240 static const std::shared_ptr<StructType>& Type();
241};
242
255struct ICEBERG_EXPORT ManifestList {
257 std::vector<ManifestFile> entries;
258};
259
261ICEBERG_EXPORT inline constexpr std::string_view ToString(ManifestContent type) noexcept {
262 switch (type) {
264 return "data";
266 return "deletes";
267 }
269}
270
273 std::string_view str) noexcept {
274 if (str == "data") return ManifestContent::kData;
275 if (str == "deletes") return ManifestContent::kDeletes;
276 return InvalidArgument("Invalid manifest content type: {}", str);
277}
278
280ICEBERG_EXPORT inline constexpr Result<ManifestContent> ManifestContentFromInt(
281 int32_t content) noexcept {
282 switch (content) {
283 case 0:
285 case 1:
287 default:
288 return InvalidArgument("Invalid manifest content type: {}", content);
289 }
290}
291
292} // namespace iceberg
293
294namespace std {
295template <>
296struct hash<iceberg::ManifestFile> {
297 size_t operator()(const iceberg::ManifestFile& manifest_file) const {
298 return std::hash<std::string>{}(manifest_file.manifest_path);
299 }
300};
301} // namespace std
A type combined with a name.
Definition schema_field.h:39
Interface for a data type for a field.
Definition type.h:44
Definition expected.h:1199
ICEBERG_EXPORT const std::shared_ptr< BinaryType > & binary()
Return a BinaryType instance.
ICEBERG_EXPORT std::shared_ptr< ListType > list(SchemaField element)
Create a ListType with the given element field.
ICEBERG_EXPORT const std::shared_ptr< IntType > & int32()
Return an IntType instance.
ICEBERG_EXPORT std::shared_ptr< StructType > struct_(std::vector< SchemaField > fields)
Create a StructType with the given fields.
ICEBERG_EXPORT const std::shared_ptr< BooleanType > & boolean()
Return a BooleanType instance.
ICEBERG_EXPORT const std::shared_ptr< LongType > & int64()
Return a LongType instance.
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:34
ManifestContent
The type of files tracked by the manifest, either data or delete files; 0 for all v1 manifests.
Definition manifest_list.h:78
@ kData
The manifest content is data.
@ kDeletes
The manifest content is deletes.
ICEBERG_EXPORT std::string_view ToString(Expression::Operation op)
Returns a string representation of an expression operation.
void unreachable() noexcept
Marks a branch the program can never take.
Definition unreachable.h:35
ICEBERG_EXPORT constexpr Result< ManifestContent > ManifestContentFromInt(int32_t content) noexcept
Get the relative manifest content type from int.
Definition manifest_list.h:280
ICEBERG_EXPORT constexpr Result< ManifestContent > ManifestContentFromString(std::string_view str) noexcept
Get the relative manifest content type from name.
Definition manifest_list.h:272
STL namespace.
Define Result, Status, and error helpers.
Entry in a manifest list.
Definition manifest_list.h:86
std::vector< PartitionFieldSummary > partitions
Definition manifest_list.h:142
std::optional< int64_t > deleted_rows_count
Definition manifest_list.h:137
std::vector< uint8_t > key_metadata
Definition manifest_list.h:145
std::optional< int32_t > existing_files_count
Definition manifest_list.h:121
bool has_existing_files() const
Checks if this manifest file contains entries with EXISTING status.
Definition manifest_list.h:154
std::optional< int64_t > added_snapshot_id
Definition manifest_list.h:113
std::optional< int64_t > added_rows_count
Definition manifest_list.h:129
std::optional< int64_t > first_row_id
Definition manifest_list.h:148
std::string manifest_path
Definition manifest_list.h:89
std::optional< int32_t > added_files_count
Definition manifest_list.h:117
std::optional< int32_t > deleted_files_count
Definition manifest_list.h:125
bool has_added_files() const
Checks if this manifest file contains entries with ADDED status.
Definition manifest_list.h:151
std::optional< int64_t > existing_rows_count
Definition manifest_list.h:133
bool has_deleted_files() const
Checks if this manifest file contains entries with DELETED status.
Definition manifest_list.h:157
Definition manifest_list.h:255
std::vector< ManifestFile > entries
Entries in a manifest list.
Definition manifest_list.h:257
Field summary for partition field in the spec.
Definition manifest_list.h:44
std::optional< std::vector< uint8_t > > lower_bound
Definition manifest_list.h:54
std::optional< std::vector< uint8_t > > upper_bound
Definition manifest_list.h:58
std::optional< bool > contains_nan
Definition manifest_list.h:50
Portable stand-in for std::unreachable.