diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLine.java b/beeline/src/java/org/apache/hive/beeline/BeeLine.java index b3d89cb..e207670 100644 --- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java +++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java @@ -31,6 +31,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; +import java.io.SequenceInputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -829,7 +830,11 @@ public void close() { public ConsoleReader getConsoleReader(InputStream inputStream) throws IOException { if (inputStream != null) { // ### NOTE: fix for sf.net bug 879425. - consoleReader = new ConsoleReader(inputStream, getOutputStream()); + // Working around an issue in jline-2.1.2, see https://github.com/jline/jline/issues/10 + // by appending a newline to the end of inputstream + InputStream inputStreamAppendedNewline = new SequenceInputStream(inputStream, + new ByteArrayInputStream((new String("\n")).getBytes())); + consoleReader = new ConsoleReader(inputStreamAppendedNewline, getOutputStream()); } else { consoleReader = new ConsoleReader(); } diff --git a/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java b/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java index f66229f..f0795d2 100644 --- a/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java +++ b/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java @@ -220,6 +220,18 @@ public void testPositiveScriptFile() throws Throwable { } /** + * Fix to HIVE-10541: Beeline requires a newline at the end of each query in a file. + * Otherwise, the last line of cmd in the script will be ignored. + */ + @Test + public void testLastLineCmdInScriptFile() throws Throwable { + final String SCRIPT_TEXT = "show databases;\nshow tables;"; + final String EXPECTED_PATTERN = " testbeelinetable1 "; + List argList = getBaseArgs(miniHS2.getBaseJdbcURL()); + testScriptFile( SCRIPT_TEXT, EXPECTED_PATTERN, true, argList); + } + + /** * Test Beeline -hivevar option. User can specify --hivevar name=value on Beeline command line. * In the script, user should be able to use it in the form of ${name}, which will be substituted with * the value.