zhangminglei commented on a change in pull request #1659:
URL: https://github.com/apache/iceberg/pull/1659#discussion_r512536531
##########
File path:
flink/src/test/java/org/apache/iceberg/flink/TestFlinkHiveCatalog.java
##########
@@ -76,6 +78,36 @@ public void testCreateCatalogWithHiveConfDir() throws
IOException {
checkSQLQuery(props, warehouseDir);
}
+ @Test
+ public void testCreateCatalogWithHiveHome() throws IOException {
+ File hiveHome = tempFolder.newFolder();
+ File hiveConfDir = new File(hiveHome, "conf");
+ hiveConfDir.mkdir();
+ File hiveSiteXML = new File(hiveConfDir, "hive-site.xml");
+ File warehouseDir = tempFolder.newFolder();
+
+ try (FileOutputStream fos = new FileOutputStream(hiveSiteXML)) {
+ Configuration newConf = new Configuration(hiveConf);
+ newConf.set(HiveConf.ConfVars.METASTOREWAREHOUSE.varname, "file://" +
warehouseDir.getAbsolutePath());
+ newConf.writeXml(fos);
+ }
+ Assert.assertTrue("hive-site.xml should be created now.",
Files.exists(hiveSiteXML.toPath()));
+
+ final Map<String, String> originalEnv = System.getenv();
+ final Map<String, String> newEnv = new HashMap<>(originalEnv);
+
+ newEnv.put("HIVE_HOME", hiveHome.getAbsolutePath());
+ CommonTestUtils.setEnv(newEnv);
+
+ // Construct the catalog attributions.
+ Map<String, String> props = Maps.newHashMap();
+ props.put("type", "iceberg");
+ props.put(FlinkCatalogFactory.ICEBERG_CATALOG_TYPE, "hive");
+ props.put(FlinkCatalogFactory.HIVE_URI,
FlinkCatalogTestBase.getURI(hiveConf));
+
+ checkSQLQuery(props, warehouseDir);
Review comment:
Sorry, I might think we can not `try-finally` here because we have
`String hiveHome = System.getenv("HIVE_HOME");` after then. If we `finally` to
`originalEnv`, then return `null` from there. And the test can not passed.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]