commit 85f5b56e4582dc088b4a75085baae533562243f5 Author: Bharath Krishna Date: Wed Mar 28 21:14:04 2018 -0700 HIVE-19047 : Fix for only the first init file is interpreted using beeline option -i diff --git beeline/src/java/org/apache/hive/beeline/BeeLine.java beeline/src/java/org/apache/hive/beeline/BeeLine.java index 402fadddde707714ae00defcf0b430f509a4405a..19eb353a6fb7a956d59f6885d55b01d4919acbb3 100644 --- beeline/src/java/org/apache/hive/beeline/BeeLine.java +++ beeline/src/java/org/apache/hive/beeline/BeeLine.java @@ -357,7 +357,7 @@ // -i options.addOption(OptionBuilder - .hasArg() + .hasArgs() .withArgName("init") .withDescription("script file for initialization") .create('i')); @@ -1118,18 +1118,30 @@ public HS2ConnectionFileParser getHiveSiteHS2ConnectionFileParser() { } int runInit() { - String initFiles[] = getOpts().getInitFiles(); + String[] initFiles = getOpts().getInitFiles(); + + //executionResult will be ERRNO_OK only if all initFiles execute successfully + int executionResult = ERRNO_OK; + boolean exitOnError = !getOpts().getForce(); + if (initFiles != null && initFiles.length != 0) { for (String initFile : initFiles) { info("Running init script " + initFile); try { - return executeFile(initFile); + int currentResult = executeFile(initFile); + if (currentResult != ERRNO_OK) { + executionResult = currentResult; + + if (exitOnError) { + return executionResult; + } + } } finally { exit = false; } } } - return ERRNO_OK; + return executionResult; } private int embeddedConnect() { diff --git beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java index 40dbc223c831cf322c826bcef8fbd29de25917fd..1fa6a75cb5b35e82faf13e039c3ae71be86a6ec7 100644 --- beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java +++ beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java @@ -254,6 +254,19 @@ public void testCommandAndFileSimultaneously() throws Exception { Assert.assertEquals(1, bl.initArgs(args)); } + /** + * Test beeline with multiple initfiles in -i. + */ + @Test + public void testMultipleInitFiles() { + TestBeeline bl = new TestBeeline(); + String[] args = new String[] {"-i", "/url/to/file1", "-i", "/url/to/file2"}; + Assert.assertEquals(0, bl.initArgs(args)); + String[] files = bl.getOpts().getInitFiles(); + Assert.assertEquals("/url/to/file1", files[0]); + Assert.assertEquals("/url/to/file2", files[1]); + } + /** * Displays the usage. */