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


##########
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:
   
   > I think the apply of most of actions is the same? Maybe we can have the 
default implementation like:
   > 
   > ```
   > pub(crate) trait TransactionAction: Sync + Send {
   >     fn apply(self: Arc<Self>, tx: &mut Transaction) -> Result<()> {
   >       tx.add_action<self>
   >     }
   >     async commit(self: Arc<Self>, tx: &mut Transaction) -> Result<()>;
   > }
   > ```
   > 
   > However, I also don't know which action needs to be customized to apply 
the function.🤔
   
   The problem with this approach is that it's still not confluent api. I think 
maybe confluent api is not that important, and we don't need the `apply` method 
at all.



##########
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:
   > I'm not sure if using tx.commit to both generate staging metadata and then 
write it to disk is ideal. 
   
   I think it's reasonable to do both for now, as they are common for different 
catalog. We don't need to follow exactly as java's api.



##########
crates/iceberg/src/transaction/action/mod.rs:
##########
@@ -0,0 +1,73 @@
+// 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::any::Any;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+
+use crate::transaction::Transaction;
+use crate::{Error, ErrorKind, Result, TableRequirement, TableUpdate};
+
+pub type BoxedTransactionAction = Arc<dyn TransactionAction>;
+
+#[async_trait]
+pub(crate) trait TransactionAction: Sync + Send {
+    fn apply(&self) -> Box<dyn Any>;

Review Comment:
   As stated in 
https://github.com/apache/iceberg-rust/pull/1400#issuecomment-2943607589 , I 
don't think we should have an `apply` method in this trait to mimic java. 



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