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


##########
crates/iceberg/src/transaction/action/mod.rs:
##########
@@ -0,0 +1,85 @@
+// 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::mem::take;
+
+use crate::{Error, ErrorKind, Result, TableRequirement, TableUpdate};
+
+pub type PendingAction = Box<dyn TransactionAction>;

Review Comment:
   ```suggestion
   pub type BoxedTransactionAction = Arc<dyn TransactionAction>;
   ```



##########
crates/iceberg/src/transaction/action/mod.rs:
##########
@@ -0,0 +1,85 @@
+// 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::mem::take;
+
+use crate::{Error, ErrorKind, Result, TableRequirement, TableUpdate};
+
+pub type PendingAction = Box<dyn TransactionAction>;
+
+pub(crate) trait TransactionAction: Sync {
+    /// Commit the changes and apply the changes to the transaction,
+    /// return the transaction with the updated current_table
+    fn commit(self: Box<Self>) -> Result<TransactionActionCommit>;
+}
+
+pub struct TransactionActionCommit {
+    action: Option<PendingAction>,

Review Comment:
   Why we need this?



##########
crates/iceberg/src/transaction/mod.rs:
##########
@@ -185,19 +204,74 @@ impl<'a> Transaction<'a> {
 
     /// Set the location of table
     pub fn set_location(mut self, location: String) -> Result<Self> {
-        self.apply(vec![TableUpdate::SetLocation { location }], vec![])?;
+        let set_location = SetLocation::new().set_location(location);
+        self.apply_commit_result(Box::new(set_location).commit()?)
+            .expect("Some error msg");

Review Comment:
   We should not call `apply_commit_result` here.



##########
crates/iceberg/src/transaction/action/mod.rs:
##########
@@ -0,0 +1,85 @@
+// 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::mem::take;
+
+use crate::{Error, ErrorKind, Result, TableRequirement, TableUpdate};
+
+pub type PendingAction = Box<dyn TransactionAction>;
+
+pub(crate) trait TransactionAction: Sync {
+    /// Commit the changes and apply the changes to the transaction,
+    /// return the transaction with the updated current_table
+    fn commit(self: Box<Self>) -> Result<TransactionActionCommit>;
+}

Review Comment:
   ```suggestion
   #[async_trait]
   pub(crate) trait TransactionAction: Sync + Send {
       /// Commit the changes and apply the changes to the transaction,
       /// return the transaction with the updated current_table
       fn commit(self: Arc<Self>, tx:  &Transaction) -> 
Result<TransactionActionCommit>;
   }
   ```
   
   We may need to load manifest files for conflict resolution, which should be 
async.



##########
crates/iceberg/src/transaction/action/mod.rs:
##########
@@ -0,0 +1,85 @@
+// 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::mem::take;
+
+use crate::{Error, ErrorKind, Result, TableRequirement, TableUpdate};
+
+pub type PendingAction = Box<dyn TransactionAction>;
+
+pub(crate) trait TransactionAction: Sync {
+    /// Commit the changes and apply the changes to the transaction,
+    /// return the transaction with the updated current_table
+    fn commit(self: Box<Self>) -> Result<TransactionActionCommit>;
+}
+
+pub struct TransactionActionCommit {
+    action: Option<PendingAction>,
+    updates: Vec<TableUpdate>,
+    requirements: Vec<TableRequirement>,
+}
+
+impl TransactionActionCommit {
+    pub fn take_action(&mut self) -> Option<PendingAction> {
+        take(&mut self.action)
+    }
+
+    pub fn take_updates(&mut self) -> Vec<TableUpdate> {
+        take(&mut self.updates)
+    }
+
+    pub fn take_requirements(&mut self) -> Vec<TableRequirement> {
+        take(&mut self.requirements)
+    }
+}
+
+pub struct SetLocation {
+    pub location: Option<String>,
+}
+
+impl SetLocation {
+    pub fn new() -> Self {
+        SetLocation { location: None }
+    }
+
+    pub fn set_location(mut self, location: String) -> Self {
+        self.location = Some(location);
+        self
+    }
+}
+

Review Comment:
   ```rust
   pub struct SetLocationAction {
      tx: Option<Transaction>
      location: Option<String>
   }
   
   impl SetLocation {
     fn apply(self) -> Result<Transaction> {
      let tx = self.tx.take();
       self.tx.add_action(Arc::new(self));
     }
   }
   ```



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to