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"
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:
45
52
61 Status WriteAddedEntry(std::shared_ptr<DataFile> file,
62 std::optional<int64_t> data_sequence_number = std::nullopt);
66
77 Status WriteExistingEntry(std::shared_ptr<DataFile> file, int64_t file_snapshot_id,
78 int64_t data_sequence_number,
79 std::optional<int64_t> file_sequence_number = std::nullopt);
83
94 Status WriteDeletedEntry(std::shared_ptr<DataFile> file, int64_t data_sequence_number,
95 std::optional<int64_t> file_sequence_number = std::nullopt);
99
103 Status AddAll(const std::vector<ManifestEntry>& entries);
104
107
110
114
118
122
136 int8_t format_version, std::optional<int64_t> snapshot_id,
137 std::string_view manifest_location, std::shared_ptr<FileIO> file_io,
138 std::shared_ptr<PartitionSpec> partition_spec,
139 std::shared_ptr<Schema> current_schema,
140 ManifestContent content = ManifestContent::kData,
141 std::optional<int64_t> first_row_id = std::nullopt);
142
143 private:
144 // Private constructor for internal use only, use the static Make*Writer methods
145 // instead.
146 ManifestWriter(std::unique_ptr<Writer> writer,
147 std::unique_ptr<class ManifestEntryAdapter> adapter,
148 std::string_view manifest_location, std::optional<int64_t> first_row_id);
149
150 Status CheckDataFile(const DataFile& file) const;
151
152 static constexpr int64_t kBatchSize = 1024;
153 std::unique_ptr<Writer> writer_;
154 std::unique_ptr<class ManifestEntryAdapter> adapter_;
155 bool closed_{false};
156 std::string manifest_location_;
157 std::optional<int64_t> first_row_id_;
158
159 int32_t add_files_count_{0};
160 int32_t existing_files_count_{0};
161 int32_t delete_files_count_{0};
162 int64_t add_rows_count_{0L};
163 int64_t existing_rows_count_{0L};
164 int64_t delete_rows_count_{0L};
165 std::optional<int64_t> min_sequence_number_{std::nullopt};
166 std::unique_ptr<PartitionSummary> partition_summary_;
167};
168
170using ManifestWriterFactory = std::function<Result<std::unique_ptr<ManifestWriter>>(
171 int32_t spec_id, ManifestContent content)>;
172
174class ICEBERG_EXPORT ManifestListWriter {
175 public:
177
181 Status Add(const ManifestFile& file);
182
186 Status AddAll(const std::vector<ManifestFile>& files);
187
190
192 std::optional<int64_t> next_row_id() const;
193
206 int8_t format_version, int64_t snapshot_id,
207 std::optional<int64_t> parent_snapshot_id, std::string_view manifest_list_location,
208 std::shared_ptr<FileIO> file_io,
209 std::optional<int64_t> sequence_number = std::nullopt,
210 std::optional<int64_t> first_row_id = std::nullopt);
211
212 private:
213 // Private constructor for internal use only, use the static Make*Writer methods
214 // instead.
215 ManifestListWriter(std::unique_ptr<Writer> writer,
216 std::unique_ptr<class ManifestFileAdapter> adapter);
217
218 static constexpr int64_t kBatchSize = 1024;
219 std::unique_ptr<Writer> writer_;
220 std::unique_ptr<class ManifestFileAdapter> adapter_;
221};
222
223} // namespace iceberg
Write manifest files to a manifest list file.
Definition manifest_writer.h:174
Status Close()
Close writer and flush to storage.
Status AddAll(const std::vector< ManifestFile > &files)
Write manifest file list to manifest list file.
std::optional< int64_t > next_row_id() const
Get the next row id to assign.
Status Add(const ManifestFile &file)
Write manifest file to manifest list file.
static Result< std::unique_ptr< ManifestListWriter > > MakeWriter(int8_t format_version, int64_t snapshot_id, std::optional< int64_t > parent_snapshot_id, std::string_view manifest_list_location, std::shared_ptr< FileIO > file_io, std::optional< int64_t > sequence_number=std::nullopt, std::optional< int64_t > first_row_id=std::nullopt)
Factory function to create a writer for the manifest list based on format version.
Write manifest entries to a manifest file.
Definition manifest_writer.h:40
Status WriteAddedEntry(std::shared_ptr< DataFile > file, std::optional< int64_t > data_sequence_number=std::nullopt)
Add an added entry for a file with a specific sequence number.
Status WriteAddedEntry(const ManifestEntry &entry)
Add a new entry to the manifest. The method populates the snapshot id and status fields of the entry.
Status Close()
Close writer and flush to storage.
Result< Metrics > metrics() const
Get the metrics of written manifest file.
Status WriteDeletedEntry(std::shared_ptr< DataFile > file, int64_t data_sequence_number, std::optional< int64_t > file_sequence_number=std::nullopt)
Add a delete entry for a file.
Result< int64_t > length() const
Get the current length of the manifest file in bytes.
ManifestContent content() const
Get the content of the manifest.
Status WriteExistingEntry(const ManifestEntry &entry)
Add an existing entry to the manifest. The method populates the status field of the entry.
static Result< std::unique_ptr< ManifestWriter > > MakeWriter(int8_t format_version, std::optional< int64_t > snapshot_id, std::string_view manifest_location, std::shared_ptr< FileIO > file_io, std::shared_ptr< PartitionSpec > partition_spec, std::shared_ptr< Schema > current_schema, ManifestContent content=ManifestContent::kData, std::optional< int64_t > first_row_id=std::nullopt)
Factory function to create a writer for a manifest file based on format version.
Status WriteEntry(const ManifestEntry &entry)
Write the entry that all its fields are populated correctly.
Status AddAll(const std::vector< ManifestEntry > &entries)
Write manifest entries to file.
Status WriteExistingEntry(std::shared_ptr< DataFile > file, int64_t file_snapshot_id, int64_t data_sequence_number, std::optional< int64_t > file_sequence_number=std::nullopt)
Add an existing entry for a file.
Result< ManifestFile > ToManifestFile() const
Get the ManifestFile object.
Status WriteDeletedEntry(const ManifestEntry &entry)
Add a deleted entry to the manifest. The method populates the snapshot id and status fields of the en...
Definition expected.h:1199
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
std::function< Result< std::unique_ptr< ManifestWriter > >(int32_t spec_id, ManifestContent content)> ManifestWriterFactory
Factory type for creating ManifestWriter instances.
Definition manifest_writer.h:171
Define Result, Status, and error helpers.
DataFile carries data file path, partition tuple, metrics, ...
Definition manifest_entry.h:63
A manifest is an immutable Avro file that lists data files or delete files, along with each file's pa...
Definition manifest_entry.h:319
Entry in a manifest list.
Definition manifest_list.h:86