Skip to content

Commit b2b38af

Browse files
authored
feat: add table update and requirement interface (#257)
1 parent 8906ff3 commit b2b38af

17 files changed

+1465
-10
lines changed

src/iceberg/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ set(ICEBERG_SOURCES
5252
table.cc
5353
table_metadata.cc
5454
table_properties.cc
55+
table_requirement.cc
56+
table_requirements.cc
5557
table_scan.cc
58+
table_update.cc
5659
transform.cc
5760
transform_function.cc
5861
type.cc

src/iceberg/catalog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ class ICEBERG_EXPORT Catalog {
123123
/// \return a Table instance or ErrorKind::kAlreadyExists if the table already exists
124124
virtual Result<std::unique_ptr<Table>> UpdateTable(
125125
const TableIdentifier& identifier,
126-
const std::vector<std::unique_ptr<UpdateRequirement>>& requirements,
127-
const std::vector<std::unique_ptr<MetadataUpdate>>& updates) = 0;
126+
const std::vector<std::unique_ptr<TableRequirement>>& requirements,
127+
const std::vector<std::unique_ptr<TableUpdate>>& updates) = 0;
128128

129129
/// \brief Start a transaction to create a table
130130
///

src/iceberg/catalog/memory/in_memory_catalog.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ Result<std::unique_ptr<Table>> InMemoryCatalog::CreateTable(
392392

393393
Result<std::unique_ptr<Table>> InMemoryCatalog::UpdateTable(
394394
const TableIdentifier& identifier,
395-
const std::vector<std::unique_ptr<UpdateRequirement>>& requirements,
396-
const std::vector<std::unique_ptr<MetadataUpdate>>& updates) {
395+
const std::vector<std::unique_ptr<TableRequirement>>& requirements,
396+
const std::vector<std::unique_ptr<TableUpdate>>& updates) {
397397
return NotImplemented("update table");
398398
}
399399

src/iceberg/catalog/memory/in_memory_catalog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ class ICEBERG_EXPORT InMemoryCatalog
7777

7878
Result<std::unique_ptr<Table>> UpdateTable(
7979
const TableIdentifier& identifier,
80-
const std::vector<std::unique_ptr<UpdateRequirement>>& requirements,
81-
const std::vector<std::unique_ptr<MetadataUpdate>>& updates) override;
80+
const std::vector<std::unique_ptr<TableRequirement>>& requirements,
81+
const std::vector<std::unique_ptr<TableUpdate>>& updates) override;
8282

8383
Result<std::shared_ptr<Transaction>> StageCreateTable(
8484
const TableIdentifier& identifier, const Schema& schema, const PartitionSpec& spec,

src/iceberg/meson.build

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ iceberg_sources = files(
7474
'table.cc',
7575
'table_metadata.cc',
7676
'table_properties.cc',
77+
'table_requirement.cc',
78+
'table_requirements.cc',
7779
'table_scan.cc',
80+
'table_update.cc',
7881
'transform.cc',
7982
'transform_function.cc',
8083
'type.cc',
@@ -169,7 +172,10 @@ install_headers(
169172
'table.h',
170173
'table_identifier.h',
171174
'table_metadata.h',
175+
'table_requirement.h',
176+
'table_requirements.h',
172177
'table_scan.h',
178+
'table_update.h',
173179
'transaction.h',
174180
'transform_function.h',
175181
'transform.h',

src/iceberg/result.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace iceberg {
3030
/// \brief Error types for iceberg.
3131
enum class ErrorKind {
3232
kAlreadyExists,
33+
kCommitFailed,
3334
kCommitStateUnknown,
3435
kDecompressError,
3536
kInvalid, // For general invalid errors
@@ -78,6 +79,7 @@ using Status = Result<void>;
7879
}
7980

8081
DEFINE_ERROR_FUNCTION(AlreadyExists)
82+
DEFINE_ERROR_FUNCTION(CommitFailed)
8183
DEFINE_ERROR_FUNCTION(CommitStateUnknown)
8284
DEFINE_ERROR_FUNCTION(DecompressError)
8385
DEFINE_ERROR_FUNCTION(Invalid)

src/iceberg/table_metadata.cc

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,21 @@
1919

2020
#include "iceberg/table_metadata.h"
2121

22+
#include <algorithm>
2223
#include <format>
2324
#include <string>
2425

2526
#include <nlohmann/json.hpp>
2627

28+
#include "iceberg/exception.h"
2729
#include "iceberg/file_io.h"
2830
#include "iceberg/json_internal.h"
2931
#include "iceberg/partition_spec.h"
3032
#include "iceberg/result.h"
3133
#include "iceberg/schema.h"
3234
#include "iceberg/snapshot.h"
3335
#include "iceberg/sort_order.h"
36+
#include "iceberg/table_update.h"
3437
#include "iceberg/util/gzip_internal.h"
3538
#include "iceberg/util/macros.h"
3639

@@ -196,4 +199,190 @@ Status TableMetadataUtil::Write(FileIO& io, const std::string& location,
196199
return io.WriteFile(location, json_string);
197200
}
198201

202+
// TableMetadataBuilder implementation
203+
204+
struct TableMetadataBuilder::Impl {};
205+
206+
TableMetadataBuilder::TableMetadataBuilder(int8_t format_version)
207+
: impl_(std::make_unique<Impl>()) {}
208+
209+
TableMetadataBuilder::TableMetadataBuilder(const TableMetadata* base)
210+
: impl_(std::make_unique<Impl>()) {}
211+
212+
TableMetadataBuilder::~TableMetadataBuilder() = default;
213+
214+
TableMetadataBuilder::TableMetadataBuilder(TableMetadataBuilder&&) noexcept = default;
215+
216+
TableMetadataBuilder& TableMetadataBuilder::operator=(TableMetadataBuilder&&) noexcept =
217+
default;
218+
219+
std::unique_ptr<TableMetadataBuilder> TableMetadataBuilder::BuildFromEmpty(
220+
int8_t format_version) {
221+
return std::unique_ptr<TableMetadataBuilder>(
222+
new TableMetadataBuilder(format_version)); // NOLINT
223+
}
224+
225+
std::unique_ptr<TableMetadataBuilder> TableMetadataBuilder::BuildFrom(
226+
const TableMetadata* base) {
227+
return std::unique_ptr<TableMetadataBuilder>(new TableMetadataBuilder(base)); // NOLINT
228+
}
229+
230+
TableMetadataBuilder& TableMetadataBuilder::SetMetadataLocation(
231+
std::string_view metadata_location) {
232+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
233+
}
234+
235+
TableMetadataBuilder& TableMetadataBuilder::SetPreviousMetadataLocation(
236+
std::string_view previous_metadata_location) {
237+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
238+
}
239+
240+
TableMetadataBuilder& TableMetadataBuilder::AssignUUID() {
241+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
242+
}
243+
244+
TableMetadataBuilder& TableMetadataBuilder::AssignUUID(std::string_view uuid) {
245+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
246+
;
247+
}
248+
249+
TableMetadataBuilder& TableMetadataBuilder::UpgradeFormatVersion(
250+
int8_t new_format_version) {
251+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
252+
}
253+
254+
TableMetadataBuilder& TableMetadataBuilder::SetCurrentSchema(
255+
std::shared_ptr<Schema> schema, int32_t new_last_column_id) {
256+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
257+
}
258+
259+
TableMetadataBuilder& TableMetadataBuilder::SetCurrentSchema(int32_t schema_id) {
260+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
261+
}
262+
263+
TableMetadataBuilder& TableMetadataBuilder::AddSchema(std::shared_ptr<Schema> schema) {
264+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
265+
}
266+
267+
TableMetadataBuilder& TableMetadataBuilder::SetDefaultPartitionSpec(
268+
std::shared_ptr<PartitionSpec> spec) {
269+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
270+
}
271+
272+
TableMetadataBuilder& TableMetadataBuilder::SetDefaultPartitionSpec(int32_t spec_id) {
273+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
274+
}
275+
276+
TableMetadataBuilder& TableMetadataBuilder::AddPartitionSpec(
277+
std::shared_ptr<PartitionSpec> spec) {
278+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
279+
}
280+
281+
TableMetadataBuilder& TableMetadataBuilder::RemovePartitionSpecs(
282+
const std::vector<int32_t>& spec_ids) {
283+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
284+
}
285+
286+
TableMetadataBuilder& TableMetadataBuilder::RemoveSchemas(
287+
const std::vector<int32_t>& schema_ids) {
288+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
289+
}
290+
291+
TableMetadataBuilder& TableMetadataBuilder::SetDefaultSortOrder(
292+
std::shared_ptr<SortOrder> order) {
293+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
294+
}
295+
296+
TableMetadataBuilder& TableMetadataBuilder::SetDefaultSortOrder(int32_t order_id) {
297+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
298+
}
299+
300+
TableMetadataBuilder& TableMetadataBuilder::AddSortOrder(
301+
std::shared_ptr<SortOrder> order) {
302+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
303+
}
304+
305+
TableMetadataBuilder& TableMetadataBuilder::AddSnapshot(
306+
std::shared_ptr<Snapshot> snapshot) {
307+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
308+
}
309+
310+
TableMetadataBuilder& TableMetadataBuilder::SetBranchSnapshot(int64_t snapshot_id,
311+
const std::string& branch) {
312+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
313+
}
314+
315+
TableMetadataBuilder& TableMetadataBuilder::SetRef(const std::string& name,
316+
std::shared_ptr<SnapshotRef> ref) {
317+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
318+
}
319+
320+
TableMetadataBuilder& TableMetadataBuilder::RemoveRef(const std::string& name) {
321+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
322+
}
323+
324+
TableMetadataBuilder& TableMetadataBuilder::RemoveSnapshots(
325+
const std::vector<std::shared_ptr<Snapshot>>& snapshots_to_remove) {
326+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
327+
}
328+
329+
TableMetadataBuilder& TableMetadataBuilder::RemoveSnapshots(
330+
const std::vector<int64_t>& snapshot_ids) {
331+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
332+
}
333+
334+
TableMetadataBuilder& TableMetadataBuilder::suppressHistoricalSnapshots() {
335+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
336+
}
337+
338+
TableMetadataBuilder& TableMetadataBuilder::SetStatistics(
339+
const std::shared_ptr<StatisticsFile>& statistics_file) {
340+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
341+
}
342+
343+
TableMetadataBuilder& TableMetadataBuilder::RemoveStatistics(int64_t snapshot_id) {
344+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
345+
}
346+
347+
TableMetadataBuilder& TableMetadataBuilder::SetPartitionStatistics(
348+
const std::shared_ptr<PartitionStatisticsFile>& partition_statistics_file) {
349+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
350+
}
351+
352+
TableMetadataBuilder& TableMetadataBuilder::RemovePartitionStatistics(
353+
int64_t snapshot_id) {
354+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
355+
}
356+
357+
TableMetadataBuilder& TableMetadataBuilder::SetProperties(
358+
const std::unordered_map<std::string, std::string>& updated) {
359+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
360+
}
361+
362+
TableMetadataBuilder& TableMetadataBuilder::RemoveProperties(
363+
const std::vector<std::string>& removed) {
364+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
365+
}
366+
367+
TableMetadataBuilder& TableMetadataBuilder::SetLocation(std::string_view location) {
368+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
369+
}
370+
371+
TableMetadataBuilder& TableMetadataBuilder::AddEncryptionKey(
372+
std::shared_ptr<EncryptedKey> key) {
373+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
374+
}
375+
376+
TableMetadataBuilder& TableMetadataBuilder::RemoveEncryptionKey(std::string_view key_id) {
377+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
378+
}
379+
380+
TableMetadataBuilder& TableMetadataBuilder::DiscardChanges() {
381+
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
382+
}
383+
384+
Result<std::unique_ptr<TableMetadata>> TableMetadataBuilder::Build() {
385+
return NotImplemented("TableMetadataBuilder::Build not implemented");
386+
}
387+
199388
} // namespace iceberg

0 commit comments

Comments
 (0)