@@ -1255,3 +1255,137 @@ fn test_create_checkpoint_stream_reads_checkpoint_file_and_returns_sidecar_batch
1255
1255
1256
1256
Ok ( ( ) )
1257
1257
}
1258
+
1259
+ #[ test]
1260
+ fn for_timestamp_conversion_gets_commit_range ( ) {
1261
+ let ( storage, log_root) = build_log_with_paths_and_checkpoint (
1262
+ & [
1263
+ delta_path_for_version ( 0 , "json" ) ,
1264
+ delta_path_for_version ( 1 , "json" ) ,
1265
+ delta_path_for_version ( 1 , "checkpoint.parquet" ) ,
1266
+ delta_path_for_version ( 2 , "json" ) ,
1267
+ delta_path_for_version ( 3 , "json" ) ,
1268
+ delta_path_for_version ( 3 , "checkpoint.parquet" ) ,
1269
+ delta_path_for_version ( 4 , "json" ) ,
1270
+ delta_path_for_version ( 5 , "json" ) ,
1271
+ delta_path_for_version ( 5 , "checkpoint.parquet" ) ,
1272
+ delta_path_for_version ( 6 , "json" ) ,
1273
+ delta_path_for_version ( 7 , "json" ) ,
1274
+ ] ,
1275
+ None ,
1276
+ ) ;
1277
+
1278
+ let log_segment =
1279
+ LogSegment :: for_timestamp_conversion ( storage. as_ref ( ) , log_root. clone ( ) , 7 , None ) . unwrap ( ) ;
1280
+ let commit_files = log_segment. ascending_commit_files ;
1281
+ let checkpoint_parts = log_segment. checkpoint_parts ;
1282
+
1283
+ assert ! ( checkpoint_parts. is_empty( ) ) ;
1284
+
1285
+ let versions = commit_files. iter ( ) . map ( |x| x. version ) . collect_vec ( ) ;
1286
+ assert_eq ! ( vec![ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ] , versions) ;
1287
+ }
1288
+
1289
+ #[ test]
1290
+ fn for_timestamp_conversion_with_old_end_version ( ) {
1291
+ let ( storage, log_root) = build_log_with_paths_and_checkpoint (
1292
+ & [
1293
+ delta_path_for_version ( 0 , "json" ) ,
1294
+ delta_path_for_version ( 1 , "json" ) ,
1295
+ delta_path_for_version ( 1 , "checkpoint.parquet" ) ,
1296
+ delta_path_for_version ( 2 , "json" ) ,
1297
+ delta_path_for_version ( 3 , "json" ) ,
1298
+ delta_path_for_version ( 3 , "checkpoint.parquet" ) ,
1299
+ delta_path_for_version ( 4 , "json" ) ,
1300
+ delta_path_for_version ( 5 , "json" ) ,
1301
+ delta_path_for_version ( 5 , "checkpoint.parquet" ) ,
1302
+ delta_path_for_version ( 6 , "json" ) ,
1303
+ delta_path_for_version ( 7 , "json" ) ,
1304
+ ] ,
1305
+ None ,
1306
+ ) ;
1307
+
1308
+ let log_segment =
1309
+ LogSegment :: for_timestamp_conversion ( storage. as_ref ( ) , log_root. clone ( ) , 5 , None ) . unwrap ( ) ;
1310
+ let commit_files = log_segment. ascending_commit_files ;
1311
+ let checkpoint_parts = log_segment. checkpoint_parts ;
1312
+
1313
+ assert ! ( checkpoint_parts. is_empty( ) ) ;
1314
+
1315
+ let versions = commit_files. iter ( ) . map ( |x| x. version ) . collect_vec ( ) ;
1316
+ assert_eq ! ( vec![ 0 , 1 , 2 , 3 , 4 , 5 ] , versions) ;
1317
+ }
1318
+
1319
+ #[ test]
1320
+ fn for_timestamp_conversion_only_contiguous_ranges ( ) {
1321
+ let ( storage, log_root) = build_log_with_paths_and_checkpoint (
1322
+ & [
1323
+ delta_path_for_version ( 0 , "json" ) ,
1324
+ delta_path_for_version ( 1 , "json" ) ,
1325
+ delta_path_for_version ( 1 , "checkpoint.parquet" ) ,
1326
+ delta_path_for_version ( 2 , "json" ) ,
1327
+ delta_path_for_version ( 3 , "json" ) ,
1328
+ delta_path_for_version ( 3 , "checkpoint.parquet" ) ,
1329
+ // version 4 is missing
1330
+ delta_path_for_version ( 5 , "json" ) ,
1331
+ delta_path_for_version ( 5 , "checkpoint.parquet" ) ,
1332
+ delta_path_for_version ( 6 , "json" ) ,
1333
+ delta_path_for_version ( 7 , "json" ) ,
1334
+ ] ,
1335
+ None ,
1336
+ ) ;
1337
+
1338
+ let log_segment =
1339
+ LogSegment :: for_timestamp_conversion ( storage. as_ref ( ) , log_root. clone ( ) , 7 , None ) . unwrap ( ) ;
1340
+ let commit_files = log_segment. ascending_commit_files ;
1341
+ let checkpoint_parts = log_segment. checkpoint_parts ;
1342
+
1343
+ assert ! ( checkpoint_parts. is_empty( ) ) ;
1344
+
1345
+ let versions = commit_files. iter ( ) . map ( |x| x. version ) . collect_vec ( ) ;
1346
+ assert_eq ! ( vec![ 5 , 6 , 7 ] , versions) ;
1347
+ }
1348
+
1349
+ #[ test]
1350
+ fn for_timestamp_conversion_with_limit ( ) {
1351
+ let ( storage, log_root) = build_log_with_paths_and_checkpoint (
1352
+ & [
1353
+ delta_path_for_version ( 0 , "json" ) ,
1354
+ delta_path_for_version ( 1 , "json" ) ,
1355
+ delta_path_for_version ( 1 , "checkpoint.parquet" ) ,
1356
+ delta_path_for_version ( 2 , "json" ) ,
1357
+ delta_path_for_version ( 3 , "json" ) ,
1358
+ delta_path_for_version ( 3 , "checkpoint.parquet" ) ,
1359
+ delta_path_for_version ( 4 , "json" ) ,
1360
+ delta_path_for_version ( 5 , "json" ) ,
1361
+ delta_path_for_version ( 5 , "checkpoint.parquet" ) ,
1362
+ delta_path_for_version ( 6 , "json" ) ,
1363
+ delta_path_for_version ( 7 , "json" ) ,
1364
+ ] ,
1365
+ None ,
1366
+ ) ;
1367
+
1368
+ let log_segment =
1369
+ LogSegment :: for_timestamp_conversion ( storage. as_ref ( ) , log_root. clone ( ) , 7 , Some ( 3 ) )
1370
+ . unwrap ( ) ;
1371
+ let commit_files = log_segment. ascending_commit_files ;
1372
+ let checkpoint_parts = log_segment. checkpoint_parts ;
1373
+
1374
+ assert ! ( checkpoint_parts. is_empty( ) ) ;
1375
+
1376
+ let versions = commit_files. iter ( ) . map ( |x| x. version ) . collect_vec ( ) ;
1377
+ assert_eq ! ( vec![ 5 , 6 , 7 ] , versions) ;
1378
+ }
1379
+
1380
+ #[ test]
1381
+ fn for_timestamp_conversion_no_commit_files ( ) {
1382
+ let ( storage, log_root) = build_log_with_paths_and_checkpoint (
1383
+ & [ delta_path_for_version ( 5 , "checkpoint.parquet" ) ] ,
1384
+ None ,
1385
+ ) ;
1386
+
1387
+ let res = LogSegment :: for_timestamp_conversion ( storage. as_ref ( ) , log_root. clone ( ) , 0 , None ) ;
1388
+ assert ! ( res. is_err( ) ) ;
1389
+ let msg = res. err ( ) . unwrap ( ) . to_string ( ) ;
1390
+ assert ! ( msg. contains( "No files in log segment" ) )
1391
+ }
0 commit comments