From f4d47ba866f56537652914b163ae4933d21982c3 Mon Sep 17 00:00:00 2001 From: Yi Hu Date: Mon, 27 Jan 2025 16:56:21 -0500 Subject: [PATCH] Fix path --- .../catalog/hiveutils/TestHiveMetastore.java | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/sdks/java/io/iceberg/src/test/java/org/apache/beam/sdk/io/iceberg/catalog/hiveutils/TestHiveMetastore.java b/sdks/java/io/iceberg/src/test/java/org/apache/beam/sdk/io/iceberg/catalog/hiveutils/TestHiveMetastore.java index d730b47bf420..23de4f379640 100644 --- a/sdks/java/io/iceberg/src/test/java/org/apache/beam/sdk/io/iceberg/catalog/hiveutils/TestHiveMetastore.java +++ b/sdks/java/io/iceberg/src/test/java/org/apache/beam/sdk/io/iceberg/catalog/hiveutils/TestHiveMetastore.java @@ -33,6 +33,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; @@ -43,10 +44,7 @@ import org.apache.hadoop.hive.metastore.IHMSHandler; import org.apache.hadoop.hive.metastore.IMetaStoreClient; import org.apache.hadoop.hive.metastore.TSetIpAddressProcessor; -import org.apache.hadoop.hive.metastore.api.GetTableRequest; -import org.apache.hadoop.hive.metastore.api.Table; import org.apache.iceberg.ClientPool; -import org.apache.iceberg.catalog.TableIdentifier; import org.apache.iceberg.common.DynConstructors; import org.apache.iceberg.common.DynMethods; import org.apache.iceberg.hadoop.Util; @@ -63,8 +61,8 @@ * HiveMetastoreExtension} instead. * *

Copied over from Iceberg's - * integration testing util + * href="https://github.com/apache/hive/blob/branch-4.0/iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java"> + * Hive metastore Iceberg integration utils */ public class TestHiveMetastore { @@ -114,7 +112,6 @@ public class TestHiveMetastore { HIVE_LOCAL_DIR = createTempDirectory("hive", asFileAttribute(fromString("rwxrwxrwx"))).toFile(); DERBY_PATH = new File(HIVE_LOCAL_DIR, "metastore_db").getPath(); - HIVE_EXTERNAL_WAREHOUSE_DIR = new File(HIVE_LOCAL_DIR, "external"); File derbyLogFile = new File(HIVE_LOCAL_DIR, "derby.log"); System.setProperty("derby.stream.error.file", derbyLogFile.getAbsolutePath()); setupMetastoreDB("jdbc:derby:" + DERBY_PATH + ";create=true"); @@ -202,6 +199,12 @@ public void stop() throws Exception { } if (executorService != null) { executorService.shutdown(); + try { + // Give it a reasonable timeout + executorService.awaitTermination(10, TimeUnit.SECONDS); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } } if (baseHandler != null) { baseHandler.shutdown(); @@ -241,6 +244,9 @@ public void reset() throws Exception { Path warehouseRoot = new Path(hiveWarehousePath); FileSystem fs = Util.getFs(warehouseRoot, hiveConf); + if (!fs.exists(warehouseRoot)) { + return; + } for (FileStatus fileStatus : fs.listStatus(warehouseRoot)) { if (!fileStatus.getPath().getName().equals("derby.log") && !fileStatus.getPath().getName().equals("metastore_db")) { @@ -249,14 +255,6 @@ public void reset() throws Exception { } } - public Table getTable(String dbName, String tableName) throws TException, InterruptedException { - return clientPool.run(client -> client.getTable(new GetTableRequest(dbName, tableName))); - } - - public Table getTable(TableIdentifier identifier) throws TException, InterruptedException { - return getTable(identifier.namespace().toString(), identifier.name()); - } - public T run(ClientPool.Action action) throws InterruptedException, TException { return clientPool.run(action, false); @@ -285,16 +283,13 @@ private TServer newThriftServer(TServerSocket socket, int poolSize, HiveConf con private void initConf(HiveConf conf, int port) { conf.set(HiveConf.ConfVars.METASTORE_URIS.varname, "thrift://localhost:" + port); conf.set(HiveConf.ConfVars.METASTORE_WAREHOUSE.varname, hiveWarehousePath); - conf.set( - HiveConf.ConfVars.HIVE_METASTORE_WAREHOUSE_EXTERNAL.varname, - "file:" + HIVE_EXTERNAL_WAREHOUSE_DIR.getAbsolutePath()); + conf.set(HiveConf.ConfVars.HIVE_METASTORE_WAREHOUSE_EXTERNAL.varname, hiveWarehousePath); conf.set(HiveConf.ConfVars.METASTORE_TRY_DIRECT_SQL.varname, "false"); conf.set(HiveConf.ConfVars.METASTORE_DISALLOW_INCOMPATIBLE_COL_TYPE_CHANGES.varname, "false"); conf.set("iceberg.hive.client-pool-size", "2"); - // set to false so that TxnManager#checkLock does not throw exception when using UNSET data type - // operation - // in the requested lock component - conf.setBoolVar(HiveConf.ConfVars.HIVE_IN_TEST, false); + // Setting this to avoid thrift exception during running Iceberg tests outside Iceberg. + conf.set( + HiveConf.ConfVars.HIVE_IN_TEST.varname, HiveConf.ConfVars.HIVE_IN_TEST.getDefaultValue()); } private static void setupMetastoreDB(String dbURL) throws Exception {