File tree Expand file tree Collapse file tree 2 files changed +17
-11
lines changed Expand file tree Collapse file tree 2 files changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -1291,10 +1291,15 @@ def snapshot_by_name(self, name: str) -> Optional[Snapshot]:
1291
1291
return self .snapshot_by_id (ref .snapshot_id )
1292
1292
return None
1293
1293
1294
- def snapshot_at_or_before_timestamp (self , timestamp_ms : int ) -> Optional [Snapshot ]:
1295
- """Get the snapshot that was current at or right before the given timestamp, or None if there is no matching snapshot."""
1294
+ def snapshot_as_of_timestamp (self , timestamp_ms : int , inclusive : bool = True ) -> Optional [Snapshot ]:
1295
+ """Get the snapshot that was current as of or right before the given timestamp, or None if there is no matching snapshot.
1296
+
1297
+ Args:
1298
+ timestamp_ms: Find snapshot that was current at/before this timestamp
1299
+ inclusive: Includes timestamp_ms in search when True. Excludes timestamp_ms when False
1300
+ """
1296
1301
for log_entry in reversed (self .history ()):
1297
- if log_entry .timestamp_ms <= timestamp_ms :
1302
+ if ( inclusive and log_entry .timestamp_ms <= timestamp_ms ) or log_entry . timestamp_ms < timestamp_ms :
1298
1303
return self .snapshot_by_id (log_entry .snapshot_id )
1299
1304
return None
1300
1305
Original file line number Diff line number Diff line change @@ -205,15 +205,16 @@ def test_snapshot_by_id(table_v2: Table) -> None:
205
205
206
206
207
207
def test_snapshot_by_timestamp (table_v2 : Table ) -> None :
208
- assert table_v2 .snapshot_at_or_before_timestamp ( 1555100955771 ) == Snapshot (
209
- snapshot_id = 3055729675574597004 ,
210
- parent_snapshot_id = 3051729675574597004 ,
211
- sequence_number = 1 ,
212
- timestamp_ms = 1555100955770 ,
213
- manifest_list = " s3://a/b/2 .avro" ,
214
- summary = Summary (operation = Operation .APPEND ),
215
- schema_id = 1 ,
208
+ assert table_v2 .snapshot_as_of_timestamp ( 1515100955770 ) == Snapshot (
209
+ snapshot_id = 3051729675574597004 ,
210
+ parent_snapshot_id = None ,
211
+ sequence_number = 0 ,
212
+ timestamp_ms = 1515100955770 ,
213
+ manifest_list = ' s3://a/b/1 .avro' ,
214
+ summary = Summary (Operation .APPEND ),
215
+ schema_id = None ,
216
216
)
217
+ assert table_v2 .snapshot_as_of_timestamp (1515100955770 , inclusive = False ) is None
217
218
218
219
219
220
def test_current_ancestors (table_v2 : Table ) -> None :
You can’t perform that action at this time.
0 commit comments