CTTY commented on code in PR #1400:
URL: https://github.com/apache/iceberg-rust/pull/1400#discussion_r2133089713


##########
crates/iceberg/src/transaction/action/mod.rs:
##########
@@ -0,0 +1,234 @@
+// 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.
+
+use std::cmp::Ordering;
+use std::collections::{HashMap, HashSet};
+use std::mem::take;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use tokio::sync::Mutex;
+
+use crate::TableUpdate::UpgradeFormatVersion;
+use crate::spec::FormatVersion;
+use crate::table::Table;
+use crate::{Error, ErrorKind, Result, TableRequirement, TableUpdate};
+
+/// TODO doc
+pub type BoxedTransactionAction = Arc<dyn TransactionAction>;
+
+/// TODO doc
+#[async_trait]
+pub trait TransactionAction: Sync + Send {
+    /// Commit the changes and apply the changes to the transaction
+    async fn commit(self: Arc<Self>, table: &Table) -> Result<ActionCommit>;
+}
+
+/// TODO doc
+pub struct ActionCommit {
+    updates: Vec<TableUpdate>,
+    requirements: Vec<TableRequirement>,
+}
+
+/// TODO doc
+impl ActionCommit {
+    /// TODO doc
+    pub fn new(updates: Vec<TableUpdate>, requirements: Vec<TableRequirement>) 
-> Self {
+        Self {
+            updates,
+            requirements,
+        }
+    }
+
+    /// TODO doc
+    pub fn take_updates(&mut self) -> Vec<TableUpdate> {
+        take(&mut self.updates)
+    }
+
+    /// TODO doc
+    pub fn take_requirements(&mut self) -> Vec<TableRequirement> {
+        take(&mut self.requirements)
+    }
+}
+
+/// TODO doc
+pub struct UpdateLocationAction {
+    state: Mutex<UpdateLocationState>,

Review Comment:
   I added this, because when `set_location`, there is `self: Arc<Self>`, and 
we still need to mutate the inner state `location`. 
   
   We have to keep TransactionAction's state mutable, so the following API call 
is possible:
   ```
   pub fn update_location(&mut self) -> Result<Arc<UpdateLocationAction>> {
           let update_location_action = Arc::new(UpdateLocationAction::new());
           self.actions.push(update_location_action.clone()); // need to make 
tx aware of this action
           // return a reference to the action so futher updates can be made 
outside of this function
           Ok(update_location_action) 
       }
   
   ...
   let action: Arc<UpdateLocationAction> = tx.update_location();
   action.set_location(path); // Need to mutate the action itself!
   
   ```
   
   Would be happy to learn if there are better ways to achieve the same 
behavior in Rust!



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