commit db8c18a503cec21fdc4a0e02c8fd7262a67a65bd 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..983db484faf607b6f5505b518d724e7b2d215d29 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 @@ -439,7 +439,8 @@ public void testTabInScriptFile() throws Throwable { final String SCRIPT_TEXT = "CREATE\tTABLE IF NOT EXISTS testTabInScriptFile\n(id\tint);\nSHOW TABLES;" + "\ndrop table testTabInScriptFile"; final String EXPECTED_PATTERN = "testTabInScriptFile"; - testScriptFile(SCRIPT_TEXT, argList, EXPECTED_PATTERN, true); + testScriptFile(SCRIPT_TEXT, argList, OutStream.ERR, EXPECTED_PATTERN, true); + testScriptFile(SCRIPT_TEXT, argList, OutStream.OUT, EXPECTED_PATTERN, false); } @Test @@ -482,7 +483,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); } /** @@ -1002,10 +1003,15 @@ public void testConnectionWithURLParams() throws Throwable { @Test 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 "; + + "(key int, value int) ROW FORMAT DELIMITED FIELDS TERMINATED BY ';';show tables;"; + String EXPECTED_PATTERN = "nonescapedsemicolon"; List argList = getBaseArgs(miniHS2.getBaseJdbcURL()); testScriptFile(SCRIPT_TEXT, argList, EXPECTED_PATTERN, true); + //look for the " nonEscapedSemiColon " in the query text not the table name which comes + //in the result + EXPECTED_PATTERN = " nonEscapedSemiColon "; + testScriptFile(SCRIPT_TEXT, argList, OutStream.ERR, EXPECTED_PATTERN, true); + testScriptFile(SCRIPT_TEXT, argList, OutStream.OUT, EXPECTED_PATTERN, false); } @Test @@ -1032,7 +1038,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