iceberg-cpp
Loading...
Searching...
No Matches
table.h
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
22#include <functional>
23#include <memory>
24#include <string>
25#include <unordered_map>
26#include <vector>
27
28#include "iceberg/iceberg_export.h"
29#include "iceberg/snapshot.h"
31#include "iceberg/type_fwd.h"
33#include "iceberg/util/timepoint.h"
34
35namespace iceberg {
36
38class ICEBERG_EXPORT Table : public std::enable_shared_from_this<Table> {
39 public:
46 static Result<std::shared_ptr<Table>> Make(TableIdentifier identifier,
47 std::shared_ptr<TableMetadata> metadata,
48 std::string metadata_location,
49 std::shared_ptr<FileIO> io,
50 std::shared_ptr<Catalog> catalog);
51
52 virtual ~Table();
53
55 const TableIdentifier& name() const { return identifier_; }
56
58 const std::string& uuid() const;
59
61 Result<std::shared_ptr<Schema>> schema() const;
62
64 Result<
65 std::reference_wrapper<const std::unordered_map<int32_t, std::shared_ptr<Schema>>>>
66 schemas() const;
67
69 Result<std::shared_ptr<PartitionSpec>> spec() const;
70
72 Result<std::reference_wrapper<
73 const std::unordered_map<int32_t, std::shared_ptr<PartitionSpec>>>>
74 specs() const;
75
77 Result<std::shared_ptr<SortOrder>> sort_order() const;
78
80 Result<std::reference_wrapper<
81 const std::unordered_map<int32_t, std::shared_ptr<SortOrder>>>>
82 sort_orders() const;
83
85 const TableProperties& properties() const;
86
88 std::string_view metadata_file_location() const;
89
91 std::string_view location() const;
92
94 TimePointMs last_updated_ms() const;
95
97 Result<std::shared_ptr<Snapshot>> current_snapshot() const;
98
103 Result<std::shared_ptr<Snapshot>> SnapshotById(int64_t snapshot_id) const;
104
106 const std::vector<std::shared_ptr<Snapshot>>& snapshots() const;
107
109 const std::vector<SnapshotLogEntry>& history() const;
110
112 const std::shared_ptr<FileIO>& io() const;
113
115 const std::shared_ptr<TableMetadata>& metadata() const;
116
118 const std::shared_ptr<Catalog>& catalog() const;
119
121 Result<std::unique_ptr<LocationProvider>> location_provider() const;
122
124 virtual Status Refresh();
125
130 virtual Result<std::unique_ptr<DataTableScanBuilder>> NewScan() const;
131
133 virtual Result<std::unique_ptr<IncrementalAppendScanBuilder>> NewIncrementalAppendScan()
134 const;
135
137 virtual Result<std::unique_ptr<IncrementalChangelogScanBuilder>>
138 NewIncrementalChangelogScan() const;
139
141 virtual Result<std::shared_ptr<Transaction>> NewTransaction();
142
145 virtual Result<std::shared_ptr<UpdatePartitionSpec>> NewUpdatePartitionSpec();
146
149 virtual Result<std::shared_ptr<UpdateProperties>> NewUpdateProperties();
150
153 virtual Result<std::shared_ptr<UpdateSortOrder>> NewUpdateSortOrder();
154
157 virtual Result<std::shared_ptr<UpdateSchema>> NewUpdateSchema();
158
161 virtual Result<std::shared_ptr<ExpireSnapshots>> NewExpireSnapshots();
162
165 virtual Result<std::shared_ptr<UpdateStatistics>> NewUpdateStatistics();
166
169 virtual Result<std::shared_ptr<UpdatePartitionStatistics>>
170 NewUpdatePartitionStatistics();
171
174 virtual Result<std::shared_ptr<UpdateLocation>> NewUpdateLocation();
175
177 virtual Result<std::shared_ptr<FastAppend>> NewFastAppend();
178
180 virtual Result<std::shared_ptr<MergeAppend>> NewMergeAppend();
181
183 virtual Result<std::shared_ptr<DeleteFiles>> NewDeleteFiles();
184
186 virtual Result<std::shared_ptr<RowDelta>> NewRowDelta();
187
189 virtual Result<std::shared_ptr<OverwriteFiles>> NewOverwrite();
190
193 virtual Result<std::shared_ptr<RewriteFiles>> NewRewriteFiles();
194
196 virtual Result<std::shared_ptr<SnapshotManager>> NewSnapshotManager();
197
198 protected:
199 Table(TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
200 std::string metadata_location, std::shared_ptr<FileIO> io,
201 std::shared_ptr<Catalog> catalog);
202
203 const TableIdentifier identifier_;
204 std::shared_ptr<TableMetadata> metadata_;
205 std::string metadata_location_;
206 std::shared_ptr<FileIO> io_;
207 std::shared_ptr<Catalog> catalog_;
208 std::unique_ptr<class TableMetadataCache> metadata_cache_;
209};
210
212class ICEBERG_EXPORT StagedTable final : public Table {
213 public:
214 static Result<std::shared_ptr<StagedTable>> Make(
215 TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
216 std::string metadata_location, std::shared_ptr<FileIO> io,
217 std::shared_ptr<Catalog> catalog);
218
219 ~StagedTable() override;
220
221 Status Refresh() override { return {}; }
222
223 Result<std::unique_ptr<DataTableScanBuilder>> NewScan() const override;
224
225 private:
226 using Table::Table;
227};
228
230
231class ICEBERG_EXPORT StaticTable : public Table {
232 public:
233 static Result<std::shared_ptr<StaticTable>> Make(
234 TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
235 std::string metadata_location, std::shared_ptr<FileIO> io);
236
237 ~StaticTable() override;
238
239 Status Refresh() override;
240
241 Result<std::shared_ptr<Transaction>> NewTransaction() override;
242
243 Result<std::shared_ptr<UpdateProperties>> NewUpdateProperties() override;
244
245 Result<std::shared_ptr<UpdateSchema>> NewUpdateSchema() override;
246
247 Result<std::shared_ptr<UpdateLocation>> NewUpdateLocation() override;
248
249 Result<std::shared_ptr<UpdatePartitionSpec>> NewUpdatePartitionSpec() override;
250
251 Result<std::shared_ptr<UpdateSortOrder>> NewUpdateSortOrder() override;
252
253 Result<std::shared_ptr<ExpireSnapshots>> NewExpireSnapshots() override;
254
255 Result<std::shared_ptr<UpdateStatistics>> NewUpdateStatistics() override;
256
257 Result<std::shared_ptr<UpdatePartitionStatistics>> NewUpdatePartitionStatistics()
258 override;
259
260 Result<std::shared_ptr<FastAppend>> NewFastAppend() override;
261
262 Result<std::shared_ptr<MergeAppend>> NewMergeAppend() override;
263
264 Result<std::shared_ptr<DeleteFiles>> NewDeleteFiles() override;
265
266 Result<std::shared_ptr<RowDelta>> NewRowDelta() override;
267
268 Result<std::shared_ptr<OverwriteFiles>> NewOverwrite() override;
269
270 Result<std::shared_ptr<RewriteFiles>> NewRewriteFiles() override;
271
272 Result<std::shared_ptr<SnapshotManager>> NewSnapshotManager() override;
273
274 private:
275 using Table::Table;
276};
277
278} // namespace iceberg
A table created by stage-create and not yet committed.
Definition table.h:212
Status Refresh() override
Refresh the current table metadata.
Definition table.h:221
A read-only table.
Definition table.h:231
Table properties for Iceberg tables.
Definition table_properties.h:37
Represents an Iceberg table.
Definition table.h:38
const TableIdentifier & name() const
Returns the identifier of this table.
Definition table.h:55
ICEBERG_EXPORT const std::shared_ptr< UuidType > & uuid()
Return a UuidType instance.
Identifies a table in iceberg catalog.
Definition table_identifier.h:46
Updates the table location.