50 static Result<std::shared_ptr<UpdateSchema>> Make(
51 std::shared_ptr<TransactionContext> ctx);
88 UpdateSchema& AddColumn(std::string_view name, std::shared_ptr<Type> type,
89 std::string_view doc =
"");
113 UpdateSchema& AddColumn(std::optional<std::string_view> parent, std::string_view name,
114 std::shared_ptr<Type> type, std::string_view doc =
"");
135 UpdateSchema& AddRequiredColumn(std::string_view name, std::shared_ptr<Type> type,
136 std::string_view doc =
"");
162 UpdateSchema& AddRequiredColumn(std::optional<std::string_view> parent,
163 std::string_view name, std::shared_ptr<Type> type,
164 std::string_view doc =
"");
181 UpdateSchema& RenameColumn(std::string_view name, std::string_view new_name);
199 std::shared_ptr<PrimitiveType> new_type);
211 UpdateSchema& UpdateColumnDoc(std::string_view name, std::string_view new_doc);
217 UpdateSchema& MakeColumnOptional(std::string_view name);
262 UpdateSchema& MoveBefore(std::string_view name, std::string_view before_name);
277 UpdateSchema& MoveAfter(std::string_view name, std::string_view after_name);
301 UpdateSchema& UnionByNameWith(std::shared_ptr<Schema> new_schema);
310 UpdateSchema& SetIdentifierFields(
const std::span<std::string_view>& names);
322 enum class MoveType {
kFirst, kBefore, kAfter };
325 int32_t reference_field_id;
328 static Move First(int32_t field_id);
330 static Move Before(int32_t field_id, int32_t reference_field_id);
332 static Move After(int32_t field_id, int32_t reference_field_id);
335 Kind
kind() const final {
return Kind::kUpdateSchema; }
345 std::shared_ptr<Schema> schema;
346 int32_t new_last_column_id;
347 std::unordered_map<std::string, std::string> updated_props;
355 Result<ApplyResult> Apply();
358 explicit UpdateSchema(std::shared_ptr<TransactionContext> ctx);
368 UpdateSchema& AddColumnInternal(std::optional<std::string_view> parent,
369 std::string_view name,
bool is_optional,
370 std::shared_ptr<Type> type, std::string_view doc);
377 UpdateSchema& UpdateColumnRequirementInternal(std::string_view name,
bool is_optional);
380 int32_t AssignNewColumnId();
383 Result<std::optional<std::reference_wrapper<const SchemaField>>> FindField(
384 std::string_view name)
const;
394 Result<std::optional<std::reference_wrapper<const SchemaField>>> FindFieldForUpdate(
395 std::string_view name)
const;
404 std::string CaseSensitivityAwareName(std::string_view name)
const;
407 Result<int32_t> FindFieldIdForMove(std::string_view name)
const;
413 std::shared_ptr<Schema> schema_;
414 int32_t last_column_id_;
415 bool allow_incompatible_changes_{
false};
416 bool case_sensitive_{
true};
417 std::vector<std::string> identifier_field_names_;
421 std::unordered_map<int32_t, int32_t> id_to_parent_;
423 std::unordered_set<int32_t> deletes_;
425 std::unordered_map<int32_t, std::shared_ptr<SchemaField>> updates_;
427 std::unordered_map<int32_t, std::vector<int32_t>> parent_to_added_ids_;
429 std::unordered_map<std::string, int32_t> added_name_to_id_;
431 std::unordered_map<int32_t, std::vector<Move>> moves_;