Skip to content

Replace i64 with DateTime #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 5 additions & 1 deletion crates/catalog/rest/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
11 changes: 8 additions & 3 deletions crates/iceberg/src/spec/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
/*!
* Snapshots
*/
use chrono::{DateTime, TimeZone, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::sync::Arc;
Expand Down Expand Up @@ -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> {
Utc.timestamp_millis_opt(self.timestamp_ms).unwrap()
}
/// Create snapshot builder
pub fn builder() -> SnapshotBuilder {
Expand Down Expand Up @@ -309,6 +310,7 @@ pub enum SnapshotRetention {

#[cfg(test)]
mod tests {
use chrono::{TimeZone, Utc};
use std::collections::HashMap;

use crate::spec::snapshot::{
Expand All @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions crates/iceberg/src/spec/table_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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> {
Utc.timestamp_millis_opt(self.last_updated_ms).unwrap()
}

/// Returns schemas
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -771,6 +773,13 @@ pub struct SnapshotLog {
pub timestamp_ms: i64,
}

impl SnapshotLog {
/// Returns the last updated timestamp as a DateTime<Utc> with millisecond precision
pub fn timestamp(self) -> DateTime<Utc> {
Utc.timestamp_millis_opt(self.timestamp_ms).unwrap()
}
}

#[cfg(test)]
mod tests {

Expand Down