zhjwpku commented on code in PR #408: URL: https://github.com/apache/iceberg-cpp/pull/408#discussion_r2670695658
########## src/iceberg/update/snapshot_update.h: ########## @@ -0,0 +1,221 @@ +/* + * 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. + */ + +#pragma once + +#include <atomic> +#include <functional> +#include <memory> +#include <optional> +#include <string> +#include <unordered_map> +#include <unordered_set> +#include <vector> + +#include "iceberg/catalog.h" +#include "iceberg/iceberg_export.h" +#include "iceberg/manifest/manifest_list.h" +#include "iceberg/result.h" +#include "iceberg/snapshot.h" +#include "iceberg/table_metadata.h" +#include "iceberg/transaction.h" +#include "iceberg/type_fwd.h" +#include "iceberg/update/pending_update.h" + +namespace iceberg { + +/// \brief Base class for operations that produce snapshots. +/// +/// This class provides common functionality for creating new snapshots, +/// including manifest list writing, commit retries, and cleanup. +/// +class ICEBERG_EXPORT SnapshotUpdate : public PendingUpdate { + public: + /// \brief Result of applying a snapshot update + struct ApplyResult { + /// \brief The new snapshot + std::shared_ptr<Snapshot> snapshot; + std::string target_branch; + bool stage_only = false; + }; + + ~SnapshotUpdate() override = default; + + /// \brief Set a callback to delete files instead of the table's default. + /// + /// \param delete_func A function used to delete file locations + /// \return Reference to this for method chaining + /// \tparam T The concrete subclass type + template <typename T> + requires std::is_base_of_v<SnapshotUpdate, T> + T& DeleteWith(std::function<Status(const std::string&)> delete_func) { + delete_func_ = std::move(delete_func); + return static_cast<T&>(*this); + } + + /// \brief Stage a snapshot in table metadata, but not update the current snapshot id. + /// + /// \return Reference to this for method chaining + /// \tparam T The concrete subclass type + template <typename T> + requires std::is_base_of_v<SnapshotUpdate, T> + T& StageOnly() { + stage_only_ = true; + return static_cast<T&>(*this); + } + + /// \brief Apply the update's changes to create a new snapshot. + /// + /// This method validates the changes, applies them to the metadata, + /// and creates a new snapshot without committing it. The snapshot + /// is stored internally and can be accessed after Apply() succeeds. + /// + /// \return A result containing the new snapshot, or an error + Result<ApplyResult> Apply(); + + /// \brief Finalizes the snapshot, cleaning up any uncommitted files. + /// + /// \return Status indicating success or failure + Status Finalize(); Review Comment: Add Finalize as a `PendingUpdate` method and default to just return success. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
