Skip to content

feat(transaction): Make Transaction own base_table #1421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions crates/iceberg/src/transaction/append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ use crate::writer::file_writer::ParquetWriter;
use crate::{Error, ErrorKind};

/// FastAppendAction is a transaction action for fast append data files to the table.
pub struct FastAppendAction<'a> {
snapshot_produce_action: SnapshotProduceAction<'a>,
pub struct FastAppendAction {
snapshot_produce_action: SnapshotProduceAction,
check_duplicate: bool,
}

impl<'a> FastAppendAction<'a> {
impl FastAppendAction {
#[allow(clippy::too_many_arguments)]
pub(crate) fn new(
tx: Transaction<'a>,
tx: Transaction,
snapshot_id: i64,
commit_uuid: Uuid,
key_metadata: Vec<u8>,
Expand Down Expand Up @@ -87,7 +87,7 @@ impl<'a> FastAppendAction<'a> {
/// Specifically, schema compatibility checks and support for adding to partitioned tables
/// have not yet been implemented.
#[allow(dead_code)]
async fn add_parquet_files(mut self, file_path: Vec<String>) -> Result<Transaction<'a>> {
async fn add_parquet_files(mut self, file_path: Vec<String>) -> Result<Transaction> {
if !self
.snapshot_produce_action
.tx
Expand Down Expand Up @@ -117,7 +117,7 @@ impl<'a> FastAppendAction<'a> {
}

/// Finished building the action and apply it to the transaction.
pub async fn apply(self) -> Result<Transaction<'a>> {
pub async fn apply(self) -> Result<Transaction> {
// Checks duplicate files
if self.check_duplicate {
let new_files: HashSet<&str> = self
Expand Down Expand Up @@ -170,14 +170,14 @@ impl SnapshotProduceOperation for FastAppendOperation {

async fn delete_entries(
&self,
_snapshot_produce: &SnapshotProduceAction<'_>,
_snapshot_produce: &SnapshotProduceAction,
) -> Result<Vec<ManifestEntry>> {
Ok(vec![])
}

async fn existing_manifest(
&self,
snapshot_produce: &SnapshotProduceAction<'_>,
snapshot_produce: &SnapshotProduceAction,
) -> Result<Vec<ManifestFile>> {
let Some(snapshot) = snapshot_produce
.tx
Expand Down
14 changes: 7 additions & 7 deletions crates/iceberg/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ use crate::transaction::sort_order::ReplaceSortOrderAction;
use crate::{Catalog, Error, ErrorKind, TableCommit, TableRequirement, TableUpdate};

/// Table transaction.
pub struct Transaction<'a> {
base_table: &'a Table,
pub struct Transaction {
base_table: Table,
current_table: Table,
updates: Vec<TableUpdate>,
requirements: Vec<TableRequirement>,
}

impl<'a> Transaction<'a> {
impl Transaction {
/// Creates a new transaction.
pub fn new(table: &'a Table) -> Self {
pub fn new(table: &Table) -> Self {
Self {
base_table: table,
base_table: table.clone(),
current_table: table.clone(),
updates: vec![],
requirements: vec![],
Expand Down Expand Up @@ -155,7 +155,7 @@ impl<'a> Transaction<'a> {
self,
commit_uuid: Option<Uuid>,
key_metadata: Vec<u8>,
) -> Result<FastAppendAction<'a>> {
) -> Result<FastAppendAction> {
let snapshot_id = self.generate_unique_snapshot_id();
FastAppendAction::new(
self,
Expand All @@ -167,7 +167,7 @@ impl<'a> Transaction<'a> {
}

/// Creates replace sort order action.
pub fn replace_sort_order(self) -> ReplaceSortOrderAction<'a> {
pub fn replace_sort_order(self) -> ReplaceSortOrderAction {
ReplaceSortOrderAction {
tx: self,
sort_fields: vec![],
Expand Down
10 changes: 5 additions & 5 deletions crates/iceberg/src/transaction/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ pub(crate) trait ManifestProcess: Send + Sync {
fn process_manifests(&self, manifests: Vec<ManifestFile>) -> Vec<ManifestFile>;
}

pub(crate) struct SnapshotProduceAction<'a> {
pub tx: Transaction<'a>,
pub(crate) struct SnapshotProduceAction {
pub tx: Transaction,
snapshot_id: i64,
key_metadata: Vec<u8>,
commit_uuid: Uuid,
Expand All @@ -72,9 +72,9 @@ pub(crate) struct SnapshotProduceAction<'a> {
manifest_counter: RangeFrom<u64>,
}

impl<'a> SnapshotProduceAction<'a> {
impl SnapshotProduceAction {
pub(crate) fn new(
tx: Transaction<'a>,
tx: Transaction,
snapshot_id: i64,
key_metadata: Vec<u8>,
commit_uuid: Uuid,
Expand Down Expand Up @@ -310,7 +310,7 @@ impl<'a> SnapshotProduceAction<'a> {
mut self,
snapshot_produce_operation: OP,
process: MP,
) -> Result<Transaction<'a>> {
) -> Result<Transaction> {
let new_manifests = self
.manifest_file(&snapshot_produce_operation, &process)
.await?;
Expand Down
8 changes: 4 additions & 4 deletions crates/iceberg/src/transaction/sort_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ use crate::transaction::Transaction;
use crate::{Error, ErrorKind, TableRequirement, TableUpdate};

/// Transaction action for replacing sort order.
pub struct ReplaceSortOrderAction<'a> {
pub tx: Transaction<'a>,
pub struct ReplaceSortOrderAction {
pub tx: Transaction,
pub sort_fields: Vec<SortField>,
}

impl<'a> ReplaceSortOrderAction<'a> {
impl ReplaceSortOrderAction {
/// Adds a field for sorting in ascending order.
pub fn asc(self, name: &str, null_order: NullOrder) -> Result<Self> {
self.add_sort_field(name, SortDirection::Ascending, null_order)
Expand All @@ -38,7 +38,7 @@ impl<'a> ReplaceSortOrderAction<'a> {
}

/// Finished building the action and apply it to the transaction.
pub fn apply(mut self) -> Result<Transaction<'a>> {
pub fn apply(mut self) -> Result<Transaction> {
let unbound_sort_order = SortOrder::builder()
.with_fields(self.sort_fields)
.build_unbound()?;
Expand Down
Loading