diff --git a/Cargo.toml b/Cargo.toml index 4ddb51fe2..f6efbc378 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,4 +55,5 @@ tokio = { version = "1", features = ["macros"] } typed-builder = "^0.18" url = "2" urlencoding = "2" -uuid = "1.5.0" +# We pin uuid's version to 1.5.0 because this bug: https://github.com/uuid-rs/uuid/issues/720 +uuid = "~1.5.0" diff --git a/crates/catalog/rest/src/catalog.rs b/crates/catalog/rest/src/catalog.rs index 653cfd4f5..efa11de11 100644 --- a/crates/catalog/rest/src/catalog.rs +++ b/crates/catalog/rest/src/catalog.rs @@ -590,6 +590,7 @@ mod _serde { #[cfg(test)] mod tests { + use chrono::{TimeZone, Utc}; use iceberg::spec::ManifestListLocation::ManifestListFile; use iceberg::spec::{ FormatVersion, NestedField, Operation, PrimitiveType, Schema, Snapshot, SnapshotLog, @@ -984,7 +985,10 @@ mod tests { uuid!("b55d9dda-6561-423a-8bfc-787980ce421f"), table.metadata().uuid() ); - assert_eq!(1646787054459, table.metadata().last_updated_ms()); + assert_eq!( + Utc.timestamp_millis_opt(1646787054459).unwrap(), + table.metadata().last_updated_ms() + ); assert_eq!( vec![&Arc::new( Schema::builder() diff --git a/crates/iceberg/src/spec/snapshot.rs b/crates/iceberg/src/spec/snapshot.rs index a04bb9998..c52ee3bb7 100644 --- a/crates/iceberg/src/spec/snapshot.rs +++ b/crates/iceberg/src/spec/snapshot.rs @@ -18,6 +18,7 @@ /*! * Snapshots */ +use chrono::{DateTime, TimeZone, Utc}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::sync::Arc; @@ -116,8 +117,8 @@ impl Snapshot { } /// Get the timestamp of when the snapshot was created #[inline] - pub fn timestamp(&self) -> i64 { - self.timestamp_ms + pub fn timestamp(&self) -> DateTime { + Utc.timestamp_millis_opt(self.timestamp_ms).unwrap() } /// Create snapshot builder pub fn builder() -> SnapshotBuilder { @@ -309,6 +310,7 @@ pub enum SnapshotRetention { #[cfg(test)] mod tests { + use chrono::{TimeZone, Utc}; use std::collections::HashMap; use crate::spec::snapshot::{ @@ -334,7 +336,10 @@ mod tests { .try_into() .unwrap(); assert_eq!(3051729675574597004, result.snapshot_id()); - assert_eq!(1515100955770, result.timestamp()); + assert_eq!( + Utc.timestamp_millis_opt(1515100955770).unwrap(), + result.timestamp() + ); assert_eq!( Summary { operation: Operation::Append, diff --git a/crates/iceberg/src/spec/table_metadata.rs b/crates/iceberg/src/spec/table_metadata.rs index 6abe95964..a5af58f39 100644 --- a/crates/iceberg/src/spec/table_metadata.rs +++ b/crates/iceberg/src/spec/table_metadata.rs @@ -32,6 +32,8 @@ use super::{ use _serde::TableMetadataEnum; +use chrono::{DateTime, TimeZone, Utc}; + static MAIN_BRANCH: &str = "main"; static DEFAULT_SPEC_ID: i32 = 0; static DEFAULT_SORT_ORDER_ID: i64 = 0; @@ -133,8 +135,8 @@ impl TableMetadata { /// Returns last updated time. #[inline] - pub fn last_updated_ms(&self) -> i64 { - self.last_updated_ms + pub fn last_updated_ms(&self) -> DateTime { + Utc.timestamp_millis_opt(self.last_updated_ms).unwrap() } /// Returns schemas @@ -242,7 +244,7 @@ impl TableMetadata { /// Append snapshot to table pub fn append_snapshot(&mut self, snapshot: Snapshot) { - self.last_updated_ms = snapshot.timestamp(); + self.last_updated_ms = snapshot.timestamp().timestamp_millis(); self.last_sequence_number = snapshot.sequence_number(); self.refs @@ -771,6 +773,13 @@ pub struct SnapshotLog { pub timestamp_ms: i64, } +impl SnapshotLog { + /// Returns the last updated timestamp as a DateTime with millisecond precision + pub fn timestamp(self) -> DateTime { + Utc.timestamp_millis_opt(self.timestamp_ms).unwrap() + } +} + #[cfg(test)] mod tests {