iceberg-cpp
Loading...
Searching...
No Matches
fast_append.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
23
24#include <memory>
25#include <string>
26#include <unordered_map>
27#include <vector>
28
30#include "iceberg/result.h"
31#include "iceberg/type_fwd.h"
34
35namespace iceberg {
36
47class ICEBERG_EXPORT FastAppend : public SnapshotUpdate {
48 public:
55 std::string table_name, std::shared_ptr<TransactionContext> ctx);
56
61 FastAppend& AppendFile(const std::shared_ptr<DataFile>& file);
62
75
76 std::string operation() override;
77
79 const TableMetadata& metadata_to_update,
80 const std::shared_ptr<Snapshot>& snapshot) override;
81 std::unordered_map<std::string, std::string> Summary() override;
82 void SetSummaryProperty(const std::string& property, const std::string& value) override;
83 Status CleanUncommitted(const std::unordered_set<std::string>& committed) override;
84 bool CleanupAfterCommit() const override;
85
86 private:
87 explicit FastAppend(std::string table_name, std::shared_ptr<TransactionContext> ctx);
88
90 Result<std::shared_ptr<PartitionSpec>> Spec(int32_t spec_id);
91
97 Result<ManifestFile> CopyManifest(const ManifestFile& manifest, bool update_summary);
98
102 Result<std::vector<ManifestFile>> WriteNewManifests();
103
104 private:
105 std::string table_name_;
106 std::unordered_map<int32_t, DataFileSet> new_data_files_by_spec_;
107 // Stable input summaries for retry-safe summary_ rebuilds.
108 SnapshotSummaryBuilder added_data_files_summary_;
109 SnapshotSummaryBuilder appended_manifests_summary_;
110 // User-provided summary properties restored after summary_ rebuilds.
111 std::unordered_map<std::string, std::string> custom_summary_properties_;
112 std::vector<ManifestFile> append_manifests_;
113 // Original manifests kept to recreate copied manifests after retry cleanup.
114 std::vector<ManifestFile> append_manifests_to_copy_;
115 std::vector<ManifestFile> rewritten_append_manifests_;
116 std::vector<ManifestFile> new_manifests_;
117 // Manifest count summary from the latest Apply() result.
118 SnapshotSummaryBuilder manifest_count_summary_;
119 bool has_new_files_{false};
120};
121
122} // namespace iceberg
API for appending new files in a table.
Definition fast_append.h:47
FastAppend & AppendFile(const std::shared_ptr< DataFile > &file)
Append a DataFile to the table.
void SetSummaryProperty(const std::string &property, const std::string &value) override
Set a summary property.
bool CleanupAfterCommit() const override
Check if cleanup should happen after commit.
std::unordered_map< std::string, std::string > Summary() override
Get the summary map for this operation.
Result< std::vector< ManifestFile > > Apply(const TableMetadata &metadata_to_update, const std::shared_ptr< Snapshot > &snapshot) override
Apply the update's changes to the given metadata and snapshot.
FastAppend & AppendManifest(const ManifestFile &manifest)
Append a ManifestFile to the table.
Status CleanUncommitted(const std::unordered_set< std::string > &committed) override
Clean up any uncommitted manifests that were created.
std::string operation() override
A string that describes the action that produced the new snapshot.
static Result< std::unique_ptr< FastAppend > > Make(std::string table_name, std::shared_ptr< TransactionContext > ctx)
Create a new FastAppend instance.
Helper class for building snapshot summaries.
Definition snapshot.h:265
API for table changes that produce snapshots.
Definition snapshot_update.h:49
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.
Define base APIs for snapshot updates.
Entry in a manifest list.
Definition manifest_list.h:85
Represents the metadata for an Iceberg table.
Definition table_metadata.h:73