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<SnapshotManager>> NewSnapshotManager();
181
182 protected:
183 Table(TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
184 std::string metadata_location, std::shared_ptr<FileIO> io,
185 std::shared_ptr<Catalog> catalog);
186
187 const TableIdentifier identifier_;
188 std::shared_ptr<TableMetadata> metadata_;
189 std::string metadata_location_;
190 std::shared_ptr<FileIO> io_;
191 std::shared_ptr<Catalog> catalog_;
192 std::unique_ptr<class TableMetadataCache> metadata_cache_;
193};
194
196class ICEBERG_EXPORT StagedTable final : public Table {
197 public:
198 static Result<std::shared_ptr<StagedTable>> Make(
199 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 ~StagedTable() override;
204
205 Status Refresh() override { return {}; }
206
207 Result<std::unique_ptr<DataTableScanBuilder>> NewScan() const override;
208
209 private:
210 using Table::Table;
211};
212
214
215class ICEBERG_EXPORT StaticTable final : public Table {
216 public:
217 static Result<std::shared_ptr<StaticTable>> Make(
218 TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
219 std::string metadata_location, std::shared_ptr<FileIO> io);
220
221 ~StaticTable() override;
222
223 Status Refresh() override;
224
225 Result<std::shared_ptr<Transaction>> NewTransaction() override;
226
227 Result<std::shared_ptr<UpdateProperties>> NewUpdateProperties() override;
228
229 Result<std::shared_ptr<UpdateSchema>> NewUpdateSchema() override;
230
231 private:
232 using Table::Table;
233};
234
235} // namespace iceberg
A table created by stage-create and not yet committed.
Definition table.h:196
Status Refresh() override
Refresh the current table metadata.
Definition table.h:205
A read-only table.
Definition table.h:215
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.