pub struct TableTransaction<'table> { /* private fields */ }
Expand description
A transaction that can perform multiple operations on a table atomically
TableTransaction allows grouping multiple table operations (like schema updates, appends, overwrites) into a single atomic transaction. The transaction must be committed for changes to take effect.
§Type Parameters
'table
- Lifetime of the reference to the table being modified
§Examples
let mut table = // ... get table reference
table.new_transaction(None)
.add_schema(new_schema)
.append(data_files)
.commit()
.await?;
Implementations§
Source§impl<'table> TableTransaction<'table>
impl<'table> TableTransaction<'table>
Sourcepub fn add_schema(self, schema: Schema) -> Self
pub fn add_schema(self, schema: Schema) -> Self
Sourcepub fn set_default_spec(self, spec_id: i32) -> Self
pub fn set_default_spec(self, spec_id: i32) -> Self
Sourcepub fn append_data(self, files: Vec<DataFile>) -> Self
pub fn append_data(self, files: Vec<DataFile>) -> Self
Appends new data files to the table
This operation adds new data files to the table’s current snapshot. Multiple append operations in the same transaction will be combined.
§Arguments
files
- Vector of data files to append to the table
§Returns
Self
- The transaction builder for method chaining
§Examples
let transaction = table.new_transaction(None)
.append_data(data_files)
.commit()
.await?;
Sourcepub fn append_delete(self, files: Vec<DataFile>) -> Self
pub fn append_delete(self, files: Vec<DataFile>) -> Self
Appends delete files to the table
This operation adds files that mark records for deletion in the table’s current snapshot. Multiple delete operations in the same transaction will be combined. The delete files specify which records should be removed when reading the table.
§Arguments
files
- Vector of delete files to append to the table
§Returns
Self
- The transaction builder for method chaining
§Examples
let transaction = table.new_transaction(None)
.append_delete(delete_files)
.commit()
.await?;
Sourcepub fn replace(self, files: Vec<DataFile>) -> Self
pub fn replace(self, files: Vec<DataFile>) -> Self
Replaces all data files in the table with new ones
This operation removes all existing data files and replaces them with the provided files. Multiple replace operations in the same transaction will be combined.
§Arguments
files
- Vector of data files that will replace the existing ones
§Returns
Self
- The transaction builder for method chaining
§Examples
let transaction = table.new_transaction(None)
.replace(new_files)
.commit()
.await?;
Sourcepub fn replace_with_lineage(
self,
files: Vec<DataFile>,
additional_summary: HashMap<String, String>,
) -> Self
pub fn replace_with_lineage( self, files: Vec<DataFile>, additional_summary: HashMap<String, String>, ) -> Self
Quickly append files to the table
Sourcepub fn update_properties(self, entries: Vec<(String, String)>) -> Self
pub fn update_properties(self, entries: Vec<(String, String)>) -> Self
Updates the table properties with new key-value pairs
This operation adds or updates table properties. Multiple update operations in the same transaction will be combined.
§Arguments
entries
- Vector of (key, value) pairs to update in the table properties
§Returns
Self
- The transaction builder for method chaining
§Examples
let transaction = table.new_transaction(None)
.update_properties(vec![
("write.format.default".to_string(), "parquet".to_string()),
("write.metadata.compression-codec".to_string(), "gzip".to_string())
])
.commit()
.await?;
Sourcepub fn set_snapshot_ref(self, entry: (String, SnapshotReference)) -> Self
pub fn set_snapshot_ref(self, entry: (String, SnapshotReference)) -> Self
Sets a snapshot reference for the table
This operation creates or updates a named reference to a specific snapshot, allowing for features like branches and tags.
§Arguments
entry
- Tuple of (reference name, snapshot reference) defining the reference
§Returns
Self
- The transaction builder for method chaining
§Examples
let transaction = table.new_transaction(None)
.set_snapshot_ref((
"test-branch".to_string(),
SnapshotReference {
snapshot_id: 123,
retention: SnapshotRetention::default(),
}
))
.commit()
.await?;
Sourcepub async fn commit(self) -> Result<(), Error>
pub async fn commit(self) -> Result<(), Error>
Commits all operations in this transaction atomically
This method executes all operations in the transaction and updates the table metadata. The changes are atomic - either all operations succeed or none do. After commit, the transaction is consumed and the table is updated with the new metadata.
§Returns
Result<(), Error>
- Ok(()) if the commit succeeds, Error if it fails
§Errors
Returns an error if:
- Any operation fails to execute
- The catalog update fails
- Cleanup of old data files fails (for replace operations)
§Examples
let result = table.new_transaction(None)
.append(data_files)
.update_properties(properties)
.commit()
.await?;
Auto Trait Implementations§
impl<'table> Freeze for TableTransaction<'table>
impl<'table> !RefUnwindSafe for TableTransaction<'table>
impl<'table> Send for TableTransaction<'table>
impl<'table> Sync for TableTransaction<'table>
impl<'table> Unpin for TableTransaction<'table>
impl<'table> !UnwindSafe for TableTransaction<'table>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more