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/labels.h"
33#include "iceberg/snapshot.h"
35#include "iceberg/type_fwd.h"
38
39namespace iceberg {
40
45class ICEBERG_EXPORT Table : public std::enable_shared_from_this<Table> {
46 public:
59 TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
60 std::string metadata_location, std::shared_ptr<FileIO> io,
61 std::shared_ptr<Catalog> catalog, std::string full_name = "",
62 std::shared_ptr<MetricsReporter> reporter = nullptr,
63 std::unique_ptr<Labels> labels = nullptr);
64
65 virtual ~Table();
66
68 const TableIdentifier& name() const { return identifier_; }
69
71 const std::string& full_name() const { return full_name_; }
72
74 const std::string& uuid() const;
75
78
80 Result<
81 std::reference_wrapper<const std::unordered_map<int32_t, std::shared_ptr<Schema>>>>
82 schemas() const;
83
86
88 Result<std::reference_wrapper<
89 const std::unordered_map<int32_t, std::shared_ptr<PartitionSpec>>>>
90 specs() const;
91
94
96 Result<std::reference_wrapper<
97 const std::unordered_map<int32_t, std::shared_ptr<SortOrder>>>>
98 sort_orders() const;
99
102
104 std::string_view metadata_file_location() const;
105
107 std::string_view location() const;
108
111
114
120
122 const std::vector<std::shared_ptr<Snapshot>>& snapshots() const;
123
125 const std::vector<SnapshotLogEntry>& history() const;
126
128 const std::shared_ptr<FileIO>& io() const;
129
131 const std::shared_ptr<TableMetadata>& metadata() const;
132
134 const std::shared_ptr<Catalog>& catalog() const;
135
137 const std::shared_ptr<MetricsReporter>& reporter() const;
138
143 const Labels& labels() const;
144
147
152 virtual Status Refresh();
153
159
162 const;
163
167
170
174
178
182
186
190
194
199
203
206
209
212
215
218
222
226
229
232
235
236 protected:
237 Table(TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
238 std::string metadata_location, std::shared_ptr<FileIO> io,
239 std::shared_ptr<Catalog> catalog, std::string full_name,
240 std::shared_ptr<MetricsReporter> reporter = nullptr,
241 std::unique_ptr<Labels> labels = nullptr);
242
243 const TableIdentifier identifier_;
244 const std::string full_name_;
245 std::shared_ptr<TableMetadata> metadata_;
246 std::string metadata_location_;
247 std::shared_ptr<FileIO> io_;
248 std::shared_ptr<Catalog> catalog_;
249 std::shared_ptr<MetricsReporter> reporter_;
250 std::unique_ptr<class TableMetadataCache> metadata_cache_;
251 const std::unique_ptr<const Labels> labels_;
252};
253
255class ICEBERG_EXPORT StagedTable final : public Table {
256 public:
258 TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
259 std::string metadata_location, std::shared_ptr<FileIO> io,
260 std::shared_ptr<Catalog> catalog, std::string full_name = "",
261 std::shared_ptr<MetricsReporter> reporter = nullptr);
262
263 ~StagedTable() override;
264
265 Status Refresh() override { return {}; }
266
268
269 private:
270 using Table::Table;
271};
272
274
275class ICEBERG_EXPORT StaticTable : public Table {
276 public:
278 TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
279 std::string metadata_location, std::shared_ptr<FileIO> io,
280 std::string full_name = "");
281
282 ~StaticTable() override;
283
284 Status Refresh() override;
285
287
289
291
293
295
297
299
301
303 override;
304
306
308
310
312
314
316
318
320
322
323 private:
324 using Table::Table;
325};
326
327} // namespace iceberg
A table created by stage-create and not yet committed.
Definition table.h:255
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:265
A read-only table.
Definition table.h:275
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< RewriteManifests > > NewRewriteManifests() override
Create a new RewriteManifests to rewrite manifest layout.
Result< std::shared_ptr< UpdateProperties > > NewUpdateProperties() override
Create a new UpdateProperties to update table properties and commit the changes.
Result< std::shared_ptr< ReplacePartitions > > NewReplacePartitions() override
Create a new ReplacePartitions to dynamically overwrite partitions 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:45
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.
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, std::unique_ptr< Labels > labels=nullptr)
Construct a 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:71
virtual Result< std::shared_ptr< UpdateSortOrder > > NewUpdateSortOrder()
Create a new UpdateSortOrder to update the table sort order and commit the changes.
Result< std::unique_ptr< MetadataTable > > Inspect(MetadataTableKind kind) const
Construct a metadata table inspector for this table.
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< ReplacePartitions > > NewReplacePartitions()
Create a new ReplacePartitions to dynamically overwrite partitions and commit the changes.
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:68
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.
const Labels & labels() const
Returns the catalog-provided labels for this table.
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.
virtual Result< std::shared_ptr< RewriteManifests > > NewRewriteManifests()
Create a new RewriteManifests to rewrite manifest layout.
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.
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.
Definition expected.h:1199
Define symbol visibility macros for core Iceberg APIs.
Catalog-provided labels for tables and their fields.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:34
std::chrono::time_point< std::chrono::system_clock, std::chrono::milliseconds > TimePointMs
A time point in milliseconds.
Definition timepoint.h:33
MetadataTableKind
Iceberg metadata tables exposed by Table::Inspect().
Definition metadata_table.h:40
Define snapshot metadata types.
Optional catalog-provided labels returned when a table is loaded.
Definition labels.h:46
Identifies a table in iceberg catalog.
Definition table_identifier.h:46
Provide time point conversion helpers.
Updates the table location.