Skip to content

Commit cbcbf5d

Browse files
committed
Merge pull request JanKaul#244 from gruuya/last-updated-ms-fix
fix: update `last-updated-ms` field when updating a table
2 parents 11958f1 + 2d8c36e commit cbcbf5d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

iceberg-rust/src/catalog/commit.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
//! All changes are made atomically - either all updates succeed or none are applied.
1010
//! Requirements are checked first to ensure concurrent modifications don't corrupt state.
1111
12-
use std::collections::HashMap;
13-
1412
use iceberg_rust_spec::{
1513
spec::{
1614
partition::PartitionSpec,
@@ -24,6 +22,8 @@ use iceberg_rust_spec::{
2422
view_metadata::Materialization,
2523
};
2624
use serde_derive::{Deserialize, Serialize};
25+
use std::collections::HashMap;
26+
use std::time::{SystemTime, UNIX_EPOCH};
2727
use uuid::Uuid;
2828

2929
use crate::error::Error;
@@ -530,6 +530,12 @@ pub fn apply_table_updates(
530530
}
531531
};
532532
}
533+
534+
// Lastly make sure `last-updated-ms` field is up-to-date
535+
metadata.last_updated_ms = SystemTime::now()
536+
.duration_since(UNIX_EPOCH)
537+
.unwrap()
538+
.as_millis() as i64;
533539
Ok(())
534540
}
535541

iceberg-rust/tests/overwrite_test.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ async fn test_table_transaction_overwrite() {
8383
.await
8484
.expect("Failed to create table");
8585

86+
let mut previous_last_updated_ms = table.metadata().last_updated_ms;
87+
8688
// 4. Create initial Arrow RecordBatch and write to parquet
8789
let initial_batch = create_initial_record_batch();
8890
let initial_stream = stream::iter(vec![Ok(initial_batch.clone())]);
@@ -104,6 +106,8 @@ async fn test_table_transaction_overwrite() {
104106
!table.metadata().snapshots.is_empty(),
105107
"Table should have at least one snapshot after append"
106108
);
109+
assert!(table.metadata().last_updated_ms > previous_last_updated_ms);
110+
previous_last_updated_ms = table.metadata().last_updated_ms;
107111

108112
// 6. Create overwrite RecordBatch with additional rows
109113
let overwrite_batch = create_overwrite_record_batch();
@@ -134,6 +138,7 @@ async fn test_table_transaction_overwrite() {
134138
final_snapshots.len() >= 2,
135139
"Table should have at least 2 snapshots after overwrite"
136140
);
141+
assert!(table.metadata().last_updated_ms > previous_last_updated_ms);
137142

138143
// Get the current snapshot (should be the overwrite snapshot)
139144
let current_snapshot = table

0 commit comments

Comments
 (0)