lishuxu commented on code in PR #321:
URL: https://github.com/apache/iceberg-cpp/pull/321#discussion_r2616173989


##########
src/iceberg/base_transaction.cc:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.
+ */
+
+#include "iceberg/base_transaction.h"
+
+#include <utility>
+
+#include "iceberg/catalog.h"
+#include "iceberg/pending_update.h"
+#include "iceberg/table.h"
+#include "iceberg/table_metadata.h"
+#include "iceberg/transaction_catalog.h"
+#include "iceberg/update/update_properties.h"
+#include "iceberg/util/macros.h"
+
+namespace iceberg {
+
+BaseTransaction::BaseTransaction(std::shared_ptr<const Table> table,
+                                 std::shared_ptr<Catalog> catalog)
+    : table_(std::move(table)) {
+  ICEBERG_DCHECK(table_ != nullptr, "table must not be null");
+  ICEBERG_DCHECK(catalog != nullptr, "catalog must not be null");
+  context_.identifier = table_->name();
+  context_.current_metadata = table_->metadata();
+  catalog_ = std::make_shared<TransactionCatalog>(std::move(catalog), this);
+}
+
+const std::shared_ptr<const Table>& BaseTransaction::table() const { return 
table_; }
+
+std::unique_ptr<UpdateProperties> BaseTransaction::UpdateProperties() {
+  auto update = CheckAndCreateUpdate<::iceberg::UpdateProperties>(
+      table_->name(), catalog_, CurrentMetadata());
+  if (!update.has_value()) {
+    ERROR_TO_EXCEPTION(update.error());
+  }
+
+  return std::move(update).value();
+}
+
+std::unique_ptr<AppendFiles> BaseTransaction::NewAppend() {
+  throw NotImplemented("BaseTransaction::NewAppend not implemented");
+}
+
+Status BaseTransaction::CommitTransaction() {
+  if (!HasLastOperationCommitted()) {
+    return InvalidState("Cannot commit transaction: last operation has not 
committed");
+  }
+
+  auto pending_updates = ConsumePendingUpdates();
+  if (pending_updates.empty()) {
+    return {};
+  }
+
+  auto pending_requirements = ConsumePendingRequirements();
+
+  ICEBERG_ASSIGN_OR_RAISE(
+      auto updated_table,
+      catalog_->catalog_impl()->UpdateTable(
+          table_->name(), std::move(pending_requirements), 
std::move(pending_updates)));
+
+  // update table to the new version
+  if (updated_table) {
+    table_ = std::shared_ptr<Table>(std::move(updated_table));

Review Comment:
   Yes,done



-- 
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]

Reply via email to