Skip to content

Commit f22c0f9

Browse files
authored
Add unit tests for UpdateStatisticsAction functionality. (#1675)
## Which issue does this PR close? - Closes #1676. ## What changes are included in this PR? - Added tests for setting and removing statistics files in UpdateStatisticsAction. - Tests cover scenarios for: 1. Setting a single statistics file. 2. Ensuring no statistics are set. ## Are these changes tested? Tested locally.
1 parent 6e04443 commit f22c0f9

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

crates/iceberg/src/transaction/update_statistics.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,56 @@ mod tests {
171171
Some(statistics_file_2)
172172
);
173173
}
174+
175+
#[test]
176+
fn test_set_single_statistics() {
177+
let table = make_v2_table();
178+
let tx = Transaction::new(&table);
179+
180+
let statistics_file = StatisticsFile {
181+
snapshot_id: 1234567890i64,
182+
statistics_path: "s3://a/b/stats1.puffin".to_string(),
183+
file_size_in_bytes: 500,
184+
file_footer_size_in_bytes: 50,
185+
key_metadata: None,
186+
blob_metadata: vec![],
187+
};
188+
189+
// Set statistics
190+
let tx = tx
191+
.update_statistics()
192+
.set_statistics(statistics_file.clone())
193+
.apply(tx)
194+
.unwrap();
195+
196+
let action = (*tx.actions[0])
197+
.downcast_ref::<UpdateStatisticsAction>()
198+
.unwrap();
199+
200+
// Verify that the statistics file is set correctly
201+
assert_eq!(
202+
action
203+
.statistics_to_set
204+
.get(&statistics_file.snapshot_id)
205+
.unwrap()
206+
.clone(),
207+
Some(statistics_file)
208+
);
209+
}
210+
211+
#[test]
212+
fn test_no_statistics_set() {
213+
let table = make_v2_table();
214+
let tx = Transaction::new(&table);
215+
216+
// No statistics are set or removed
217+
let tx = tx.update_statistics().apply(tx).unwrap();
218+
219+
let action = (*tx.actions[0])
220+
.downcast_ref::<UpdateStatisticsAction>()
221+
.unwrap();
222+
223+
// Verify that no statistics are set
224+
assert!(action.statistics_to_set.is_empty());
225+
}
174226
}

0 commit comments

Comments
 (0)