Skip to content

Commit 1fc535e

Browse files
make it with_operation and with_commit_info
1 parent b4feb4f commit 1fc535e

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

kernel/src/transaction.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ impl Transaction {
9090

9191
/// Set the operation that this transaction is performing. This string will be persisted in the
9292
/// commit and visible to anyone who describes the table history.
93-
pub fn operation(&mut self, operation: String) {
93+
pub fn with_operation(mut self, operation: String) -> Self {
9494
self.operation = Some(operation);
95+
self
9596
}
9697

9798
/// WARNING: This is an unstable API and will likely change in the future.
@@ -107,8 +108,9 @@ impl Transaction {
107108
/// that can either be `null` or contain an empty map.
108109
///
109110
/// Any other columns in the data chunk are ignored.
110-
pub fn commit_info(&mut self, commit_info: Box<dyn EngineData>) {
111+
pub fn with_commit_info(mut self, commit_info: Box<dyn EngineData>) -> Self {
111112
self.commit_info = Some(commit_info.into());
113+
self
112114
}
113115
}
114116

kernel/tests/write.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,7 @@ async fn test_commit_info() -> Result<(), Box<dyn std::error::Error>> {
100100
)]));
101101
let table = create_table(store.clone(), table_location, schema, &[]).await?;
102102

103-
// create a transaction
104-
let mut txn = table.new_transaction(&engine)?;
105-
106-
// add commit info of the form {engineCommitInfo: Map { "engineInfo": "default engine" } }
103+
// create commit info of the form {engineCommitInfo: Map { "engineInfo": "default engine" } }
107104
let commit_info_schema = Arc::new(ArrowSchema::new(vec![Field::new(
108105
"engineCommitInfo",
109106
ArrowDataType::Map(
@@ -139,7 +136,11 @@ async fn test_commit_info() -> Result<(), Box<dyn std::error::Error>> {
139136

140137
let commit_info_batch =
141138
RecordBatch::try_new(commit_info_schema.clone(), vec![Arc::new(array)])?;
142-
txn.commit_info(Box::new(ArrowEngineData::new(commit_info_batch)));
139+
140+
// create a transaction
141+
let txn = table
142+
.new_transaction(&engine)?
143+
.with_commit_info(Box::new(ArrowEngineData::new(commit_info_batch)));
143144

144145
// commit!
145146
txn.commit(&engine)?;
@@ -212,11 +213,12 @@ async fn test_invalid_commit_info() -> Result<(), Box<dyn std::error::Error>> {
212213
let table = create_table(store.clone(), table_location, schema, &[]).await?;
213214

214215
// empty commit info test
215-
let mut txn = table.new_transaction(&engine)?;
216216
let commit_info_schema = Arc::new(ArrowSchema::empty());
217217
let commit_info_batch = RecordBatch::new_empty(commit_info_schema.clone());
218218
assert!(commit_info_batch.num_rows() == 0);
219-
txn.commit_info(Box::new(ArrowEngineData::new(commit_info_batch)));
219+
let txn = table
220+
.new_transaction(&engine)?
221+
.with_commit_info(Box::new(ArrowEngineData::new(commit_info_batch)));
220222

221223
// commit!
222224
assert!(matches!(
@@ -225,7 +227,6 @@ async fn test_invalid_commit_info() -> Result<(), Box<dyn std::error::Error>> {
225227
));
226228

227229
// two-row commit info test
228-
let mut txn = table.new_transaction(&engine)?;
229230
let commit_info_schema = Arc::new(ArrowSchema::new(vec![Field::new(
230231
"engineInfo",
231232
ArrowDataType::Utf8,
@@ -239,7 +240,9 @@ async fn test_invalid_commit_info() -> Result<(), Box<dyn std::error::Error>> {
239240
]))],
240241
)?;
241242

242-
txn.commit_info(Box::new(ArrowEngineData::new(commit_info_batch)));
243+
let txn = table
244+
.new_transaction(&engine)?
245+
.with_commit_info(Box::new(ArrowEngineData::new(commit_info_batch)));
243246

244247
// commit!
245248
assert!(matches!(

0 commit comments

Comments
 (0)