Skip to content

Commit 2cb6080

Browse files
committed
feat: add PendingUpdateTyped template class
Add PendingUpdateTyped template class to provide type-safe ApplyTyped() method for table metadata changes. This allows different operations to return specific result types (e.g., vector<Snapshot> for ExpireSnapshots). Changes: - Add PendingUpdateTyped<T> template extending PendingUpdate - Add ApplyTyped() method returning Result<T> for typed operations - Keep Apply() returning Status in base PendingUpdate for compatibility - PendingUpdateTyped provides default Apply() implementation that calls ApplyTyped() - Update ExpireSnapshots to use ApplyTyped() instead of Apply() This design allows: - ExpireSnapshots to return Result<vector<Snapshot>> from ApplyTyped() - UpdateProperties to continue using Status Apply() from base - All PendingUpdate subclasses to work polymorphically through base interface
1 parent 720c566 commit 2cb6080

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

src/iceberg/pending_update.h

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "iceberg/iceberg_export.h"
2626
#include "iceberg/result.h"
2727
#include "iceberg/type_fwd.h"
28-
#include "iceberg/util/error_collector.h"
2928

3029
namespace iceberg {
3130

@@ -37,7 +36,7 @@ namespace iceberg {
3736
///
3837
/// This matches the Java Iceberg pattern where BaseTransaction stores a
3938
/// List<PendingUpdate> without type parameters.
40-
class ICEBERG_EXPORT PendingUpdate : public ErrorCollector {
39+
class ICEBERG_EXPORT PendingUpdate {
4140
public:
4241
virtual ~PendingUpdate() = default;
4342

@@ -69,4 +68,44 @@ class ICEBERG_EXPORT PendingUpdate : public ErrorCollector {
6968
PendingUpdate() = default;
7069
};
7170

71+
/// \brief Template class for type-safe table metadata changes using builder pattern
72+
///
73+
/// PendingUpdateTyped extends PendingUpdate with a type-safe Apply() method that
74+
/// returns the specific result type for each operation. Subclasses implement
75+
/// specific types of table updates such as schema changes, property updates, or
76+
/// snapshot-producing operations like appends and deletes.
77+
///
78+
/// Apply() can be used to validate and inspect the uncommitted changes before
79+
/// committing. Commit() applies the changes and commits them to the table.
80+
///
81+
/// \tparam T The type of result returned by Apply()
82+
template <typename T>
83+
class ICEBERG_EXPORT PendingUpdateTyped : public PendingUpdate {
84+
public:
85+
~PendingUpdateTyped() override = default;
86+
87+
/// \brief Apply the pending changes and return the uncommitted result (typed version)
88+
///
89+
/// This does not result in a permanent update.
90+
///
91+
/// \return the uncommitted changes that would be committed, or an error:
92+
/// - ValidationFailed: if pending changes cannot be applied
93+
/// - InvalidArgument: if pending changes are conflicting
94+
virtual Result<T> ApplyTyped() = 0;
95+
96+
/// \brief Apply the pending changes (base class override)
97+
///
98+
/// This implementation calls ApplyTyped() and discards the result.
99+
Status Apply() override {
100+
auto result = ApplyTyped();
101+
if (result.has_error()) {
102+
return Status(result.error());
103+
}
104+
return {};
105+
}
106+
107+
protected:
108+
PendingUpdateTyped() = default;
109+
};
110+
72111
} // namespace iceberg

src/iceberg/update/expire_snapshots.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ ExpireSnapshots& ExpireSnapshots::SetCleanupLevel(CleanupLevel level) {
5454
return *this;
5555
}
5656

57-
Result<std::vector<std::shared_ptr<Snapshot>>> ExpireSnapshots::Apply() {
57+
Result<std::vector<std::shared_ptr<Snapshot>>> ExpireSnapshots::ApplyTyped() {
5858
// Placeholder implementation - full snapshot expiration logic to be implemented
59-
return NotImplemented("ExpireSnapshots::Apply() is not yet implemented");
59+
return NotImplemented("ExpireSnapshots::ApplyTyped() is not yet implemented");
6060
}
6161

6262
Status ExpireSnapshots::Commit() {

src/iceberg/update/expire_snapshots.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class ICEBERG_EXPORT ExpireSnapshots
147147
///
148148
/// \return the list of snapshots that would be expired, or an error:
149149
/// - ValidationFailed: if pending changes cannot be applied
150-
Result<std::vector<std::shared_ptr<Snapshot>>> Apply() override;
150+
Result<std::vector<std::shared_ptr<Snapshot>>> ApplyTyped() override;
151151

152152
/// \brief Apply and commit the pending changes to the table
153153
///

0 commit comments

Comments
 (0)