iceberg-cpp
Loading...
Searching...
No Matches
table.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 <functional>
26#include <memory>
27#include <string>
28#include <unordered_map>
29#include <vector>
30
32#include "iceberg/snapshot.h"
34#include "iceberg/type_fwd.h"
37
38namespace iceberg {
39
41class ICEBERG_EXPORT Table : public std::enable_shared_from_this<Table> {
42 public:
54 TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
55 std::string metadata_location, std::shared_ptr<FileIO> io,
56 std::shared_ptr<Catalog> catalog, std::string full_name = "",
57 std::shared_ptr<MetricsReporter> reporter = nullptr);
58
59 virtual ~Table();
60
62 const TableIdentifier& name() const { return identifier_; }
63
65 const std::string& full_name() const { return full_name_; }
66
68 const std::string& uuid() const;
69
72
74 Result<
75 std::reference_wrapper<const std::unordered_map<int32_t, std::shared_ptr<Schema>>>>
76 schemas() const;
77
80
82 Result<std::reference_wrapper<
83 const std::unordered_map<int32_t, std::shared_ptr<PartitionSpec>>>>
84 specs() const;
85
88
90 Result<std::reference_wrapper<
91 const std::unordered_map<int32_t, std::shared_ptr<SortOrder>>>>
92 sort_orders() const;
93
96
98 std::string_view metadata_file_location() const;
99
101 std::string_view location() const;
102
105
108
114
116 const std::vector<std::shared_ptr<Snapshot>>& snapshots() const;
117
119 const std::vector<SnapshotLogEntry>& history() const;
120
122 const std::shared_ptr<FileIO>& io() const;
123
125 const std::shared_ptr<TableMetadata>& metadata() const;
126
128 const std::shared_ptr<Catalog>& catalog() const;
129
131 const std::shared_ptr<MetricsReporter>& reporter() const;
132
135
137 virtual Status Refresh();
138
144
147 const;
148
152
155
159
163
167
171
175
179
184
188
191
194
197
200
203
207
210
211 protected:
212 Table(TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
213 std::string metadata_location, std::shared_ptr<FileIO> io,
214 std::shared_ptr<Catalog> catalog, std::string full_name,
215 std::shared_ptr<MetricsReporter> reporter = nullptr);
216
217 const TableIdentifier identifier_;
218 const std::string full_name_;
219 std::shared_ptr<TableMetadata> metadata_;
220 std::string metadata_location_;
221 std::shared_ptr<FileIO> io_;
222 std::shared_ptr<Catalog> catalog_;
223 std::shared_ptr<MetricsReporter> reporter_;
224 std::unique_ptr<class TableMetadataCache> metadata_cache_;
225};
226
228class ICEBERG_EXPORT StagedTable final : public Table {
229 public:
231 TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
232 std::string metadata_location, std::shared_ptr<FileIO> io,
233 std::shared_ptr<Catalog> catalog, std::string full_name = "",
234 std::shared_ptr<MetricsReporter> reporter = nullptr);
235
236 ~StagedTable() override;
237
238 Status Refresh() override { return {}; }
239
241
242 private:
243 using Table::Table;
244};
245
247
248class ICEBERG_EXPORT StaticTable : public Table {
249 public:
251 TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
252 std::string metadata_location, std::shared_ptr<FileIO> io,
253 std::string full_name = "");
254
255 ~StaticTable() override;
256
257 Status Refresh() override;
258
260
262
264
266
268
270
272
274
276 override;
277
279
281
283
285
287
289
291
292 private:
293 using Table::Table;
294};
295
296} // namespace iceberg
A table created by stage-create and not yet committed.
Definition table.h:228
Result< std::unique_ptr< DataTableScanBuilder > > NewScan() const override
Create a new table scan builder for this table.
Status Refresh() override
Refresh the current table metadata.
Definition table.h:238
A read-only table.
Definition table.h:248
Result< std::shared_ptr< MergeAppend > > NewMergeAppend() override
Create a new MergeAppend to append data files and merge manifests.
Result< std::shared_ptr< ExpireSnapshots > > NewExpireSnapshots() override
Create a new ExpireSnapshots to remove expired snapshots and commit the changes.
Result< std::shared_ptr< SnapshotManager > > NewSnapshotManager() override
Create a new SnapshotManager to manage snapshots and snapshot references.
Result< std::shared_ptr< UpdateSchema > > NewUpdateSchema() override
Create a new UpdateSchema to alter the columns of this table and commit the changes.
Result< std::shared_ptr< DeleteFiles > > NewDeleteFiles() override
Create a new DeleteFiles to delete data files and commit the changes.
Result< std::shared_ptr< UpdateLocation > > NewUpdateLocation() override
Create a new UpdateLocation to update the table location and commit the changes.
Result< std::shared_ptr< UpdateSortOrder > > NewUpdateSortOrder() override
Create a new UpdateSortOrder to update the table sort order and commit the changes.
Status Refresh() override
Refresh the current table metadata.
Result< std::shared_ptr< UpdatePartitionSpec > > NewUpdatePartitionSpec() override
Create a new UpdatePartitionSpec to update the partition spec of this table and commit the changes.
Result< std::shared_ptr< Transaction > > NewTransaction() override
Create a new Transaction to commit multiple table operations at once.
Result< std::shared_ptr< RowDelta > > NewRowDelta() override
Create a new RowDelta to add rows and row-level deletes.
Result< std::shared_ptr< FastAppend > > NewFastAppend() override
Create a new FastAppend to append data files and commit the changes.
Result< std::shared_ptr< UpdateProperties > > NewUpdateProperties() override
Create a new UpdateProperties to update table properties and commit the changes.
Result< std::shared_ptr< OverwriteFiles > > NewOverwrite() override
Create a new OverwriteFiles to overwrite data files and commit the changes.
Result< std::shared_ptr< UpdatePartitionStatistics > > NewUpdatePartitionStatistics() override
Create a new UpdatePartitionStatistics to update partition statistics and commit the changes.
Result< std::shared_ptr< RewriteFiles > > NewRewriteFiles() override
Create a new RewriteFiles to replace files in this table and commit the changes.
Result< std::shared_ptr< UpdateStatistics > > NewUpdateStatistics() override
Create a new UpdateStatistics to update the table statistics and commit the changes.
Table properties for Iceberg tables.
Definition table_properties.h:40
Represents an Iceberg table.
Definition table.h:41
virtual Result< std::unique_ptr< DataTableScanBuilder > > NewScan() const
Create a new table scan builder for this table.
virtual Result< std::shared_ptr< DeleteFiles > > NewDeleteFiles()
Create a new DeleteFiles to delete data files and commit the changes.
virtual Result< std::shared_ptr< ExpireSnapshots > > NewExpireSnapshots()
Create a new ExpireSnapshots to remove expired snapshots and commit the changes.
virtual Result< std::shared_ptr< RowDelta > > NewRowDelta()
Create a new RowDelta to add rows and row-level deletes.
virtual Result< std::shared_ptr< Transaction > > NewTransaction()
Create a new Transaction to commit multiple table operations at once.
const TableProperties & properties() const
Returns the properties of this table.
virtual Result< std::shared_ptr< FastAppend > > NewFastAppend()
Create a new FastAppend to append data files and commit the changes.
TimePointMs last_updated_ms() const
Returns the time when this table was last updated.
virtual Result< std::shared_ptr< UpdatePartitionStatistics > > NewUpdatePartitionStatistics()
Create a new UpdatePartitionStatistics to update partition statistics and commit the changes.
const std::string & full_name() const
Returns the fully-qualified name of this table.
Definition table.h:65
virtual Result< std::shared_ptr< UpdateSortOrder > > NewUpdateSortOrder()
Create a new UpdateSortOrder to update the table sort order and commit the changes.
Result< std::reference_wrapper< const std::unordered_map< int32_t, std::shared_ptr< PartitionSpec > > > > specs() const
Returns a map of partition specs for this table.
const std::shared_ptr< FileIO > & io() const
Returns a FileIO to read and write table data and metadata files.
virtual Result< std::shared_ptr< RewriteFiles > > NewRewriteFiles()
Create a new RewriteFiles to replace files in this table and commit the changes.
Result< std::reference_wrapper< const std::unordered_map< int32_t, std::shared_ptr< SortOrder > > > > sort_orders() const
Returns a map of sort order IDs to sort orders for this table.
Result< std::shared_ptr< Snapshot > > SnapshotById(int64_t snapshot_id) const
Get the snapshot of this table with the given id.
virtual Result< std::shared_ptr< UpdateStatistics > > NewUpdateStatistics()
Create a new UpdateStatistics to update the table statistics and commit the changes.
virtual Result< std::shared_ptr< UpdateLocation > > NewUpdateLocation()
Create a new UpdateLocation to update the table location and commit the changes.
const std::shared_ptr< TableMetadata > & metadata() const
Returns the current metadata for this table.
virtual Result< std::shared_ptr< OverwriteFiles > > NewOverwrite()
Create a new OverwriteFiles to overwrite data files and commit the changes.
virtual Status Refresh()
Refresh the current table metadata.
std::string_view metadata_file_location() const
Returns the table's metadata file location.
Result< std::reference_wrapper< const std::unordered_map< int32_t, std::shared_ptr< Schema > > > > schemas() const
Returns a map of schema for this table.
const std::string & uuid() const
Returns the UUID of the table.
const TableIdentifier & name() const
Returns the identifier of this table.
Definition table.h:62
Result< std::unique_ptr< LocationProvider > > location_provider() const
Returns a LocationProvider for this table.
std::string_view location() const
Returns the table's base location.
const std::vector< SnapshotLogEntry > & history() const
Get the snapshot history of this table.
Result< std::shared_ptr< SortOrder > > sort_order() const
Returns the sort order for this table, return NotFoundError if not found.
virtual Result< std::shared_ptr< MergeAppend > > NewMergeAppend()
Create a new MergeAppend to append data files and merge manifests.
const std::shared_ptr< MetricsReporter > & reporter() const
Returns the metrics reporter for this table.
Result< std::shared_ptr< Schema > > schema() const
Returns the schema for this table, return NotFoundError if not found.
virtual Result< std::unique_ptr< IncrementalChangelogScanBuilder > > NewIncrementalChangelogScan() const
Create a new incremental changelog scan builder for this table.
virtual Result< std::shared_ptr< UpdatePartitionSpec > > NewUpdatePartitionSpec()
Create a new UpdatePartitionSpec to update the partition spec of this table and commit the changes.
virtual Result< std::shared_ptr< UpdateProperties > > NewUpdateProperties()
Create a new UpdateProperties to update table properties and commit the changes.
virtual Result< std::shared_ptr< SnapshotManager > > NewSnapshotManager()
Create a new SnapshotManager to manage snapshots and snapshot references.
const std::shared_ptr< Catalog > & catalog() const
Returns the catalog that this table belongs to.
virtual Result< std::shared_ptr< UpdateSchema > > NewUpdateSchema()
Create a new UpdateSchema to alter the columns of this table and commit the changes.
Result< std::shared_ptr< PartitionSpec > > spec() const
Returns the partition spec for this table, return NotFoundError if not found.
Result< std::shared_ptr< Snapshot > > current_snapshot() const
Returns the table's current snapshot, return NotFoundError if not found.
static Result< std::shared_ptr< Table > > Make(TableIdentifier identifier, std::shared_ptr< TableMetadata > metadata, std::string metadata_location, std::shared_ptr< FileIO > io, std::shared_ptr< Catalog > catalog, std::string full_name="", std::shared_ptr< MetricsReporter > reporter=nullptr)
Construct a table.
virtual Result< std::unique_ptr< IncrementalAppendScanBuilder > > NewIncrementalAppendScan() const
Create a new incremental append scan builder for this table.
const std::vector< std::shared_ptr< Snapshot > > & snapshots() const
Get the snapshots of this table.
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
std::chrono::time_point< std::chrono::system_clock, std::chrono::milliseconds > TimePointMs
A time point in milliseconds.
Definition timepoint.h:33
std::expected< T, E > Result
Result alias.
Definition result.h:88
Define snapshot metadata types.
Identifies a table in iceberg catalog.
Definition table_identifier.h:46
Provide time point conversion helpers.
Updates the table location.