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
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
72
73 // Helper methods to deduplicate requirements to add.
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:
122 const std::vector<std::unique_ptr<TableUpdate>>& table_updates);
123
133 const TableMetadata& base,
134 const std::vector<std::unique_ptr<TableUpdate>>& table_updates);
135
145 const TableMetadata& base,
146 const std::vector<std::unique_ptr<TableUpdate>>& table_updates);
147
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
static Result< std::vector< std::unique_ptr< TableRequirement > > > ForReplaceTable(const TableMetadata &base, const std::vector< std::unique_ptr< TableUpdate > > &table_updates)
Generate requirements for replacing an existing table.
static Result< std::vector< std::unique_ptr< TableRequirement > > > ForCreateTable(const std::vector< std::unique_ptr< TableUpdate > > &table_updates)
Generate requirements for creating a new table.
static Result< bool > IsCreate(const std::vector< std::unique_ptr< TableRequirement > > &requirements)
Check if the requirements are for table creation.
static Result< std::vector< std::unique_ptr< TableRequirement > > > ForUpdateTable(const TableMetadata &base, const std::vector< std::unique_ptr< TableUpdate > > &table_updates)
Generate requirements for updating an existing table.
Context for generating table requirements.
Definition table_requirements.h:45
void RequireCurrentSchemaIdUnchanged()
Require that the current schema ID remains unchanged.
void RequireDefaultSpecIdUnchanged()
Require that the default spec ID remains unchanged.
void RequireDefaultSortOrderIdUnchanged()
Require that the default sort order ID remains unchanged.
void RequireLastAssignedPartitionIdUnchanged()
Require that the last assigned partition ID remains unchanged.
TableUpdateContext(const TableMetadata *base, bool is_replace)
Construct a context for requirement generation.
Definition table_requirements.h:51
bool AddChangedRef(const std::string &ref_name)
Track a changed ref and return whether it was newly added.
bool is_replace() const
Check if this is a replace operation.
Definition table_requirements.h:68
void RequireNoBranchesChanged()
Require that no branches have been changed.
Result< std::vector< std::unique_ptr< TableRequirement > > > Build()
Build and return the list of requirements.
void RequireLastAssignedFieldIdUnchanged()
Require that the last assigned field ID remains unchanged.
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
std::expected< T, E > Result
Result alias.
Definition result.h:88
STL namespace.
Represents the metadata for an Iceberg table.
Definition table_metadata.h:73