forked from apache/iceberg-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable_update.cc
More file actions
207 lines (152 loc) · 6.24 KB
/
Copy pathtable_update.cc
File metadata and controls
207 lines (152 loc) · 6.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "iceberg/table_update.h"
#include "iceberg/exception.h"
#include "iceberg/table_metadata.h"
#include "iceberg/table_requirements.h"
namespace iceberg::table {
// AssignUUID
void AssignUUID::ApplyTo(TableMetadataBuilder& builder) const {
builder.AssignUUID(uuid_);
}
void AssignUUID::GenerateRequirements(TableUpdateContext& context) const {
// AssignUUID does not generate additional requirements.
}
// UpgradeFormatVersion
void UpgradeFormatVersion::ApplyTo(TableMetadataBuilder& builder) const {
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
}
void UpgradeFormatVersion::GenerateRequirements(TableUpdateContext& context) const {
// UpgradeFormatVersion doesn't generate any requirements
}
// AddSchema
void AddSchema::ApplyTo(TableMetadataBuilder& builder) const {
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
}
void AddSchema::GenerateRequirements(TableUpdateContext& context) const {
context.RequireLastAssignedFieldIdUnchanged();
}
// SetCurrentSchema
void SetCurrentSchema::ApplyTo(TableMetadataBuilder& builder) const {
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
}
void SetCurrentSchema::GenerateRequirements(TableUpdateContext& context) const {
context.RequireCurrentSchemaIdUnchanged();
}
// AddPartitionSpec
void AddPartitionSpec::ApplyTo(TableMetadataBuilder& builder) const {
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
}
void AddPartitionSpec::GenerateRequirements(TableUpdateContext& context) const {
context.RequireLastAssignedPartitionIdUnchanged();
}
// SetDefaultPartitionSpec
void SetDefaultPartitionSpec::ApplyTo(TableMetadataBuilder& builder) const {
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
}
void SetDefaultPartitionSpec::GenerateRequirements(TableUpdateContext& context) const {
context.RequireDefaultSpecIdUnchanged();
}
// RemovePartitionSpecs
void RemovePartitionSpecs::ApplyTo(TableMetadataBuilder& builder) const {
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
}
void RemovePartitionSpecs::GenerateRequirements(TableUpdateContext& context) const {
context.RequireDefaultSpecIdUnchanged();
context.RequireNoBranchesChanged();
}
// RemoveSchemas
void RemoveSchemas::ApplyTo(TableMetadataBuilder& builder) const {
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
}
void RemoveSchemas::GenerateRequirements(TableUpdateContext& context) const {
context.RequireCurrentSchemaIdUnchanged();
context.RequireNoBranchesChanged();
}
// AddSortOrder
void AddSortOrder::ApplyTo(TableMetadataBuilder& builder) const {
builder.AddSortOrder(sort_order_);
}
void AddSortOrder::GenerateRequirements(TableUpdateContext& context) const {
// AddSortOrder doesn't generate any requirements
}
// SetDefaultSortOrder
void SetDefaultSortOrder::ApplyTo(TableMetadataBuilder& builder) const {
builder.SetDefaultSortOrder(sort_order_id_);
}
void SetDefaultSortOrder::GenerateRequirements(TableUpdateContext& context) const {
context.RequireDefaultSortOrderIdUnchanged();
}
// AddSnapshot
void AddSnapshot::ApplyTo(TableMetadataBuilder& builder) const {
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
}
void AddSnapshot::GenerateRequirements(TableUpdateContext& context) const {
// AddSnapshot doesn't generate any requirements
}
// RemoveSnapshots
void RemoveSnapshots::ApplyTo(TableMetadataBuilder& builder) const {}
void RemoveSnapshots::GenerateRequirements(TableUpdateContext& context) const {
// RemoveSnapshots doesn't generate any requirements
}
// RemoveSnapshotRef
void RemoveSnapshotRef::ApplyTo(TableMetadataBuilder& builder) const {
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
}
void RemoveSnapshotRef::GenerateRequirements(TableUpdateContext& context) const {
// RemoveSnapshotRef doesn't generate any requirements
}
// SetSnapshotRef
void SetSnapshotRef::ApplyTo(TableMetadataBuilder& builder) const {
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
}
void SetSnapshotRef::GenerateRequirements(TableUpdateContext& context) const {
bool added = context.AddChangedRef(ref_name_);
if (added && context.base() != nullptr && !context.is_replace()) {
const auto& refs = context.base()->refs;
auto it = refs.find(ref_name_);
// Require that the ref does not exist (nullopt) or is the same as the base snapshot
std::optional<int64_t> base_snapshot_id =
(it != refs.end()) ? std::make_optional(it->second->snapshot_id) : std::nullopt;
context.AddRequirement(
std::make_unique<table::AssertRefSnapshotID>(ref_name_, base_snapshot_id));
}
}
// SetProperties
void SetProperties::ApplyTo(TableMetadataBuilder& builder) const {
builder.SetProperties(updated_);
}
void SetProperties::GenerateRequirements(TableUpdateContext& context) const {
// SetProperties doesn't generate any requirements
}
// RemoveProperties
void RemoveProperties::ApplyTo(TableMetadataBuilder& builder) const {
builder.RemoveProperties(removed_);
}
void RemoveProperties::GenerateRequirements(TableUpdateContext& context) const {
// RemoveProperties doesn't generate any requirements
}
// SetLocation
void SetLocation::ApplyTo(TableMetadataBuilder& builder) const {
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
}
void SetLocation::GenerateRequirements(TableUpdateContext& context) const {
// SetLocation doesn't generate any requirements
}
} // namespace iceberg::table