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
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
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
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
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.
std::function< Result< std::unique_ptr< ManifestWriter > >()> ManifestWriterFactory
Factory function type for creating ManifestWriter instances.
Definition rolling_manifest_writer.h:41
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< std::vector< ManifestFile > > ToManifestFiles() const
Get the list of manifest files produced by this writer.
RollingManifestWriter(ManifestWriterFactory manifest_writer_factory, int64_t target_file_size_in_bytes)
Construct a rolling manifest writer.
Status WriteAddedEntry(std::shared_ptr< DataFile > file, std::optional< int64_t > data_sequence_number=std::nullopt)
Add an added entry for a file.
Status Close()
Close the rolling manifest writer.
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
std::expected< T, E > Result
Result alias.
Definition result.h:88
Define Result, Status, and error helpers.