You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by xu...@apache.org on 2015/10/23 01:29:37 UTC

hive git commit: HIVE-11710: Beeline embedded mode doesn't output query progress after setting any session property (Aihua via Xuefu)

Repository: hive
Updated Branches:
  refs/heads/master d6d10129e -> 3f03d2677


HIVE-11710: Beeline embedded mode doesn't output query progress after setting any session property (Aihua via Xuefu)


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

Branch: refs/heads/master
Commit: 3f03d2677d846b1221b4cd792fb42179259d1783
Parents: d6d1012
Author: Xuefu Zhang <xz...@Cloudera.com>
Authored: Thu Oct 22 16:29:32 2015 -0700
Committer: Xuefu Zhang <xz...@Cloudera.com>
Committed: Thu Oct 22 16:29:32 2015 -0700

----------------------------------------------------------------------
 .../hive/beeline/TestBeeLineWithArgs.java       | 13 +++++++++++++
 .../cli/operation/HiveCommandOperation.java     | 20 ++++++++++++++------
 .../service/cli/operation/SQLOperation.java     | 18 ++++++++++++++++++
 3 files changed, 45 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/3f03d267/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java
----------------------------------------------------------------------
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 19ee621..0465ef3 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
@@ -739,4 +739,17 @@ public class TestBeeLineWithArgs {
     final String QUERY_TEXT_DROP = "drop table multiCmdTbl;show tables;";
     testCommandEnclosedQuery(QUERY_TEXT_DROP, EXPECTED_PATTERN, false, argList);
   }
+
+  @Test
+  public void testEmbeddedBeelineOutputs() throws Throwable{
+    String embeddedJdbcURL = BeeLine.BEELINE_DEFAULT_JDBC_URL+"/Default";
+    List<String> argList = getBaseArgs(embeddedJdbcURL);
+    // Set to non-zk lock manager to avoid trying to connect to zookeeper
+    final String SCRIPT_TEXT =
+        "set hive.lock.manager=org.apache.hadoop.hive.ql.lockmgr.EmbeddedLockManager;\n" +
+        "create table if not exists embeddedBeelineOutputs(d int);\n" +
+        "set a=1;\nselect count(*) from embeddedBeelineOutputs;\n";
+    final String EXPECTED_PATTERN = "Stage-1 map =";
+    testScriptFile(SCRIPT_TEXT, EXPECTED_PATTERN, true, argList);
+  }
 }

http://git-wip-us.apache.org/repos/asf/hive/blob/3f03d267/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 c40c269..807f010 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
@@ -30,6 +30,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.lang3.CharEncoding;
 import org.apache.hadoop.hive.metastore.api.Schema;
 import org.apache.hadoop.hive.ql.processors.CommandProcessor;
 import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse;
@@ -49,6 +50,7 @@ import org.apache.hive.service.cli.session.HiveSession;
 public class HiveCommandOperation extends ExecuteStatementOperation {
   private CommandProcessor commandProcessor;
   private TableSchema resultSchema = null;
+  private boolean closeSessionStreams = true; // Only close file based streams, not System.out and System.err.
 
   /**
    * For processors other than Hive queries (Driver), they output to session.out (a temp file)
@@ -56,7 +58,6 @@ public class HiveCommandOperation extends ExecuteStatementOperation {
    */
   private BufferedReader resultReader;
 
-
   protected HiveCommandOperation(HiveSession parentSession, String statement,
       CommandProcessor commandProcessor, Map<String, String> confOverlay) {
     super(parentSession, statement, confOverlay, false);
@@ -71,15 +72,20 @@ public class HiveCommandOperation extends ExecuteStatementOperation {
       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 and tmp error output
       sessionState.out =
-          new PrintStream(new FileOutputStream(sessionState.getTmpOutputFile()), true, "UTF-8");
+          new PrintStream(new FileOutputStream(sessionState.getTmpOutputFile()), true, CharEncoding.UTF_8);
       sessionState.err =
-          new PrintStream(new FileOutputStream(sessionState.getTmpErrOutputFile()), true, "UTF-8");
+          new PrintStream(new FileOutputStream(sessionState.getTmpErrOutputFile()), true,CharEncoding.UTF_8);
     } catch (IOException e) {
       LOG.error("Error in creating temp output file ", e);
+
+      // Close file streams to avoid resource leaking
+      IOUtils.cleanup(LOG, parentSession.getSessionState().out, parentSession.getSessionState().err);
+      closeSessionStreams = false;
+
       try {
         sessionState.in = null;
-        sessionState.out = new PrintStream(System.out, true, "UTF-8");
-        sessionState.err = new PrintStream(System.err, true, "UTF-8");
+        sessionState.out = new PrintStream(System.out, true, CharEncoding.UTF_8);
+        sessionState.err = new PrintStream(System.err, true, CharEncoding.UTF_8);
       } catch (UnsupportedEncodingException ee) {
         LOG.error("Error creating PrintStream", e);
         ee.printStackTrace();
@@ -91,7 +97,9 @@ public class HiveCommandOperation extends ExecuteStatementOperation {
 
 
   private void tearDownSessionIO() {
-    IOUtils.cleanup(LOG, parentSession.getSessionState().out, parentSession.getSessionState().err);
+    if (closeSessionStreams) {
+      IOUtils.cleanup(LOG, parentSession.getSessionState().out, parentSession.getSessionState().err);
+    }
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hive/blob/3f03d267/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 e2ee388..1c798eb 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
@@ -19,6 +19,7 @@
 package org.apache.hive.service.cli.operation;
 
 import java.io.IOException;
+import java.io.PrintStream;
 import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
 import java.security.PrivilegedExceptionAction;
@@ -31,6 +32,7 @@ import java.util.concurrent.Future;
 import java.util.concurrent.RejectedExecutionException;
 
 import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.CharEncoding;
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.conf.HiveVariableSource;
 import org.apache.hadoop.hive.conf.VariableSubstitution;
@@ -81,8 +83,24 @@ public class SQLOperation extends ExecuteStatementOperation {
       String> confOverlay, boolean runInBackground) {
     // TODO: call setRemoteUser in ExecuteStatementOperation or higher.
     super(parentSession, statement, confOverlay, runInBackground);
+    setupSessionIO(parentSession.getSessionState());
   }
 
+  private void setupSessionIO(SessionState sessionState) {
+    try {
+      sessionState.in = null; // hive server's session input stream is not used
+      sessionState.out = new PrintStream(System.out, true, CharEncoding.UTF_8);
+      sessionState.info = new PrintStream(System.err, true, CharEncoding.UTF_8);
+      sessionState.err = new PrintStream(System.err, true, CharEncoding.UTF_8);
+    } catch (UnsupportedEncodingException e) {
+        LOG.error("Error creating PrintStream", e);
+        e.printStackTrace();
+        sessionState.out = null;
+        sessionState.info = null;
+        sessionState.err = null;
+      }
+    }
+
   /***
    * Compile the query and extract metadata
    * @param sqlOperationConf