iceberg-cpp
Loading...
Searching...
No Matches
rewrite_files.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 <memory>
26#include <optional>
27#include <string>
28#include <vector>
29
30#include "iceberg/iceberg_export.h"
31#include "iceberg/result.h"
32#include "iceberg/type_fwd.h"
35
36namespace iceberg {
37
51class ICEBERG_EXPORT RewriteFiles : public MergingSnapshotUpdate {
52 public:
58 static Result<std::unique_ptr<RewriteFiles>> Make(
59 std::string table_name, std::shared_ptr<TransactionContext> ctx);
60
61 ~RewriteFiles() override = default;
62
72 RewriteFiles& DeleteDataFile(const std::shared_ptr<DataFile>& data_file);
73
83 RewriteFiles& DeleteDeleteFile(const std::shared_ptr<DataFile>& delete_file);
84
94 RewriteFiles& AddDataFile(const std::shared_ptr<DataFile>& file);
95
105 RewriteFiles& AddDeleteFile(const std::shared_ptr<DataFile>& delete_file);
106
122 RewriteFiles& AddDeleteFile(const std::shared_ptr<DataFile>& delete_file,
123 int64_t data_sequence_number);
124
133 RewriteFiles& SetDataSequenceNumber(int64_t sequence_number);
134
144 RewriteFiles& RewriteDataFiles(
145 const std::vector<std::shared_ptr<DataFile>>& files_to_delete,
146 const std::vector<std::shared_ptr<DataFile>>& files_to_add,
147 int64_t sequence_number);
148
157 RewriteFiles& Rewrite(
158 const std::vector<std::shared_ptr<DataFile>>& data_files_to_replace,
159 const std::vector<std::shared_ptr<DataFile>>& delete_files_to_replace,
160 const std::vector<std::shared_ptr<DataFile>>& data_files_to_add,
161 const std::vector<std::shared_ptr<DataFile>>& delete_files_to_add);
162
171 RewriteFiles& ValidateFromSnapshot(int64_t snapshot_id);
172
173 std::string operation() override;
174
175 protected:
176 Status Validate(const TableMetadata& current_metadata,
177 const std::shared_ptr<Snapshot>& snapshot) override;
178
179 explicit RewriteFiles(std::string table_name, std::shared_ptr<TransactionContext> ctx);
180
181 private:
188 void ValidateReplacedAndAddedFiles();
189
191 DataFileSet replaced_data_files_;
192
194 std::optional<int64_t> starting_snapshot_id_;
195};
196
197} // namespace iceberg
A set of DataFile pointers with insertion order preserved and deduplicated by file path.
Definition data_file_set.h:44
Abstract base class for merge-based snapshot write operations.
Definition merging_snapshot_update.h:69
API for replacing files in a table.
Definition rewrite_files.h:51
Represents the metadata for an Iceberg table.
Definition table_metadata.h:73