hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From x..@apache.org
Subject hive git commit: HIVE-11579: Invoke the set command will close standard error output[beeline-cli](Ferdinand Xu, reviewed by Xuefu Zhang)
Date Thu, 20 Aug 2015 01:13:28 GMT
Repository: hive
Updated Branches:
  refs/heads/beeline-cli e28043fb4 -> 80f6184d3


HIVE-11579: Invoke the set command will close standard error output[beeline-cli](Ferdinand
Xu, reviewed by Xuefu Zhang)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/80f6184d
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/80f6184d
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/80f6184d

Branch: refs/heads/beeline-cli
Commit: 80f6184d301d94b5c203f45d0d849ea4bea054fb
Parents: e28043f
Author: Ferdinand Xu <cheng.a.xu@intel.com>
Authored: Wed Aug 19 21:12:00 2015 -0400
Committer: Ferdinand Xu <cheng.a.xu@intel.com>
Committed: Wed Aug 19 21:12:00 2015 -0400

----------------------------------------------------------------------
 .../org/apache/hive/beeline/BeeLineOpts.java    |  2 +-
 .../apache/hive/beeline/cli/TestHiveCli.java    | 12 ++++++++---
 .../hadoop/hive/ql/session/SessionState.java    | 21 ++++++++++++++++++++
 .../cli/operation/HiveCommandOperation.java     | 18 +++++++++--------
 .../service/cli/operation/SQLOperation.java     |  4 ++++
 5 files changed, 45 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/80f6184d/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java
----------------------------------------------------------------------
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 @@ class BeeLineOpts implements Completer {
   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));
     }

http://git-wip-us.apache.org/repos/asf/hive/blob/80f6184d/beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java
----------------------------------------------------------------------
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 class TestHiveCli {
 
   @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 class TestHiveCli {
 
   @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 class TestHiveCli {
     f.delete();
   }
 
+  @Test
+  public void testErrOutput() {
+    verifyCMD("show tables;set system:xxx=5;set system:yyy=${system:xxx};\nlss;",
+        "cannot recognize input near 'lss' '<EOF>' '<EOF>'", errS, null, ERRNO_OK);
+  }
+
   private void redirectOutputStream() {
     // Setup output stream to redirect output to
     os = new ByteArrayOutputStream();
@@ -200,8 +206,8 @@ public class TestHiveCli {
   @Before
   public void setup() {
     cli = new HiveCli();
-    redirectOutputStream();
     initFromFile();
+    redirectOutputStream();
   }
 
   @After

http://git-wip-us.apache.org/repos/asf/hive/blob/80f6184d/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java b/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java
index 49d64db..13ca87d 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java
@@ -161,6 +161,11 @@ public class SessionState {
   protected File tmpOutputFile;
 
   /**
+   * Temporary file name used to store error output of executing non-Hive commands (e.g.,
set, dfs)
+   */
+  protected File tmpErrOutputFile;
+
+  /**
    * type of the command.
    */
   private HiveOperation commandType;
@@ -305,6 +310,14 @@ public class SessionState {
     tmpOutputFile = f;
   }
 
+  public File getTmpErrOutputFile() {
+    return tmpErrOutputFile;
+  }
+
+  public void setTmpErrOutputFile(File tmpErrOutputFile) {
+    this.tmpErrOutputFile = tmpErrOutputFile;
+  }
+
   public boolean getIsSilent() {
     if(conf != null) {
       return conf.getBoolVar(HiveConf.ConfVars.HIVESESSIONSILENT);
@@ -525,6 +538,14 @@ public class SessionState {
         }
       }
 
+      // Set temp file containing error output to be sent to client
+      if (startSs.getTmpErrOutputFile() == null) {
+        try {
+          startSs.setTmpErrOutputFile(createTempFile(startSs.getConf()));
+        } catch (IOException e) {
+          throw new RuntimeException(e);
+        }
+      }
     } catch (Exception e) {
       // Catch-all due to some exec time dependencies on session state
       // that would cause ClassNoFoundException otherwise

http://git-wip-us.apache.org/repos/asf/hive/blob/80f6184d/service/src/java/org/apache/hive/service/cli/operation/HiveCommandOperation.java
----------------------------------------------------------------------
diff --git a/service/src/java/org/apache/hive/service/cli/operation/HiveCommandOperation.java
b/service/src/java/org/apache/hive/service/cli/operation/HiveCommandOperation.java
index bcc66cf..1d1e995 100644
--- a/service/src/java/org/apache/hive/service/cli/operation/HiveCommandOperation.java
+++ b/service/src/java/org/apache/hive/service/cli/operation/HiveCommandOperation.java
@@ -66,13 +66,14 @@ public class HiveCommandOperation extends ExecuteStatementOperation {
 
   private void setupSessionIO(SessionState sessionState) {
     try {
-      LOG.info("Putting temp output to file " + sessionState.getTmpOutputFile().toString());
+      LOG.info("Putting temp output to file " + sessionState.getTmpOutputFile().toString()
+          + " and error output to file " + sessionState.getTmpErrOutputFile().toString());
       sessionState.in = null; // hive server's session input stream is not used
-      // open a per-session file in auto-flush mode for writing temp results
-      sessionState.out = new PrintStream(new FileOutputStream(sessionState.getTmpOutputFile()),
true, "UTF-8");
-      // TODO: for hadoop jobs, progress is printed out to session.err,
-      // we should find a way to feed back job progress to client
-      sessionState.err = new PrintStream(System.err, true, "UTF-8");
+      // open a per-session file in auto-flush mode for writing temp results and tmp error
output
+      sessionState.out =
+          new PrintStream(new FileOutputStream(sessionState.getTmpOutputFile()), true, "UTF-8");
+      sessionState.err =
+          new PrintStream(new FileOutputStream(sessionState.getTmpErrOutputFile()), true,
"UTF-8");
     } catch (IOException e) {
       LOG.error("Error in creating temp output file ", e);
       try {
@@ -90,8 +91,7 @@ public class HiveCommandOperation extends ExecuteStatementOperation {
 
 
   private void tearDownSessionIO() {
-    IOUtils.cleanup(LOG, parentSession.getSessionState().out);
-    IOUtils.cleanup(LOG, parentSession.getSessionState().err);
+    IOUtils.cleanup(LOG, parentSession.getSessionState().out, parentSession.getSessionState().err);
   }
 
   @Override
@@ -202,6 +202,8 @@ public class HiveCommandOperation extends ExecuteStatementOperation {
     SessionState sessionState = getParentSession().getSessionState();
     File tmp = sessionState.getTmpOutputFile();
     tmp.delete();
+    tmp = sessionState.getTmpErrOutputFile();
+    tmp.delete();
   }
 
   private void resetResultReader() {

http://git-wip-us.apache.org/repos/asf/hive/blob/80f6184d/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
----------------------------------------------------------------------
diff --git a/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java b/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
index f4334e4..175348b 100644
--- a/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
+++ b/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
@@ -296,6 +296,10 @@ public class SQLOperation extends ExecuteStatementOperation {
     if (ss.getTmpOutputFile() != null) {
       ss.getTmpOutputFile().delete();
     }
+
+    if (ss.getTmpErrOutputFile() != null) {
+      ss.getTmpErrOutputFile().delete();
+    }
   }
 
   @Override


Mime
View raw message