iceberg-cpp
Loading...
Searching...
No Matches
rolling_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 <vector>
28
29#include "iceberg/iceberg_export.h"
33#include "iceberg/result.h"
34
35namespace iceberg {
36
38class ICEBERG_EXPORT RollingManifestWriter {
39 public:
41 using ManifestWriterFactory = std::function<Result<std::unique_ptr<ManifestWriter>>()>;
42
49 RollingManifestWriter(ManifestWriterFactory manifest_writer_factory,
50 int64_t target_file_size_in_bytes);
51
53
61 Status WriteAddedEntry(std::shared_ptr<DataFile> file,
62 std::optional<int64_t> data_sequence_number = std::nullopt);
63
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);
78
90 Status WriteDeletedEntry(std::shared_ptr<DataFile> file, int64_t data_sequence_number,
91 std::optional<int64_t> file_sequence_number = std::nullopt);
92
94 Status Close();
95
99 Result<std::vector<ManifestFile>> ToManifestFiles() const;
100
101 private:
104 Result<ManifestWriter*> CurrentWriter();
105
110 bool ShouldRollToNewFile() const;
111
113 Status CloseCurrentWriter();
114
117 static constexpr int64_t kRowsDivisor = 250;
118
119 ManifestWriterFactory manifest_writer_factory_;
120 int64_t target_file_size_in_bytes_;
121 std::vector<ManifestFile> manifest_files_;
122
123 int64_t current_file_rows_{0};
124 std::unique_ptr<ManifestWriter> current_writer_{nullptr};
125 bool closed_{false};
126};
127
128} // namespace iceberg
A rolling manifest writer that can produce multiple manifest files.
Definition rolling_manifest_writer.h:38
std::function< Result< std::unique_ptr< ManifestWriter > >()> ManifestWriterFactory
Factory function type for creating ManifestWriter instances.
Definition rolling_manifest_writer.h:41