30#include <unordered_map>
31#include <unordered_set>
48 std::shared_ptr<TransactionContext> ctx);
87 std::string_view doc =
"",
88 std::optional<Literal> default_value = std::nullopt);
114 std::shared_ptr<Type> type, std::string_view doc =
"",
115 std::optional<Literal> default_value = std::nullopt);
137 std::string_view doc =
"",
138 std::optional<Literal> default_value = std::nullopt);
165 std::string_view name, std::shared_ptr<Type> type,
166 std::string_view doc =
"",
167 std::optional<Literal> default_value = std::nullopt);
202 std::shared_ptr<PrimitiveType> new_type);
228 std::optional<Literal> new_default);
339 enum class MoveType {
kFirst, kBefore, kAfter };
342 int32_t reference_field_id;
345 static Move First(int32_t field_id);
347 static Move Before(int32_t field_id, int32_t reference_field_id);
349 static Move After(int32_t field_id, int32_t reference_field_id);
352 Kind
kind() const final {
return Kind::kUpdateSchema; }
362 std::shared_ptr<Schema> schema;
363 int32_t new_last_column_id;
364 std::unordered_map<std::string, std::string> updated_props;
375 explicit UpdateSchema(std::shared_ptr<TransactionContext> ctx);
386 UpdateSchema& AddColumnInternal(std::optional<std::string_view> parent,
387 std::string_view name,
bool is_optional,
388 std::shared_ptr<Type> type, std::string_view doc,
389 std::optional<Literal> default_value);
396 UpdateSchema& UpdateColumnRequirementInternal(std::string_view name,
bool is_optional);
399 int32_t AssignNewColumnId();
403 std::string_view name)
const;
414 std::string_view name)
const;
423 std::string CaseSensitivityAwareName(std::string_view name)
const;
432 std::shared_ptr<Schema> schema_;
433 int32_t last_column_id_;
434 bool allow_incompatible_changes_{
false};
435 bool case_sensitive_{
true};
436 std::vector<std::string> identifier_field_names_;
440 std::unordered_map<int32_t, int32_t> id_to_parent_;
442 std::unordered_set<int32_t> deletes_;
444 std::unordered_map<int32_t, std::shared_ptr<SchemaField>> updates_;
446 std::unordered_map<int32_t, std::vector<int32_t>> parent_to_added_ids_;
448 std::unordered_map<std::string, int32_t> added_name_to_id_;
450 std::unordered_map<int32_t, std::vector<Move>> moves_;
Base class for all kinds of table metadata updates.
Definition pending_update.h:41
API for schema evolution.
Definition update_schema.h:45
UpdateSchema & AddColumn(std::optional< std::string_view > parent, std::string_view name, std::shared_ptr< Type > type, std::string_view doc="", std::optional< Literal > default_value=std::nullopt)
Add a new optional column to a nested struct with documentation.
UpdateSchema & RequireColumn(std::string_view name)
Update a column to be required.
UpdateSchema & DeleteColumn(std::string_view name)
Delete a column in the schema.
UpdateSchema & SetIdentifierFields(const std::span< std::string_view > &names)
Set the identifier fields given a set of field names.
Kind kind() const final
Return the kind of this pending update.
Definition update_schema.h:352
UpdateSchema & MoveFirst(std::string_view name)
Move a column from its current position to the start of the schema or its parent struct.
UpdateSchema & MakeColumnOptional(std::string_view name)
Update a column to be optional.
UpdateSchema & CaseSensitive(bool case_sensitive)
Determines if the case of schema needs to be considered when comparing column names.
UpdateSchema & AllowIncompatibleChanges()
Allow incompatible changes to the schema.
Result< ApplyResult > Apply()
Apply the pending changes to the original schema and return the result.
bool IsRetryable() const override
Schema updates are not retryable.
Definition update_schema.h:359
UpdateSchema & UpdateColumn(std::string_view name, std::shared_ptr< PrimitiveType > new_type)
Update a column in the schema to a new primitive type.
UpdateSchema & MoveAfter(std::string_view name, std::string_view after_name)
Move a column from its current position to directly after a reference column.
UpdateSchema & AddColumn(std::string_view name, std::shared_ptr< Type > type, std::string_view doc="", std::optional< Literal > default_value=std::nullopt)
Add a new optional top-level column with documentation.
UpdateSchema & AddRequiredColumn(std::string_view name, std::shared_ptr< Type > type, std::string_view doc="", std::optional< Literal > default_value=std::nullopt)
Add a new required top-level column with documentation.
UpdateSchema & AddRequiredColumn(std::optional< std::string_view > parent, std::string_view name, std::shared_ptr< Type > type, std::string_view doc="", std::optional< Literal > default_value=std::nullopt)
Add a new required column to a nested struct with documentation.
UpdateSchema & UnionByNameWith(std::shared_ptr< Schema > new_schema)
Applies all field additions and updates from the provided new schema to the existing schema to create...
UpdateSchema & MoveBefore(std::string_view name, std::string_view before_name)
Move a column from its current position to directly before a reference column.
UpdateSchema & RenameColumn(std::string_view name, std::string_view new_name)
Rename a column in the schema.
UpdateSchema & UpdateColumnDefault(std::string_view name, std::optional< Literal > new_default)
Update the write-default value for a column (v3+).
UpdateSchema & UpdateColumnDoc(std::string_view name, std::string_view new_doc)
Update the documentation string for a column.
Define symbol visibility macros for core Iceberg APIs.
Define typed literal values used by expressions.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
@ kFirst
Nulls are sorted first.
std::expected< T, E > Result
Result alias.
Definition result.h:88
Define Result, Status, and error helpers.
Definition update_schema.h:361
Represents a column move operation within a struct (internal use only).
Definition update_schema.h:338