Skip to content

Commit 9521da8

Browse files
committed
Expose TimestampMillis only via public APIs
1 parent 21346c6 commit 9521da8

File tree

6 files changed

+228
-126
lines changed

6 files changed

+228
-126
lines changed

crates/catalog/rest/src/catalog.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ mod tests {
591591
use iceberg::spec::ManifestListLocation::ManifestListFile;
592592
use iceberg::spec::{
593593
FormatVersion, NestedField, Operation, PrimitiveType, Schema, Snapshot, SnapshotLog,
594-
SortOrder, Summary, Timestamp, Type,
594+
SortOrder, Summary, TimestampMillis, Type,
595595
};
596596
use mockito::{Mock, Server, ServerGuard};
597597
use std::sync::Arc;
@@ -983,7 +983,7 @@ mod tests {
983983
table.metadata().uuid()
984984
);
985985
assert_eq!(
986-
Timestamp::new(1646787054459).unwrap(),
986+
TimestampMillis::new(1646787054459),
987987
table.metadata().last_updated_ms()
988988
);
989989
assert_eq!(
@@ -1011,7 +1011,7 @@ mod tests {
10111011
);
10121012
assert_eq!(vec![&Arc::new(Snapshot::builder()
10131013
.with_snapshot_id(3497810964824022504)
1014-
.with_timestamp_ms(Timestamp::new(1646787054459).unwrap())
1014+
.with_timestamp_ms(1646787054459)
10151015
.with_manifest_list(ManifestListFile("s3://warehouse/database/table/metadata/snap-3497810964824022504-1-c4f68204-666b-4e50-a9df-b10c34bf6b82.avro".to_string()))
10161016
.with_sequence_number(0)
10171017
.with_schema_id(0)
@@ -1034,7 +1034,7 @@ mod tests {
10341034
)], table.metadata().snapshots().collect::<Vec<_>>());
10351035
assert_eq!(
10361036
&[SnapshotLog {
1037-
timestamp_ms: Timestamp::new(1646787054459).unwrap(),
1037+
timestamp_ms: TimestampMillis::new(1646787054459),
10381038
snapshot_id: 3497810964824022504
10391039
}],
10401040
table.metadata().history()

crates/iceberg/src/spec/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mod schema;
2424
mod snapshot;
2525
mod sort;
2626
mod table_metadata;
27-
mod timestamp;
27+
mod timestamp_millis;
2828
mod transform;
2929
mod values;
3030

@@ -35,6 +35,6 @@ pub use schema::*;
3535
pub use snapshot::*;
3636
pub use sort::*;
3737
pub use table_metadata::*;
38-
pub use timestamp::*;
38+
pub use timestamp_millis::*;
3939
pub use transform::*;
4040
pub use values::*;

crates/iceberg/src/spec/snapshot.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/*!
1919
* Snapshots
2020
*/
21-
use crate::spec::timestamp::Timestamp;
21+
use crate::spec::timestamp_millis::TimestampMillis;
2222
use serde::{Deserialize, Serialize};
2323
use std::collections::HashMap;
2424
use std::sync::Arc;
@@ -73,7 +73,7 @@ pub struct Snapshot {
7373
sequence_number: i64,
7474
/// A timestamp when the snapshot was created, used for garbage
7575
/// collection and table inspection
76-
timestamp_ms: Timestamp,
76+
timestamp_ms: i64,
7777
/// The location of a manifest list for this snapshot that
7878
/// tracks manifest files with additional metadata.
7979
manifest_list: ManifestListLocation,
@@ -117,8 +117,8 @@ impl Snapshot {
117117
}
118118
/// Get the timestamp of when the snapshot was created
119119
#[inline]
120-
pub fn timestamp(&self) -> Timestamp {
121-
self.timestamp_ms
120+
pub fn timestamp(&self) -> TimestampMillis {
121+
TimestampMillis::new(self.timestamp_ms)
122122
}
123123
/// Create snapshot builder
124124
pub fn builder() -> SnapshotBuilder {
@@ -127,7 +127,7 @@ impl Snapshot {
127127

128128
pub(crate) fn log(&self) -> SnapshotLog {
129129
SnapshotLog {
130-
timestamp_ms: self.timestamp_ms,
130+
timestamp_ms: TimestampMillis::new(self.timestamp_ms),
131131
snapshot_id: self.snapshot_id,
132132
}
133133
}
@@ -142,12 +142,11 @@ pub(super) mod _serde {
142142

143143
use serde::{Deserialize, Serialize};
144144

145+
use crate::spec::TimestampMillis;
145146
use crate::{Error, ErrorKind};
146147

147148
use super::{ManifestListLocation, Operation, Snapshot, Summary};
148149

149-
use crate::spec::timestamp::Timestamp;
150-
151150
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
152151
#[serde(rename_all = "kebab-case")]
153152
/// Defines the structure of a v2 snapshot for serialization/deserialization
@@ -156,7 +155,7 @@ pub(super) mod _serde {
156155
#[serde(skip_serializing_if = "Option::is_none")]
157156
pub parent_snapshot_id: Option<i64>,
158157
pub sequence_number: i64,
159-
pub timestamp_ms: Timestamp,
158+
pub timestamp_ms: TimestampMillis,
160159
pub manifest_list: String,
161160
pub summary: Summary,
162161
#[serde(skip_serializing_if = "Option::is_none")]
@@ -170,7 +169,7 @@ pub(super) mod _serde {
170169
pub snapshot_id: i64,
171170
#[serde(skip_serializing_if = "Option::is_none")]
172171
pub parent_snapshot_id: Option<i64>,
173-
pub timestamp_ms: Timestamp,
172+
pub timestamp_ms: TimestampMillis,
174173
#[serde(skip_serializing_if = "Option::is_none")]
175174
pub manifest_list: Option<String>,
176175
#[serde(skip_serializing_if = "Option::is_none")]
@@ -187,7 +186,7 @@ pub(super) mod _serde {
187186
snapshot_id: v2.snapshot_id,
188187
parent_snapshot_id: v2.parent_snapshot_id,
189188
sequence_number: v2.sequence_number,
190-
timestamp_ms: v2.timestamp_ms,
189+
timestamp_ms: v2.timestamp_ms.to_date_time().timestamp_millis(),
191190
manifest_list: ManifestListLocation::ManifestListFile(v2.manifest_list),
192191
summary: v2.summary,
193192
schema_id: v2.schema_id,
@@ -201,7 +200,7 @@ pub(super) mod _serde {
201200
snapshot_id: v2.snapshot_id,
202201
parent_snapshot_id: v2.parent_snapshot_id,
203202
sequence_number: v2.sequence_number,
204-
timestamp_ms: v2.timestamp_ms,
203+
timestamp_ms: TimestampMillis::new(v2.timestamp_ms),
205204
manifest_list: match v2.manifest_list {
206205
ManifestListLocation::ManifestListFile(file) => file,
207206
ManifestListLocation::ManifestFiles(_) => panic!("Wrong table format version. Can't convert a list of manifest files into a location of a manifest file.")
@@ -220,7 +219,7 @@ pub(super) mod _serde {
220219
snapshot_id: v1.snapshot_id,
221220
parent_snapshot_id: v1.parent_snapshot_id,
222221
sequence_number: 0,
223-
timestamp_ms: v1.timestamp_ms,
222+
timestamp_ms: v1.timestamp_ms.to_date_time().timestamp_millis(),
224223
manifest_list: match (v1.manifest_list, v1.manifests) {
225224
(Some(file), _) => ManifestListLocation::ManifestListFile(file),
226225
(None, Some(files)) => ManifestListLocation::ManifestFiles(files),
@@ -249,7 +248,7 @@ pub(super) mod _serde {
249248
SnapshotV1 {
250249
snapshot_id: v2.snapshot_id,
251250
parent_snapshot_id: v2.parent_snapshot_id,
252-
timestamp_ms: v2.timestamp_ms,
251+
timestamp_ms: TimestampMillis::new(v2.timestamp_ms),
253252
manifest_list,
254253
manifests,
255254
summary: Some(v2.summary),
@@ -317,7 +316,7 @@ mod tests {
317316
use crate::spec::snapshot::{
318317
ManifestListLocation, Operation, Snapshot, Summary, _serde::SnapshotV1,
319318
};
320-
use crate::spec::timestamp::Timestamp;
319+
use crate::spec::timestamp_millis::TimestampMillis;
321320

322321
#[test]
323322
fn schema() {
@@ -338,7 +337,7 @@ mod tests {
338337
.try_into()
339338
.unwrap();
340339
assert_eq!(3051729675574597004, result.snapshot_id());
341-
assert_eq!(Timestamp::new(1515100955770).unwrap(), result.timestamp());
340+
assert_eq!(TimestampMillis::new(1515100955770), result.timestamp());
342341
assert_eq!(
343342
Summary {
344343
operation: Operation::Append,

crates/iceberg/src/spec/table_metadata.rs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Defines the [table metadata](https://iceberg.apache.org/spec/#table-metadata).
2020
The main struct here is [TableMetadataV2] which defines the data for a table.
2121
*/
2222

23-
use crate::spec::timestamp::Timestamp;
23+
use crate::spec::timestamp_millis::TimestampMillis;
2424
use serde::{Deserialize, Serialize};
2525
use serde_repr::{Deserialize_repr, Serialize_repr};
2626
use std::{collections::HashMap, sync::Arc};
@@ -53,7 +53,7 @@ pub struct TableMetadata {
5353
/// The tables highest sequence number
5454
last_sequence_number: i64,
5555
/// Timestamp in milliseconds from the unix epoch when the table was last updated.
56-
last_updated_ms: Timestamp,
56+
last_updated_ms: i64,
5757
/// An integer; the highest assigned column ID for the table.
5858
last_column_id: i32,
5959
/// A list of schemas, stored as objects with schema-id.
@@ -134,8 +134,8 @@ impl TableMetadata {
134134

135135
/// Returns last updated time.
136136
#[inline]
137-
pub fn last_updated_ms(&self) -> Timestamp {
138-
self.last_updated_ms
137+
pub fn last_updated_ms(&self) -> TimestampMillis {
138+
TimestampMillis::new(self.last_updated_ms)
139139
}
140140

141141
/// Returns schemas
@@ -243,7 +243,7 @@ impl TableMetadata {
243243

244244
/// Append snapshot to table
245245
pub fn append_snapshot(&mut self, snapshot: Snapshot) {
246-
self.last_updated_ms = snapshot.timestamp();
246+
self.last_updated_ms = snapshot.timestamp().to_date_time().timestamp_millis();
247247
self.last_sequence_number = snapshot.sequence_number();
248248

249249
self.refs
@@ -279,7 +279,7 @@ pub(super) mod _serde {
279279
use serde::{Deserialize, Serialize};
280280
use uuid::Uuid;
281281

282-
use crate::spec::Snapshot;
282+
use crate::spec::{Snapshot, TimestampMillis};
283283
use crate::{
284284
spec::{
285285
schema::_serde::{SchemaV1, SchemaV2},
@@ -294,8 +294,6 @@ pub(super) mod _serde {
294294
DEFAULT_SPEC_ID, MAIN_BRANCH,
295295
};
296296

297-
use crate::spec::timestamp::Timestamp;
298-
299297
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
300298
#[serde(untagged)]
301299
pub(super) enum TableMetadataEnum {
@@ -311,7 +309,7 @@ pub(super) mod _serde {
311309
pub table_uuid: Uuid,
312310
pub location: String,
313311
pub last_sequence_number: i64,
314-
pub last_updated_ms: Timestamp,
312+
pub last_updated_ms: TimestampMillis,
315313
pub last_column_id: i32,
316314
pub schemas: Vec<SchemaV2>,
317315
pub current_schema_id: i32,
@@ -342,7 +340,7 @@ pub(super) mod _serde {
342340
#[serde(skip_serializing_if = "Option::is_none")]
343341
pub table_uuid: Option<Uuid>,
344342
pub location: String,
345-
pub last_updated_ms: Timestamp,
343+
pub last_updated_ms: TimestampMillis,
346344
pub last_column_id: i32,
347345
pub schema: SchemaV1,
348346
#[serde(skip_serializing_if = "Option::is_none")]
@@ -436,7 +434,7 @@ pub(super) mod _serde {
436434
table_uuid: value.table_uuid,
437435
location: value.location,
438436
last_sequence_number: value.last_sequence_number,
439-
last_updated_ms: value.last_updated_ms,
437+
last_updated_ms: value.last_updated_ms.to_date_time().timestamp_millis(),
440438
last_column_id: value.last_column_id,
441439
current_schema_id: if schemas.keys().contains(&value.current_schema_id) {
442440
Ok(value.current_schema_id)
@@ -544,7 +542,7 @@ pub(super) mod _serde {
544542
table_uuid: value.table_uuid.unwrap_or_default(),
545543
location: value.location,
546544
last_sequence_number: 0,
547-
last_updated_ms: value.last_updated_ms,
545+
last_updated_ms: value.last_updated_ms.to_date_time().timestamp_millis(),
548546
last_column_id: value.last_column_id,
549547
current_schema_id: value
550548
.current_schema_id
@@ -607,7 +605,7 @@ pub(super) mod _serde {
607605
table_uuid: v.table_uuid,
608606
location: v.location,
609607
last_sequence_number: v.last_sequence_number,
610-
last_updated_ms: v.last_updated_ms,
608+
last_updated_ms: TimestampMillis::new(v.last_updated_ms),
611609
last_column_id: v.last_column_id,
612610
schemas: v
613611
.schemas
@@ -673,7 +671,7 @@ pub(super) mod _serde {
673671
format_version: VersionNumber::<1>,
674672
table_uuid: Some(v.table_uuid),
675673
location: v.location,
676-
last_updated_ms: v.last_updated_ms,
674+
last_updated_ms: TimestampMillis::new(v.last_updated_ms),
677675
last_column_id: v.last_column_id,
678676
schema: v
679677
.schemas
@@ -771,7 +769,7 @@ pub struct SnapshotLog {
771769
/// Id of the snapshot.
772770
pub snapshot_id: i64,
773771
/// Last updated timestamp
774-
pub timestamp_ms: Timestamp,
772+
pub timestamp_ms: TimestampMillis,
775773
}
776774

777775
#[cfg(test)]
@@ -790,7 +788,7 @@ mod tests {
790788
SnapshotRetention, SortDirection, SortField, SortOrder, Summary, Transform, Type,
791789
};
792790

793-
use crate::spec::timestamp::Timestamp;
791+
use crate::spec::timestamp_millis::TimestampMillis;
794792

795793
use super::{FormatVersion, MetadataLog, SnapshotLog};
796794

@@ -883,7 +881,7 @@ mod tests {
883881
format_version: FormatVersion::V2,
884882
table_uuid: Uuid::parse_str("fb072c92-a02b-11e9-ae9c-1bb7bc9eca94").unwrap(),
885883
location: "s3://b/wh/data.db/table".to_string(),
886-
last_updated_ms: Timestamp::new(1515100955770).unwrap(),
884+
last_updated_ms: 1515100955770,
887885
last_column_id: 1,
888886
schemas: HashMap::from_iter(vec![(1, Arc::new(schema))]),
889887
current_schema_id: 1,
@@ -1042,7 +1040,7 @@ mod tests {
10421040

10431041
let snapshot = Snapshot::builder()
10441042
.with_snapshot_id(638933773299822130)
1045-
.with_timestamp_ms(Timestamp::new(1662532818843).unwrap())
1043+
.with_timestamp_ms(1662532818843)
10461044
.with_sequence_number(0)
10471045
.with_schema_id(0)
10481046
.with_manifest_list(ManifestListLocation::ManifestListFile("/home/iceberg/warehouse/nyc/taxis/metadata/snap-638933773299822130-1-7e6760f0-4f6c-4b23-b907-0a5a174e3863.avro".to_string()))
@@ -1053,7 +1051,7 @@ mod tests {
10531051
format_version: FormatVersion::V1,
10541052
table_uuid: Uuid::parse_str("df838b92-0b32-465d-a44e-d39936e538b7").unwrap(),
10551053
location: "/home/iceberg/warehouse/nyc/taxis".to_string(),
1056-
last_updated_ms: Timestamp::new(1662532818843).unwrap(),
1054+
last_updated_ms: 1662532818843,
10571055
last_column_id: 5,
10581056
schemas: HashMap::from_iter(vec![(0, Arc::new(schema))]),
10591057
current_schema_id: 0,
@@ -1068,7 +1066,7 @@ mod tests {
10681066
properties: HashMap::from_iter(vec![("owner".to_string(),"root".to_string())]),
10691067
snapshot_log: vec![SnapshotLog {
10701068
snapshot_id: 638933773299822130,
1071-
timestamp_ms: Timestamp::new(1662532818843).unwrap(),
1069+
timestamp_ms: TimestampMillis::new(1662532818843),
10721070
}],
10731071
metadata_log: vec![MetadataLog{metadata_file:"/home/iceberg/warehouse/nyc/taxis/metadata/00000-8a62c37d-4573-4021-952a-c0baef7d21d0.metadata.json".to_string(), timestamp_ms: 1662532805245}],
10741072
refs: HashMap::from_iter(vec![("main".to_string(),SnapshotReference{snapshot_id: 638933773299822130, retention: SnapshotRetention::Branch { min_snapshots_to_keep: None, max_snapshot_age_ms: None, max_ref_age_ms: None }})])
@@ -1166,7 +1164,7 @@ mod tests {
11661164

11671165
let snapshot1 = Snapshot::builder()
11681166
.with_snapshot_id(3051729675574597004)
1169-
.with_timestamp_ms(Timestamp::new(1515100955770).unwrap())
1167+
.with_timestamp_ms(1515100955770)
11701168
.with_sequence_number(0)
11711169
.with_manifest_list(ManifestListLocation::ManifestListFile(
11721170
"s3://a/b/1.avro".to_string(),
@@ -1181,7 +1179,7 @@ mod tests {
11811179
let snapshot2 = Snapshot::builder()
11821180
.with_snapshot_id(3055729675574597004)
11831181
.with_parent_snapshot_id(Some(3051729675574597004))
1184-
.with_timestamp_ms(Timestamp::new(1555100955770).unwrap())
1182+
.with_timestamp_ms(1555100955770)
11851183
.with_sequence_number(1)
11861184
.with_schema_id(1)
11871185
.with_manifest_list(ManifestListLocation::ManifestListFile(
@@ -1198,7 +1196,7 @@ mod tests {
11981196
format_version: FormatVersion::V2,
11991197
table_uuid: Uuid::parse_str("9c12d441-03fe-4693-9a96-a0705ddf69c1").unwrap(),
12001198
location: "s3://bucket/test/location".to_string(),
1201-
last_updated_ms: Timestamp::new(1602638573590).unwrap(),
1199+
last_updated_ms: 1602638573590,
12021200
last_column_id: 3,
12031201
schemas: HashMap::from_iter(vec![(0, Arc::new(schema1)), (1, Arc::new(schema2))]),
12041202
current_schema_id: 1,
@@ -1217,11 +1215,11 @@ mod tests {
12171215
snapshot_log: vec![
12181216
SnapshotLog {
12191217
snapshot_id: 3051729675574597004,
1220-
timestamp_ms: Timestamp::new(1515100955770).unwrap(),
1218+
timestamp_ms: TimestampMillis::new(1515100955770),
12211219
},
12221220
SnapshotLog {
12231221
snapshot_id: 3055729675574597004,
1224-
timestamp_ms: Timestamp::new(1555100955770).unwrap(),
1222+
timestamp_ms: TimestampMillis::new(1555100955770),
12251223
},
12261224
],
12271225
metadata_log: Vec::new(),
@@ -1299,7 +1297,7 @@ mod tests {
12991297
format_version: FormatVersion::V2,
13001298
table_uuid: Uuid::parse_str("9c12d441-03fe-4693-9a96-a0705ddf69c1").unwrap(),
13011299
location: "s3://bucket/test/location".to_string(),
1302-
last_updated_ms: Timestamp::new(1602638573590).unwrap(),
1300+
last_updated_ms: 1602638573590,
13031301
last_column_id: 3,
13041302
schemas: HashMap::from_iter(vec![(0, Arc::new(schema))]),
13051303
current_schema_id: 0,
@@ -1361,7 +1359,7 @@ mod tests {
13611359
format_version: FormatVersion::V1,
13621360
table_uuid: Uuid::parse_str("d20125c8-7284-442c-9aea-15fee620737c").unwrap(),
13631361
location: "s3://bucket/test/location".to_string(),
1364-
last_updated_ms: Timestamp::new(1602638573874).unwrap(),
1362+
last_updated_ms: 1602638573874,
13651363
last_column_id: 3,
13661364
schemas: HashMap::from_iter(vec![(0, Arc::new(schema))]),
13671365
current_schema_id: 0,

0 commit comments

Comments
 (0)