use crate::spec::DataFile;
use crate::table::Table;
#[derive(Debug, Clone)]
pub enum TransactionOperation {
Append(#[allow(dead_code)] Vec<DataFile>),
}
pub struct Transaction {
table: Table,
operations: Vec<TransactionOperation>,
}
impl Transaction {
pub(crate) fn new(table: Table) -> Self {
Self {
table,
operations: Vec::new(),
}
}
pub fn table(&self) -> &Table {
&self.table
}
pub fn append(mut self, data_files: Vec<DataFile>) -> Self {
self.operations
.push(TransactionOperation::Append(data_files));
self
}
pub fn has_operations(&self) -> bool {
!self.operations.is_empty()
}
#[allow(dead_code)]
pub(crate) fn operations(&self) -> &[TransactionOperation] {
&self.operations
}
pub(crate) fn rebind_table(self, table: Table) -> Self {
Self {
table,
operations: self.operations,
}
}
pub async fn commit(self, catalog: &dyn crate::catalog::Catalog) -> crate::error::Result<()> {
crate::commit::commit_transaction(self, catalog).await
}
}