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
31#include "iceberg/result.h"
32#include "iceberg/type_fwd.h"
35
36namespace iceberg {
37
51class ICEBERG_EXPORT RewriteFiles : public MergingSnapshotUpdate {
52 public:
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
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
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:63
API for replacing files in a table.
Definition rewrite_files.h:51
RewriteFiles & SetDataSequenceNumber(int64_t sequence_number)
Configure the data sequence number for this rewrite operation.
RewriteFiles & ValidateFromSnapshot(int64_t snapshot_id)
Set the snapshot ID used in any reads for this operation.
RewriteFiles & AddDeleteFile(const std::shared_ptr< DataFile > &delete_file)
Add a new delete file.
static Result< std::unique_ptr< RewriteFiles > > Make(std::string table_name, std::shared_ptr< TransactionContext > ctx)
Create a new RewriteFiles operation.
std::string operation() override
A string that describes the action that produced the new snapshot.
RewriteFiles & AddDataFile(const std::shared_ptr< DataFile > &file)
Add a new data file.
RewriteFiles & RewriteDataFiles(const std::vector< std::shared_ptr< DataFile > > &files_to_delete, const std::vector< std::shared_ptr< DataFile > > &files_to_add, int64_t sequence_number)
Add a rewrite that replaces one set of data files with another set that contains the same data....
Status Validate(const TableMetadata &current_metadata, const std::shared_ptr< Snapshot > &snapshot) override
Validate the current metadata.
RewriteFiles & DeleteDataFile(const std::shared_ptr< DataFile > &data_file)
Remove a data file from the current table state.
RewriteFiles & DeleteDeleteFile(const std::shared_ptr< DataFile > &delete_file)
Remove a delete file from the table state.
RewriteFiles & Rewrite(const std::vector< std::shared_ptr< DataFile > > &data_files_to_replace, const std::vector< std::shared_ptr< DataFile > > &delete_files_to_replace, const std::vector< std::shared_ptr< DataFile > > &data_files_to_add, const std::vector< std::shared_ptr< DataFile > > &delete_files_to_add)
Add a rewrite that replaces one set of files with another set that contains the same data.
RewriteFiles & AddDeleteFile(const std::shared_ptr< DataFile > &delete_file, int64_t data_sequence_number)
Add a new delete file with the given data sequence number.
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.
Represents the metadata for an Iceberg table.
Definition table_metadata.h:73