iceberg-cpp
Loading...
Searching...
No Matches
table_requirements.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
28
29#include <memory>
30#include <string>
31#include <unordered_set>
32#include <vector>
33
34#include "iceberg/iceberg_export.h"
36#include "iceberg/type_fwd.h"
37
38namespace iceberg {
39
45class ICEBERG_EXPORT TableUpdateContext {
46 public:
51 TableUpdateContext(const TableMetadata* base, bool is_replace)
52 : base_(base), is_replace_(is_replace) {}
53
54 // Delete copy operations (contains unique_ptr members)
56 TableUpdateContext& operator=(const TableUpdateContext&) = delete;
57
58 // Enable move construction only (assignment deleted due to const members)
59 TableUpdateContext(TableUpdateContext&&) noexcept = default;
60
62 void AddRequirement(std::unique_ptr<TableRequirement> requirement);
63
65 const TableMetadata* base() const { return base_; }
66
68 bool is_replace() const { return is_replace_; }
69
71 Result<std::vector<std::unique_ptr<TableRequirement>>> Build();
72
73 // Helper methods to deduplicate requirements to add.
75 void RequireLastAssignedFieldIdUnchanged();
77 void RequireCurrentSchemaIdUnchanged();
79 void RequireLastAssignedPartitionIdUnchanged();
81 void RequireDefaultSpecIdUnchanged();
83 void RequireDefaultSortOrderIdUnchanged();
85 void RequireNoBranchesChanged();
86
90 bool AddChangedRef(const std::string& ref_name);
91
92 private:
93 const TableMetadata* base_;
94 const bool is_replace_;
95
96 std::vector<std::unique_ptr<TableRequirement>> requirements_;
97
98 // flags to avoid adding duplicate requirements
99 bool added_last_assigned_field_id_ = false;
100 bool added_current_schema_id_ = false;
101 bool added_last_assigned_partition_id_ = false;
102 bool added_default_spec_id_ = false;
103 bool added_default_sort_order_id_ = false;
104
105 // Track refs that have been changed to avoid duplicate requirements
106 std::unordered_set<std::string> changed_refs_;
107};
108
113class ICEBERG_EXPORT TableRequirements {
114 public:
121 static Result<std::vector<std::unique_ptr<TableRequirement>>> ForCreateTable(
122 const std::vector<std::unique_ptr<TableUpdate>>& table_updates);
123
132 static Result<std::vector<std::unique_ptr<TableRequirement>>> ForReplaceTable(
133 const TableMetadata& base,
134 const std::vector<std::unique_ptr<TableUpdate>>& table_updates);
135
144 static Result<std::vector<std::unique_ptr<TableRequirement>>> ForUpdateTable(
145 const TableMetadata& base,
146 const std::vector<std::unique_ptr<TableUpdate>>& table_updates);
147
149 static Result<bool> IsCreate(
150 const std::vector<std::unique_ptr<TableRequirement>>& requirements);
151};
152
153} // namespace iceberg
Base class for update requirement operations.
Definition table_requirement.h:44
Factory class for generating table requirements.
Definition table_requirements.h:113
Context for generating table requirements.
Definition table_requirements.h:45
TableUpdateContext(const TableMetadata *base, bool is_replace)
Construct a context for requirement generation.
Definition table_requirements.h:51
bool is_replace() const
Check if this is a replace operation.
Definition table_requirements.h:68
STL namespace.
Represents the metadata for an Iceberg table.
Definition table_metadata.h:72