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 protected:
77 std::string operation() override;
78
80 const TableMetadata& metadata_to_update,
81 const std::shared_ptr<Snapshot>& snapshot) override;
82 std::unordered_map<std::string, std::string> Summary() override;
83 void SetSummaryProperty(const std::string& property, const std::string& value) override;
84 Status CleanUncommitted(const std::unordered_set<std::string>& committed) 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
96 Result<ManifestFile> CopyManifest(const ManifestFile& manifest);
97
101 Result<std::vector<ManifestFile>> WriteNewManifests();
102
103 private:
104 std::string table_name_;
105 std::unordered_map<int32_t, DataFileSet> new_data_files_by_spec_;
106 // Stable input summaries for retry-safe summary_ rebuilds.
107 SnapshotSummaryBuilder added_data_files_summary_;
108 SnapshotSummaryBuilder appended_manifests_summary_;
109 // User-provided summary properties restored after summary_ rebuilds.
110 std::unordered_map<std::string, std::string> custom_summary_properties_;
111 std::vector<ManifestFile> append_manifests_;
112 // Original manifests kept to recreate copied manifests after retry cleanup.
113 std::vector<ManifestFile> append_manifests_to_copy_;
114 std::vector<ManifestFile> rewritten_append_manifests_;
115 std::vector<ManifestFile> new_manifests_;
116 // Manifest count summary from the latest Apply() result.
117 SnapshotSummaryBuilder manifest_count_summary_;
118 bool has_new_files_{false};
119};
120
121} // namespace iceberg
API for appending new files in a table.
Definition fast_append.h:47
static Result< std::shared_ptr< FastAppend > > Make(std::string table_name, std::shared_ptr< TransactionContext > ctx)
Create a new FastAppend instance.
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.
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.
Helper class for building snapshot summaries.
Definition snapshot.h:266
API for table changes that produce snapshots.
Definition snapshot_update.h:61
Definition expected.h:1199
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:34
Define Result, Status, and error helpers.
Define base APIs for snapshot updates.
Entry in a manifest list.
Definition manifest_list.h:86
Represents the metadata for an Iceberg table.
Definition table_metadata.h:73