diff --git beeline/src/java/org/apache/hive/beeline/BeeLine.java beeline/src/java/org/apache/hive/beeline/BeeLine.java index 10fd2e2..34c13c8 100644 --- beeline/src/java/org/apache/hive/beeline/BeeLine.java +++ beeline/src/java/org/apache/hive/beeline/BeeLine.java @@ -697,7 +697,9 @@ boolean initArgs(String[] args) { for (Iterator i = commands.iterator(); i.hasNext();) { String command = i.next().toString(); debug(loc("executing-command", command)); - dispatch(command); + for (String singleCommand: command.split(";")) { + dispatch(singleCommand + ";"); + } } exit = true; // execute and exit } diff --git itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java index 8888bd9..7beade4 100644 --- itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java +++ itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java @@ -210,7 +210,23 @@ private void testScriptFile(String testName, String scriptText, String expectedP } scriptFile.delete(); } - + + private void testCommands(String testName, String expectedPattern, + boolean shouldMatch, List argList) throws Throwable { + System.out.println(">>> STARTED " + testName); + { + List copy = new ArrayList(argList); + + String output = testCommandLineScript(copy, null); + boolean matches = output.contains(expectedPattern); + if (shouldMatch != matches) { + //failed + fail(testName + ": Output" + output + " should" + (shouldMatch ? "" : " not") + + " contain " + expectedPattern); + } + } + } + /** * Test that BeeLine will read comment lines that start with whitespace * @throws Throwable @@ -477,4 +493,13 @@ public void testEmbeddedBeelineConnection() throws Throwable{ final String EXPECTED_PATTERN = "embedded_table"; testScriptFile(TEST_NAME, SCRIPT_TEXT, EXPECTED_PATTERN, true, argList); } + + @Test + public void testCommandWithMultipleQueries() throws Throwable { + List argList = getBaseArgs(JDBC_URL + "#D_TBL=dummy_t"); + argList.add("-e \"create table ${D_TBL} (d int);show tables;\""); + final String TEST_NAME = "testCommandWithMultipleQueries"; + final String EXPECTED_PATTERN = "dummy_t"; + testCommands(TEST_NAME, EXPECTED_PATTERN, true, argList); + } }