commit 7f62c04d19291685c4a638b90f01ef69539719de Author: Vihang Karajgaonkar Date: Tue May 9 12:37:23 2017 -0700 HIVE-14389 : Beeline should not output query and prompt to stdout diff --git beeline/src/java/org/apache/hive/beeline/BeeLine.java beeline/src/java/org/apache/hive/beeline/BeeLine.java index a589f337381258a96425f9cae2e57eea72f70bb6..1aed085f93420c8fa4fb3da62b608adb41eb589c 100644 --- beeline/src/java/org/apache/hive/beeline/BeeLine.java +++ beeline/src/java/org/apache/hive/beeline/BeeLine.java @@ -141,6 +141,7 @@ private OutputFile recordOutputFile = null; private PrintStream outputStream = new PrintStream(System.out, true); private PrintStream errorStream = new PrintStream(System.err, true); + private InputStream inputStream = System.in; private ConsoleReader consoleReader; private List batch = null; private final Reflector reflector = new Reflector(this); @@ -1223,10 +1224,10 @@ public ConsoleReader initializeConsoleReader(InputStream inputStream) throws IOE // 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()); + consoleReader = new ConsoleReader(inputStreamAppendedNewline, getErrorStream()); consoleReader.setCopyPasteDetection(true); // jline will detect if is regular character } else { - consoleReader = new ConsoleReader(); + consoleReader = new ConsoleReader(getInputStream(), getErrorStream()); } //disable the expandEvents for the purpose of backward compatibility @@ -2404,6 +2405,10 @@ PrintStream getErrorStream() { return errorStream; } + InputStream getInputStream() { + return inputStream; + } + ConsoleReader getConsoleReader() { return consoleReader; } diff --git beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java index d306e29f5a9b8c57182a70a1428300209c720a2b..8eaa68308f00b98f2dc7af21362032ba961e08d6 100644 --- beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java +++ beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java @@ -112,7 +112,7 @@ public void testCmd() { @Test public void testSetPromptValue() { - verifyCMD("set hive.cli.prompt=MYCLI;SHOW\nTABLES;", "MYCLI> ", os, null, + verifyCMD("set hive.cli.prompt=MYCLI;SHOW\nTABLES;", "MYCLI> ", errS, null, ERRNO_OK, true); } @@ -213,21 +213,21 @@ public void testErrOutput() { public void testUseCurrentDB1() { verifyCMD( "create database if not exists testDB; set hive.cli.print.current.db=true;use testDB;\n" - + "use default;drop if exists testDB;", "hive (testDB)>", os, null, ERRNO_OTHER, true); + + "use default;drop if exists testDB;", "hive (testDB)>", errS, null, ERRNO_OTHER, true); } @Test public void testUseCurrentDB2() { verifyCMD( "create database if not exists testDB; set hive.cli.print.current.db=true;use\ntestDB;\nuse default;drop if exists testDB;", - "hive (testDB)>", os, null, ERRNO_OTHER, true); + "hive (testDB)>", errS, null, ERRNO_OTHER, true); } @Test public void testUseCurrentDB3() { verifyCMD( "create database if not exists testDB; set hive.cli.print.current.db=true;use testDB;\n" - + "use default;drop if exists testDB;", "hive (testDB)>", os, null, ERRNO_OTHER, true); + + "use default;drop if exists testDB;", "hive (testDB)>", errS, null, ERRNO_OTHER, true); } @Test 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 75f46eca045e7d74f21ace943226fbd42c13209d..5a2584d69e2cba2b5d4f8de020eda8a263d0a4a1 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 @@ -252,7 +252,7 @@ private void testScriptFile(String scriptText, List argList, @Override public Tuple apply(Tuple tuple) { return new Tuple<>( - Pattern.compile(".*" + tuple.pattern + ".*", Pattern.DOTALL), + Pattern.compile(".*" + tuple.pattern + ".*", Pattern.DOTALL | Pattern.CASE_INSENSITIVE), tuple.shouldMatch ); } @@ -482,7 +482,7 @@ public void testNullNonEmpty() throws Throwable { public void testGetVariableValue() throws Throwable { final String SCRIPT_TEXT = "set env:TERM;"; final String EXPECTED_PATTERN = "env:TERM"; - testScriptFile(SCRIPT_TEXT, getBaseArgs(miniHS2.getBaseJdbcURL()), EXPECTED_PATTERN, true); + testScriptFile(SCRIPT_TEXT, getBaseArgs(miniHS2.getBaseJdbcURL()), OutStream.ERR, EXPECTED_PATTERN, true); } /** @@ -1003,7 +1003,7 @@ public void testConnectionWithURLParams() throws Throwable { public void testQueryNonEscapedSemiColon() throws Throwable { String SCRIPT_TEXT = "drop table if exists nonEscapedSemiColon;create table nonEscapedSemiColon " + "(key int) ROW FORMAT DELIMITED FIELDS TERMINATED BY ';';show tables;"; - final String EXPECTED_PATTERN = " nonEscapedSemiColon "; + final String EXPECTED_PATTERN = "nonEscapedSemiColon"; List argList = getBaseArgs(miniHS2.getBaseJdbcURL()); testScriptFile(SCRIPT_TEXT, argList, EXPECTED_PATTERN, true); } @@ -1032,7 +1032,7 @@ public void testShowDbInPrompt() throws Throwable { argList.add(miniHS2.getBaseJdbcURL() + ";user=hivetest;password=hive"); String SCRIPT_TEXT = "select current_user();"; - testScriptFile(SCRIPT_TEXT, argList, EXPECTED_PATTERN, true); + testScriptFile(SCRIPT_TEXT, argList, OutStream.ERR, EXPECTED_PATTERN, true); } @Test