rdblue commented on code in PR #4946:
URL: https://github.com/apache/iceberg/pull/4946#discussion_r890379144
##########
hive-metastore/src/test/java/org/apache/iceberg/hive/HiveTableTest.java:
##########
@@ -404,6 +389,80 @@ public void testRegisterTable() throws TException {
Assert.assertEquals(originalTable.getSd(), newTable.getSd());
}
+ @Test
+ public void testRegisterHadoopTableToHiveCatalog() throws IOException,
TException {
+ // create a hadoop catalog
+ String tableLocation = tempFolder.newFolder().toString();
+ HadoopCatalog hadoopCatalog = new HadoopCatalog(new Configuration(),
tableLocation);
+ // create table using hadoop catalog
+ TableIdentifier identifier = TableIdentifier.of(DB_NAME, "table1");
+ Table table = hadoopCatalog.createTable(identifier, schema,
PartitionSpec.unpartitioned(), Maps.newHashMap());
+ // insert some data
+ appendData(table, "file1");
+ List<FileScanTask> tasks = Lists.newArrayList(table.newScan().planFiles());
+ Assert.assertEquals("Should scan 1 file", 1, tasks.size());
+
+ // collect metadata file
+ List<String> metadataFiles =
+ Arrays.stream(new File(table.location() + "/metadata").listFiles())
+ .map(File::getAbsolutePath)
+ .filter(f ->
f.endsWith(getFileExtension(TableMetadataParser.Codec.NONE)))
+ .collect(Collectors.toList());
+ Assert.assertEquals(2, metadataFiles.size());
+
+ AssertHelpers.assertThrows(
+ "Hive metastore should not have this table",
NoSuchObjectException.class,
+ "table not found",
+ () -> metastoreClient.getTable(DB_NAME, "table1"));
+ AssertHelpers.assertThrows(
+ "Hive catalog should fail to load the table",
NoSuchTableException.class,
+ "Table does not exist:",
+ () -> catalog.loadTable(identifier));
+
+ // register the table to hive catalog using the latest metadata file
+ metadataFiles.sort(Collections.reverseOrder());
Review Comment:
Rather than guessing which file is the metadata file, I think you should
just get the location from the table:
```java
String metadataLocation = ((BaseTable)
table).operations().current().metadataFileLocation();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]