diff --git a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java index 3a045b7..0b68640 100644 --- a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -1503,8 +1503,8 @@ "The parent node in ZooKeeper used by HiveServer2 when supporting dynamic service discovery."), // HiveServer2 global init file location HIVE_SERVER2_GLOBAL_INIT_FILE_LOCATION("hive.server2.global.init.file.location", "${env:HIVE_CONF_DIR}", - "The location of HS2 global init file (.hiverc).\n" + - "If the property is reset, the value must be a valid path where the init file is located."), + "Either the location of a HS2 global init file or a directory containing a .hiverc file. If the \n" + + "property is set, the value must be a valid path to an init file or directory where the init file is located."), HIVE_SERVER2_TRANSPORT_MODE("hive.server2.transport.mode", "binary", new StringSet("binary", "http"), "Transport mode of HiveServer2."), HIVE_SERVER2_THRIFT_BIND_HOST("hive.server2.thrift.bind.host", "", diff --git a/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java b/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java index 5231d5e..f021870 100644 --- a/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java +++ b/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java @@ -166,15 +166,20 @@ private void processGlobalInitFile() { IHiveFileProcessor processor = new GlobalHivercFileProcessor(); try { - if (hiveConf.getVar(ConfVars.HIVE_SERVER2_GLOBAL_INIT_FILE_LOCATION) != null) { - String hiverc = hiveConf.getVar(ConfVars.HIVE_SERVER2_GLOBAL_INIT_FILE_LOCATION) - + File.separator + SessionManager.HIVERCFILE; - if (new File(hiverc).exists()) { - LOG.info("Running global init file: " + hiverc); - int rc = processor.processFile(hiverc); + String hiverc = hiveConf.getVar(ConfVars.HIVE_SERVER2_GLOBAL_INIT_FILE_LOCATION); + if (hiverc != null) { + File hivercFile = new File(hiverc); + if (hivercFile.isDirectory()) { + hivercFile = new File(hivercFile, SessionManager.HIVERCFILE); + } + if (hivercFile.isFile()) { + LOG.info("Running global init file: " + hivercFile); + int rc = processor.processFile(hivercFile.getAbsolutePath()); if (rc != 0) { - LOG.warn("Failed on initializing global .hiverc file"); + LOG.error("Failed on initializing global .hiverc file"); } + } else { + LOG.debug("Global init file " + hivercFile + " does not exist"); } } } catch (IOException e) { diff --git a/service/src/test/org/apache/hive/service/cli/session/TestSessionGlobalInitFile.java b/service/src/test/org/apache/hive/service/cli/session/TestSessionGlobalInitFile.java index 5b1cbc0..8ae1ab0 100644 --- a/service/src/test/org/apache/hive/service/cli/session/TestSessionGlobalInitFile.java +++ b/service/src/test/org/apache/hive/service/cli/session/TestSessionGlobalInitFile.java @@ -44,6 +44,7 @@ private ThriftCLIServiceClient client; private File initFile; private String tmpDir; + private HiveConf hiveConf; /** * This class is almost the same as EmbeddedThriftBinaryCLIService, @@ -86,7 +87,7 @@ public void setUp() throws Exception { FileUtils.writeLines(initFile, Arrays.asList(fileContent)); // set up service and client - HiveConf hiveConf = new HiveConf(); + hiveConf = new HiveConf(); hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_GLOBAL_INIT_FILE_LOCATION, initFile.getParentFile().getAbsolutePath()); service = new FakeEmbeddedThriftBinaryCLIService(hiveConf); @@ -102,11 +103,25 @@ public void tearDown() throws Exception { @Test public void testSessionGlobalInitFile() throws Exception { - /** - * create session, and fetch the property set in global init file. Test if - * the global init file .hiverc is loaded correctly by checking the expected - * setting property. - */ + File tmpInitFile = new File(initFile.getParent(), "hiverc"); + Assert.assertTrue("Failed to rename " + initFile + " to " + tmpInitFile, + initFile.renameTo(tmpInitFile)); + initFile = tmpInitFile; + hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_GLOBAL_INIT_FILE_LOCATION, + initFile.getAbsolutePath()); + doTestSessionGlobalInitFile(); + } + @Test + public void testSessionGlobalInitDir() throws Exception { + doTestSessionGlobalInitFile(); + } + + /** + * create session, and fetch the property set in global init file. Test if + * the global init file .hiverc is loaded correctly by checking the expected + * setting property. + */ + private void doTestSessionGlobalInitFile() throws Exception { SessionHandle sessionHandle = client.openSession(null, null, null); verifyInitProperty("a", "1", sessionHandle);