diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java b/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java index d9f726d..72e9037 100644 --- a/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java +++ b/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java @@ -228,7 +228,7 @@ public void load(InputStream fin) throws IOException { public void updateBeeLineOptsFromConf() { if (!beeLine.isBeeLine()) { if (conf == null) { - conf = beeLine.getCommands().getHiveConf(true); + conf = beeLine.getCommands().getHiveConf(false); } setForce(HiveConf.getBoolVar(conf, HiveConf.ConfVars.CLIIGNOREERRORS)); } diff --git a/beeline/src/java/org/apache/hive/beeline/Commands.java b/beeline/src/java/org/apache/hive/beeline/Commands.java index 01349e2..0860db7 100644 --- a/beeline/src/java/org/apache/hive/beeline/Commands.java +++ b/beeline/src/java/org/apache/hive/beeline/Commands.java @@ -58,6 +58,7 @@ import java.util.TreeSet; import org.apache.hadoop.hive.common.cli.ShellCmdExecutor; +import org.apache.hive.jdbc.HiveConnection; import org.apache.hive.jdbc.HiveStatement; @@ -783,7 +784,7 @@ private BufferedRows getConfInternal(boolean call) { } finally { if (stmnt != null) { try { - stmnt.close(); + closeStatementIfNeeded(stmnt); } catch (SQLException e1) { beeLine.error(e1); } @@ -981,7 +982,7 @@ private boolean executeInternal(String sql, boolean call) { showRemainingLogsIfAny(stmnt); } if (stmnt != null) { - stmnt.close(); + closeStatementIfNeeded(stmnt); } } } catch (Exception e) { @@ -991,6 +992,22 @@ private boolean executeInternal(String sql, boolean call) { return true; } + /** + * The close operation will close the standard error outputstream for embeded connection, + * We should not close it in this mode. FIX for HIVE-11579 + * + * @param stmnt + * @throws SQLException + */ + public void closeStatementIfNeeded(Statement stmnt) throws SQLException { + if (beeLine.getDatabaseConnection().getConnection() instanceof HiveConnection + && ((HiveConnection) beeLine.getDatabaseConnection().getConnection()).isEmbeddedMode()) { + return; + } else { + stmnt.close(); + } + } + public String handleMultiLineCmd(String line) throws IOException { //When using -e, console reader is not initialized and command is a single line while (beeLine.getConsoleReader() != null && !(line.trim().endsWith(";")) && beeLine.getOpts() diff --git a/beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java b/beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java index c465eac..c7eaa8e 100644 --- a/beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java +++ b/beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java @@ -107,7 +107,7 @@ public void testInvalidDatabaseOptions() { @Test public void testDatabaseOptions() { - verifyCMD("\nshow tables;\nquit;", "testTbl", os, new String[] { "--database", "test" }, + verifyCMD("\nshow tables;\nquit;", "testtbl", os, new String[] { "--database", "test" }, ERRNO_OK); } @@ -134,7 +134,7 @@ public void testSqlFromCmd() { @Test public void testSqlFromCmdWithDBName() { - verifyCMD(null, "testTbl", os, new String[] { "-e", "show tables;", "--database", "test" }, + verifyCMD(null, "testtbl", os, new String[] { "-e", "show tables;", "--database", "test" }, ERRNO_OK); } @@ -164,6 +164,12 @@ public void testVariablesForSource() { f.delete(); } + @Test + public void testErrOutput() { + verifyCMD("show tables;set system:xxx=5;set system:yyy=${system:xxx};\nlss;", + "cannot recognize input near 'lss' '' ''", errS, null, ERRNO_OK); + } + private void redirectOutputStream() { // Setup output stream to redirect output to os = new ByteArrayOutputStream(); @@ -200,8 +206,8 @@ private File generateTmpFile(String context) { @Before public void setup() { cli = new HiveCli(); - redirectOutputStream(); initFromFile(); + redirectOutputStream(); } @After diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java b/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java index 959822e..4245549 100644 --- a/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java +++ b/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java @@ -1034,7 +1034,11 @@ public boolean isValid(int timeout) throws SQLException { throw new SQLException("Method not supported"); } - /* + public boolean isEmbeddedMode() { + return isEmbeddedMode; + } + +/* * (non-Javadoc) * * @see java.sql.Connection#nativeSQL(java.lang.String)