iceberg-cpp
Loading...
Searching...
No Matches
manifest_writer.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
24
25#include <functional>
26#include <memory>
27#include <string>
28#include <vector>
29
30#include "iceberg/file_writer.h"
31#include "iceberg/iceberg_export.h"
33#include "iceberg/metrics.h"
34#include "iceberg/result.h"
35#include "iceberg/type_fwd.h"
36
37namespace iceberg {
38
40class ICEBERG_EXPORT ManifestWriter {
41 public:
43
49 Status WriteEntry(const ManifestEntry& entry);
50
59 Status WriteAddedEntry(std::shared_ptr<DataFile> file,
60 std::optional<int64_t> data_sequence_number = std::nullopt);
63 Status WriteAddedEntry(const ManifestEntry& entry);
64
75 Status WriteExistingEntry(std::shared_ptr<DataFile> file, int64_t file_snapshot_id,
76 int64_t data_sequence_number,
77 std::optional<int64_t> file_sequence_number = std::nullopt);
80 Status WriteExistingEntry(const ManifestEntry& entry);
81
92 Status WriteDeletedEntry(std::shared_ptr<DataFile> file, int64_t data_sequence_number,
93 std::optional<int64_t> file_sequence_number = std::nullopt);
96 Status WriteDeletedEntry(const ManifestEntry& entry);
97
101 Status AddAll(const std::vector<ManifestEntry>& entries);
102
104 Status Close();
105
107 ManifestContent content() const;
108
111 Result<Metrics> metrics() const;
112
115 Result<int64_t> length() const;
116
119 Result<ManifestFile> ToManifestFile() const;
120
133 static Result<std::unique_ptr<ManifestWriter>> MakeWriter(
134 int8_t format_version, std::optional<int64_t> snapshot_id,
135 std::string_view manifest_location, std::shared_ptr<FileIO> file_io,
136 std::shared_ptr<PartitionSpec> partition_spec,
137 std::shared_ptr<Schema> current_schema,
138 ManifestContent content = ManifestContent::kData,
139 std::optional<int64_t> first_row_id = std::nullopt);
140
141 private:
142 // Private constructor for internal use only, use the static Make*Writer methods
143 // instead.
144 ManifestWriter(std::unique_ptr<Writer> writer,
145 std::unique_ptr<class ManifestEntryAdapter> adapter,
146 std::string_view manifest_location, std::optional<int64_t> first_row_id);
147
148 Status CheckDataFile(const DataFile& file) const;
149
150 static constexpr int64_t kBatchSize = 1024;
151 std::unique_ptr<Writer> writer_;
152 std::unique_ptr<class ManifestEntryAdapter> adapter_;
153 bool closed_{false};
154 std::string manifest_location_;
155 std::optional<int64_t> first_row_id_;
156
157 int32_t add_files_count_{0};
158 int32_t existing_files_count_{0};
159 int32_t delete_files_count_{0};
160 int64_t add_rows_count_{0L};
161 int64_t existing_rows_count_{0L};
162 int64_t delete_rows_count_{0L};
163 std::optional<int64_t> min_sequence_number_{std::nullopt};
164 std::unique_ptr<PartitionSummary> partition_summary_;
165};
166
168using ManifestWriterFactory = std::function<Result<std::unique_ptr<ManifestWriter>>(
169 int32_t spec_id, ManifestContent content)>;
170
172class ICEBERG_EXPORT ManifestListWriter {
173 public:
175
179 Status Add(const ManifestFile& file);
180
184 Status AddAll(const std::vector<ManifestFile>& files);
185
187 Status Close();
188
190 std::optional<int64_t> next_row_id() const;
191
203 static Result<std::unique_ptr<ManifestListWriter>> MakeWriter(
204 int8_t format_version, int64_t snapshot_id,
205 std::optional<int64_t> parent_snapshot_id, std::string_view manifest_list_location,
206 std::shared_ptr<FileIO> file_io,
207 std::optional<int64_t> sequence_number = std::nullopt,
208 std::optional<int64_t> first_row_id = std::nullopt);
209
210 private:
211 // Private constructor for internal use only, use the static Make*Writer methods
212 // instead.
213 ManifestListWriter(std::unique_ptr<Writer> writer,
214 std::unique_ptr<class ManifestFileAdapter> adapter);
215
216 static constexpr int64_t kBatchSize = 1024;
217 std::unique_ptr<Writer> writer_;
218 std::unique_ptr<class ManifestFileAdapter> adapter_;
219};
220
221} // namespace iceberg
Write manifest files to a manifest list file.
Definition manifest_writer.h:172
Write manifest entries to a manifest file.
Definition manifest_writer.h:40
ManifestContent
The type of files tracked by the manifest, either data or delete files; 0 for all v1 manifests.
Definition manifest_list.h:77
std::function< Result< std::unique_ptr< ManifestWriter > >(int32_t spec_id, ManifestContent content)> ManifestWriterFactory
Factory type for creating ManifestWriter instances.
Definition manifest_writer.h:169
DataFile carries data file path, partition tuple, metrics, ...
Definition manifest_entry.h:62
A manifest is an immutable Avro file that lists data files or delete files, along with each file's pa...
Definition manifest_entry.h:311
Entry in a manifest list.
Definition manifest_list.h:85