2525import java .util .Collections ;
2626import java .util .List ;
2727import java .util .Map ;
28+ import java .util .Set ;
2829import java .util .stream .Collectors ;
2930import org .apache .avro .generic .GenericData ;
3031import org .apache .avro .generic .GenericRecordBuilder ;
3738import org .apache .hadoop .hive .metastore .api .hive_metastoreConstants ;
3839import org .apache .hadoop .hive .serde .serdeConstants ;
3940import org .apache .iceberg .AssertHelpers ;
41+ import org .apache .iceberg .BaseTable ;
4042import org .apache .iceberg .DataFile ;
4143import org .apache .iceberg .DataFiles ;
4244import org .apache .iceberg .FileScanTask ;
@@ -398,9 +400,10 @@ public void testRegisterHadoopTableToHiveCatalog() throws IOException, TExceptio
398400 TableIdentifier identifier = TableIdentifier .of (DB_NAME , "table1" );
399401 Table table = hadoopCatalog .createTable (identifier , schema , PartitionSpec .unpartitioned (), Maps .newHashMap ());
400402 // insert some data
401- appendData (table , "file1" );
403+ String file1Location = appendData (table , "file1" );
402404 List <FileScanTask > tasks = Lists .newArrayList (table .newScan ().planFiles ());
403405 Assert .assertEquals ("Should scan 1 file" , 1 , tasks .size ());
406+ Assert .assertEquals (tasks .get (0 ).file ().path (), file1Location );
404407
405408 // collect metadata file
406409 List <String > metadataFiles =
@@ -420,18 +423,20 @@ public void testRegisterHadoopTableToHiveCatalog() throws IOException, TExceptio
420423 () -> catalog .loadTable (identifier ));
421424
422425 // register the table to hive catalog using the latest metadata file
423- metadataFiles . sort ( Collections . reverseOrder () );
424- catalog .registerTable (identifier , "file:" + metadataFiles . get ( 0 ) );
426+ String latestMetadataFile = (( BaseTable ) table ). operations (). current (). metadataFileLocation ( );
427+ catalog .registerTable (identifier , "file:" + latestMetadataFile );
425428 Assert .assertNotNull (metastoreClient .getTable (DB_NAME , "table1" ));
426429
427430 // load the table in hive catalog
428431 table = catalog .loadTable (identifier );
429432 Assert .assertNotNull (table );
430433
431434 // insert some data
432- appendData (table , "file2" );
435+ String file2Location = appendData (table , "file2" );
433436 tasks = Lists .newArrayList (table .newScan ().planFiles ());
434437 Assert .assertEquals ("Should scan 2 files" , 2 , tasks .size ());
438+ Set <String > files = tasks .stream ().map (task -> task .file ().path ().toString ()).collect (Collectors .toSet ());
439+ Assert .assertTrue (files .contains (file1Location ) && files .contains (file2Location ));
435440 }
436441
437442 private String appendData (Table table , String fileName ) throws IOException {
0 commit comments