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 cfb3f9a..6ee5b8d 100644 --- a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -1448,8 +1448,8 @@ // Hive global init file location HIVE_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\n" + + "If the property is set, the value must be a valid path where the init file is located."), // prefix used to auto generated column aliases (this should be started with '_') HIVE_AUTOGEN_COLUMNALIAS_PREFIX_LABEL("hive.autogen.columnalias.prefix.label", "_c", 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 b0bb8be..60e43aa 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_GLOBAL_INIT_FILE_LOCATION) != null) { - String hiverc = hiveConf.getVar(ConfVars.HIVE_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_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 66fc1fc..10fe0f1 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 @@ -40,6 +40,7 @@ private ThriftCLIServiceClient client; private File initFile; private String tmpDir; + private HiveConf hiveConf; /** * This class is almost the same as EmbeddedThriftBinaryCLIService, @@ -82,7 +83,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_GLOBAL_INIT_FILE_LOCATION, initFile.getParentFile().getAbsolutePath()); service = new FakeEmbeddedThriftBinaryCLIService(hiveConf); @@ -98,11 +99,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_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);