|
33 | 33 | #include "iceberg/result.h" |
34 | 34 | #include "iceberg/type_fwd.h" |
35 | 35 |
|
36 | | - namespace iceberg { |
| 36 | +namespace iceberg { |
37 | 37 |
|
38 | | - /// \brief Base class for update requirement operations |
39 | | - /// |
40 | | - /// Represents a requirement that must be validated before applying |
41 | | - /// metadata updates to a table. Each concrete subclass represents |
42 | | - /// a specific type of requirement check. |
43 | | - class ICEBERG_EXPORT TableRequirement { |
44 | | - public: |
45 | | - virtual ~TableRequirement() = default; |
46 | | - |
47 | | - /// \brief Validate this requirement against table metadata |
48 | | - /// |
49 | | - /// \param base The base table metadata to validate against (may be nullptr) |
50 | | - /// \return Status indicating success or failure with error details |
51 | | - virtual Status Validate(const TableMetadata* base) const = 0; |
52 | | - }; |
53 | | - |
54 | | - /// \brief Requirement that the table does not exist |
| 38 | +/// \brief Base class for update requirement operations |
| 39 | +/// |
| 40 | +/// Represents a requirement that must be validated before applying |
| 41 | +/// metadata updates to a table. Each concrete subclass represents |
| 42 | +/// a specific type of requirement check. |
| 43 | +class ICEBERG_EXPORT TableRequirement { |
| 44 | + public: |
| 45 | + virtual ~TableRequirement() = default; |
| 46 | + |
| 47 | + /// \brief Validate this requirement against table metadata |
55 | 48 | /// |
56 | | - /// This requirement is used when creating a new table to ensure |
57 | | - /// it doesn't already exist. |
58 | | - class ICEBERG_EXPORT AssertTableDoesNotExist : public TableRequirement { |
59 | | - public: |
60 | | - AssertTableDoesNotExist() = default; |
| 49 | + /// \param base The base table metadata to validate against (may be nullptr) |
| 50 | + /// \return Status indicating success or failure with error details |
| 51 | + virtual Status Validate(const TableMetadata* base) const = 0; |
| 52 | +}; |
61 | 53 |
|
62 | | - Status Validate(const TableMetadata* base) const override; |
63 | | - }; |
| 54 | +/// \brief Requirement that the table does not exist |
| 55 | +/// |
| 56 | +/// This requirement is used when creating a new table to ensure |
| 57 | +/// it doesn't already exist. |
| 58 | +class ICEBERG_EXPORT AssertTableDoesNotExist : public TableRequirement { |
| 59 | + public: |
| 60 | + AssertTableDoesNotExist() = default; |
64 | 61 |
|
65 | | - /// \brief Requirement that the table UUID matches the expected value |
66 | | - /// |
67 | | - /// This ensures the table hasn't been replaced or recreated between |
68 | | - /// reading the metadata and attempting to update it. |
69 | | - class ICEBERG_EXPORT AssertTableUUID : public TableRequirement { |
70 | | - public: |
71 | | - explicit AssertTableUUID(std::string uuid) : uuid_(std::move(uuid)) {} |
| 62 | + Status Validate(const TableMetadata* base) const override; |
| 63 | +}; |
72 | 64 |
|
73 | | - const std::string& uuid() const { return uuid_; } |
| 65 | +/// \brief Requirement that the table UUID matches the expected value |
| 66 | +/// |
| 67 | +/// This ensures the table hasn't been replaced or recreated between |
| 68 | +/// reading the metadata and attempting to update it. |
| 69 | +class ICEBERG_EXPORT AssertTableUUID : public TableRequirement { |
| 70 | + public: |
| 71 | + explicit AssertTableUUID(std::string uuid) : uuid_(std::move(uuid)) {} |
74 | 72 |
|
75 | | - Status Validate(const TableMetadata* base) const override; |
| 73 | + const std::string& uuid() const { return uuid_; } |
76 | 74 |
|
77 | | - private: |
78 | | - std::string uuid_; |
79 | | - }; |
| 75 | + Status Validate(const TableMetadata* base) const override; |
80 | 76 |
|
81 | | - /// \brief Requirement that a reference (branch or tag) points to a specific snapshot |
82 | | - /// |
83 | | - /// This requirement validates that a named reference (branch or tag) either: |
84 | | - /// - Points to the expected snapshot ID |
85 | | - /// - Does not exist (if snapshot_id is nullopt) |
86 | | - class ICEBERG_EXPORT AssertRefSnapshotID : public TableRequirement { |
87 | | - public: |
88 | | - AssertRefSnapshotID(std::string ref_name, std::optional<int64_t> snapshot_id) |
89 | | - : ref_name_(std::move(ref_name)), snapshot_id_(snapshot_id) {} |
| 77 | + private: |
| 78 | + std::string uuid_; |
| 79 | +}; |
| 80 | + |
| 81 | +/// \brief Requirement that a reference (branch or tag) points to a specific snapshot |
| 82 | +/// |
| 83 | +/// This requirement validates that a named reference (branch or tag) either: |
| 84 | +/// - Points to the expected snapshot ID |
| 85 | +/// - Does not exist (if snapshot_id is nullopt) |
| 86 | +class ICEBERG_EXPORT AssertTableRefSnapshotID : public TableRequirement { |
| 87 | + public: |
| 88 | + AssertTableRefSnapshotID(std::string ref_name, std::optional<int64_t> snapshot_id) |
| 89 | + : ref_name_(std::move(ref_name)), snapshot_id_(snapshot_id) {} |
90 | 90 |
|
91 | | - const std::string& ref_name() const { return ref_name_; } |
| 91 | + const std::string& ref_name() const { return ref_name_; } |
92 | 92 |
|
93 | | - const std::optional<int64_t>& snapshot_id() const { return snapshot_id_; } |
| 93 | + const std::optional<int64_t>& snapshot_id() const { return snapshot_id_; } |
94 | 94 |
|
95 | | - Status Validate(const TableMetadata* base) const override; |
| 95 | + Status Validate(const TableMetadata* base) const override; |
96 | 96 |
|
97 | | - private: |
98 | | - std::string ref_name_; |
99 | | - std::optional<int64_t> snapshot_id_; |
100 | | - }; |
| 97 | + private: |
| 98 | + std::string ref_name_; |
| 99 | + std::optional<int64_t> snapshot_id_; |
| 100 | +}; |
101 | 101 |
|
102 | | - /// \brief Requirement that the last assigned field ID matches |
103 | | - /// |
104 | | - /// This ensures the schema hasn't been modified (by adding fields) |
105 | | - /// since the metadata was read. |
106 | | - class ICEBERG_EXPORT AssertLastAssignedFieldId : public TableRequirement { |
107 | | - public: |
108 | | - explicit AssertLastAssignedFieldId(int32_t last_assigned_field_id) |
109 | | - : last_assigned_field_id_(last_assigned_field_id) {} |
| 102 | +/// \brief Requirement that the last assigned field ID matches |
| 103 | +/// |
| 104 | +/// This ensures the schema hasn't been modified (by adding fields) |
| 105 | +/// since the metadata was read. |
| 106 | +class ICEBERG_EXPORT AssertCurrentTableLastAssignedFieldId : public TableRequirement { |
| 107 | + public: |
| 108 | + explicit AssertCurrentTableLastAssignedFieldId(int32_t last_assigned_field_id) |
| 109 | + : last_assigned_field_id_(last_assigned_field_id) {} |
110 | 110 |
|
111 | | - int32_t last_assigned_field_id() const { return last_assigned_field_id_; } |
| 111 | + int32_t last_assigned_field_id() const { return last_assigned_field_id_; } |
112 | 112 |
|
113 | | - Status Validate(const TableMetadata* base) const override; |
| 113 | + Status Validate(const TableMetadata* base) const override; |
114 | 114 |
|
115 | | - private: |
116 | | - int32_t last_assigned_field_id_; |
117 | | - }; |
| 115 | + private: |
| 116 | + int32_t last_assigned_field_id_; |
| 117 | +}; |
118 | 118 |
|
119 | | - /// \brief Requirement that the current schema ID matches |
120 | | - /// |
121 | | - /// This ensures the active schema hasn't changed since the |
122 | | - /// metadata was read. |
123 | | - class ICEBERG_EXPORT AssertCurrentSchemaID : public TableRequirement { |
124 | | - public: |
125 | | - explicit AssertCurrentSchemaID(int32_t schema_id) : schema_id_(schema_id) {} |
| 119 | +/// \brief Requirement that the current schema ID matches |
| 120 | +/// |
| 121 | +/// This ensures the active schema hasn't changed since the |
| 122 | +/// metadata was read. |
| 123 | +class ICEBERG_EXPORT AssertCurrentTableSchemaID : public TableRequirement { |
| 124 | + public: |
| 125 | + explicit AssertCurrentTableSchemaID(int32_t schema_id) : schema_id_(schema_id) {} |
126 | 126 |
|
127 | | - int32_t schema_id() const { return schema_id_; } |
| 127 | + int32_t schema_id() const { return schema_id_; } |
128 | 128 |
|
129 | | - Status Validate(const TableMetadata* base) const override; |
| 129 | + Status Validate(const TableMetadata* base) const override; |
130 | 130 |
|
131 | | - private: |
132 | | - int32_t schema_id_; |
133 | | - }; |
| 131 | + private: |
| 132 | + int32_t schema_id_; |
| 133 | +}; |
134 | 134 |
|
135 | | - /// \brief Requirement that the last assigned partition ID matches |
136 | | - /// |
137 | | - /// This ensures partition specs haven't been modified since the |
138 | | - /// metadata was read. |
139 | | - class ICEBERG_EXPORT AssertLastAssignedPartitionId : public TableRequirement { |
140 | | - public: |
141 | | - explicit AssertLastAssignedPartitionId(int32_t last_assigned_partition_id) |
142 | | - : last_assigned_partition_id_(last_assigned_partition_id) {} |
| 135 | +/// \brief Requirement that the last assigned partition ID matches |
| 136 | +/// |
| 137 | +/// This ensures partition specs haven't been modified since the |
| 138 | +/// metadata was read. |
| 139 | +class ICEBERG_EXPORT AssertCurrentTableLastAssignedPartitionId : public TableRequirement { |
| 140 | + public: |
| 141 | + explicit AssertCurrentTableLastAssignedPartitionId(int32_t last_assigned_partition_id) |
| 142 | + : last_assigned_partition_id_(last_assigned_partition_id) {} |
143 | 143 |
|
144 | | - int32_t last_assigned_partition_id() const { return last_assigned_partition_id_; } |
| 144 | + int32_t last_assigned_partition_id() const { return last_assigned_partition_id_; } |
145 | 145 |
|
146 | | - Status Validate(const TableMetadata* base) const override; |
| 146 | + Status Validate(const TableMetadata* base) const override; |
147 | 147 |
|
148 | | - private: |
149 | | - int32_t last_assigned_partition_id_; |
150 | | - }; |
| 148 | + private: |
| 149 | + int32_t last_assigned_partition_id_; |
| 150 | +}; |
151 | 151 |
|
152 | | - /// \brief Requirement that the default partition spec ID matches |
153 | | - /// |
154 | | - /// This ensures the default partition spec hasn't changed since |
155 | | - /// the metadata was read. |
156 | | - class ICEBERG_EXPORT AssertDefaultSpecID : public TableRequirement { |
157 | | - public: |
158 | | - explicit AssertDefaultSpecID(int32_t spec_id) : spec_id_(spec_id) {} |
| 152 | +/// \brief Requirement that the default partition spec ID matches |
| 153 | +/// |
| 154 | +/// This ensures the default partition spec hasn't changed since |
| 155 | +/// the metadata was read. |
| 156 | +class ICEBERG_EXPORT AssertDefaultTableSpecID : public TableRequirement { |
| 157 | + public: |
| 158 | + explicit AssertDefaultTableSpecID(int32_t spec_id) : spec_id_(spec_id) {} |
159 | 159 |
|
160 | | - int32_t spec_id() const { return spec_id_; } |
| 160 | + int32_t spec_id() const { return spec_id_; } |
161 | 161 |
|
162 | | - Status Validate(const TableMetadata* base) const override; |
| 162 | + Status Validate(const TableMetadata* base) const override; |
163 | 163 |
|
164 | | - private: |
165 | | - int32_t spec_id_; |
166 | | - }; |
| 164 | + private: |
| 165 | + int32_t spec_id_; |
| 166 | +}; |
167 | 167 |
|
168 | | - /// \brief Requirement that the default sort order ID matches |
169 | | - /// |
170 | | - /// This ensures the default sort order hasn't changed since |
171 | | - /// the metadata was read. |
172 | | - class ICEBERG_EXPORT AssertDefaultSortOrderID : public TableRequirement { |
173 | | - public: |
174 | | - explicit AssertDefaultSortOrderID(int32_t sort_order_id) |
175 | | - : sort_order_id_(sort_order_id) {} |
| 168 | +/// \brief Requirement that the default sort order ID matches |
| 169 | +/// |
| 170 | +/// This ensures the default sort order hasn't changed since |
| 171 | +/// the metadata was read. |
| 172 | +class ICEBERG_EXPORT AssertDefaultTableSortOrderID : public TableRequirement { |
| 173 | + public: |
| 174 | + explicit AssertDefaultTableSortOrderID(int32_t sort_order_id) |
| 175 | + : sort_order_id_(sort_order_id) {} |
176 | 176 |
|
177 | | - int32_t sort_order_id() const { return sort_order_id_; } |
| 177 | + int32_t sort_order_id() const { return sort_order_id_; } |
178 | 178 |
|
179 | | - Status Validate(const TableMetadata* base) const override; |
| 179 | + Status Validate(const TableMetadata* base) const override; |
180 | 180 |
|
181 | | - private: |
182 | | - int32_t sort_order_id_; |
183 | | - }; |
| 181 | + private: |
| 182 | + int32_t sort_order_id_; |
| 183 | +}; |
184 | 184 |
|
185 | 185 | } // namespace iceberg |
0 commit comments