liurenjie1024 commented on code in PR #1420: URL: https://github.com/apache/iceberg-rust/pull/1420#discussion_r2135340930
########## crates/iceberg/src/transaction/action.rs: ########## @@ -0,0 +1,190 @@ +// 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 std::sync::Arc; + +use async_trait::async_trait; + +use crate::table::Table; +use crate::transaction::Transaction; +use crate::{Result, TableRequirement, TableUpdate}; + +/// A boxed, thread-safe reference to a `TransactionAction`. +pub type BoxedTransactionAction = Arc<dyn TransactionAction>; + +/// A trait representing an atomic action that can be part of a transaction. +/// +/// Implementors of this trait define how a specific action is committed to a table. +/// Each action is responsible for generating the updates and requirements needed +/// to modify the table metadata. +#[async_trait] +pub trait TransactionAction: Sync + Send { Review Comment: ```suggestion pub(crate) trait TransactionAction: Sync + Send { ``` ########## crates/iceberg/src/transaction/action.rs: ########## @@ -0,0 +1,190 @@ +// 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 std::sync::Arc; + +use async_trait::async_trait; + +use crate::table::Table; +use crate::transaction::Transaction; +use crate::{Result, TableRequirement, TableUpdate}; + +/// A boxed, thread-safe reference to a `TransactionAction`. +pub type BoxedTransactionAction = Arc<dyn TransactionAction>; + +/// A trait representing an atomic action that can be part of a transaction. +/// +/// Implementors of this trait define how a specific action is committed to a table. +/// Each action is responsible for generating the updates and requirements needed +/// to modify the table metadata. +#[async_trait] +pub trait TransactionAction: Sync + Send { + /// Commits this action against the provided table and returns the resulting updates. + /// NOTE: This function is intended for internal use only and should not be called directly by users. + /// + /// # Arguments + /// + /// * `table` - The current state of the table this action should apply to. + /// + /// # Returns + /// + /// An `ActionCommit` containing table updates and table requirements, + /// or an error if the commit fails. + #[allow(dead_code)] Review Comment: I would perfer to put this attribute on `action` module so that it would be easier to remove them. ########## crates/iceberg/src/transaction/action.rs: ########## @@ -0,0 +1,190 @@ +// 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 std::sync::Arc; + +use async_trait::async_trait; + +use crate::table::Table; +use crate::transaction::Transaction; +use crate::{Result, TableRequirement, TableUpdate}; + +/// A boxed, thread-safe reference to a `TransactionAction`. +pub type BoxedTransactionAction = Arc<dyn TransactionAction>; + +/// A trait representing an atomic action that can be part of a transaction. +/// +/// Implementors of this trait define how a specific action is committed to a table. +/// Each action is responsible for generating the updates and requirements needed +/// to modify the table metadata. +#[async_trait] +pub trait TransactionAction: Sync + Send { + /// Commits this action against the provided table and returns the resulting updates. + /// NOTE: This function is intended for internal use only and should not be called directly by users. + /// + /// # Arguments + /// + /// * `table` - The current state of the table this action should apply to. + /// + /// # Returns + /// + /// An `ActionCommit` containing table updates and table requirements, + /// or an error if the commit fails. + #[allow(dead_code)] + async fn commit(self: Arc<Self>, table: &Table) -> Result<ActionCommit>; +} + +/// A helper trait for applying a `TransactionAction` to a `Transaction`. +/// +/// This is implemented for all `TransactionAction` types +/// to allow easy chaining of actions into a transaction context. +pub trait ApplyTransactionAction { + /// Adds this action to the given transaction. + /// + /// # Arguments + /// + /// * `tx` - The transaction to apply the action to. + /// + /// # Returns + /// + /// The modified transaction containing this action, or an error if the operation fails. + #[allow(dead_code)] Review Comment: Ditto -- 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