hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ct...@apache.org
Subject [2/2] hive git commit: HIVE-15626: beeline should not exit after canceling the query on ctrl-c (Vihang Karajgaonkar via Chaoyu Tang)
Date Wed, 08 Feb 2017 14:59:00 GMT
HIVE-15626: beeline should not exit after canceling the query on ctrl-c (Vihang Karajgaonkar
via Chaoyu Tang)


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

Branch: refs/heads/master
Commit: 8a06b9e6eca81a08ee4631b60bbbee0a557d2624
Parents: d63d98f
Author: Chaoyu Tang <ctang@cloudera.com>
Authored: Wed Feb 8 09:55:21 2017 -0500
Committer: Chaoyu Tang <ctang@cloudera.com>
Committed: Wed Feb 8 09:55:21 2017 -0500

----------------------------------------------------------------------
 beeline/src/java/org/apache/hive/beeline/BeeLine.java  |  3 ++-
 .../org/apache/hive/beeline/BeeLineSignalHandler.java  |  1 -
 .../java/org/apache/hive/beeline/SunSignalHandler.java | 13 +++++++++++--
 beeline/src/main/resources/BeeLine.properties          |  1 +
 4 files changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/8a06b9e6/beeline/src/java/org/apache/hive/beeline/BeeLine.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLine.java b/beeline/src/java/org/apache/hive/beeline/BeeLine.java
index 65818dd..abeff02 100644
--- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java
+++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java
@@ -123,7 +123,7 @@ import org.apache.hive.jdbc.Utils.JdbcConnectionParams;
 public class BeeLine implements Closeable {
   private static final ResourceBundle resourceBundle =
       ResourceBundle.getBundle(BeeLine.class.getSimpleName());
-  private final BeeLineSignalHandler signalHandler = null;
+  private final BeeLineSignalHandler signalHandler;
   private static final String separator = System.getProperty("line.separator");
   private boolean exit = false;
   private final DatabaseConnections connections = new DatabaseConnections();
@@ -531,6 +531,7 @@ public class BeeLine implements Closeable {
 
   public BeeLine(boolean isBeeLine) {
     this.isBeeLine = isBeeLine;
+    this.signalHandler = new SunSignalHandler(this);
   }
 
   DatabaseConnection getDatabaseConnection() {

http://git-wip-us.apache.org/repos/asf/hive/blob/8a06b9e6/beeline/src/java/org/apache/hive/beeline/BeeLineSignalHandler.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLineSignalHandler.java b/beeline/src/java/org/apache/hive/beeline/BeeLineSignalHandler.java
index 378f1b0..7555109 100644
--- a/beeline/src/java/org/apache/hive/beeline/BeeLineSignalHandler.java
+++ b/beeline/src/java/org/apache/hive/beeline/BeeLineSignalHandler.java
@@ -25,7 +25,6 @@ package org.apache.hive.beeline;
 
 import java.sql.Statement;
 
-
 /**
  * BeeLineSignalHandler.
  *

http://git-wip-us.apache.org/repos/asf/hive/blob/8a06b9e6/beeline/src/java/org/apache/hive/beeline/SunSignalHandler.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/SunSignalHandler.java b/beeline/src/java/org/apache/hive/beeline/SunSignalHandler.java
index 8d4097e..3fb9397 100644
--- a/beeline/src/java/org/apache/hive/beeline/SunSignalHandler.java
+++ b/beeline/src/java/org/apache/hive/beeline/SunSignalHandler.java
@@ -30,20 +30,29 @@ import sun.misc.SignalHandler;
 
 public class SunSignalHandler implements BeeLineSignalHandler, SignalHandler {
   private Statement stmt = null;
+  private final BeeLine beeLine;
 
-  SunSignalHandler () {
+  SunSignalHandler (BeeLine beeLine) {
+    this.beeLine = beeLine;
     // Interpret Ctrl+C as a request to cancel the currently
     // executing query.
     Signal.handle (new Signal ("INT"), this);
   }
 
+  @Override
   public void setStatement(Statement stmt) {
     this.stmt = stmt;
   }
 
+  @Override
   public void handle (Signal signal) {
     try {
-      if (stmt != null) {
+      // exit the JVM if Ctrl+C is received
+      // and no current statement is executing
+      if(stmt == null || stmt.isClosed()) {
+        System.exit(127);
+      } else {
+        beeLine.info(beeLine.loc("interrupt-ctrl-c"));
         stmt.cancel();
       }
     } catch (SQLException ex) {

http://git-wip-us.apache.org/repos/asf/hive/blob/8a06b9e6/beeline/src/main/resources/BeeLine.properties
----------------------------------------------------------------------
diff --git a/beeline/src/main/resources/BeeLine.properties b/beeline/src/main/resources/BeeLine.properties
index 141f0c6..af86284 100644
--- a/beeline/src/main/resources/BeeLine.properties
+++ b/beeline/src/main/resources/BeeLine.properties
@@ -151,6 +151,7 @@ server URI and if the URI is correct, then ask the administrator to check
the se
 hs2-connection-timed-out: Connection timeout when communicating with HS2 server.
 hs2-unknown-connection-problem: Unknown HS2 problem when communicating with Thrift server.
 hs2-unexpected-error: Unexpected HS2 error when communicating with the Thrift server.
+interrupt-ctrl-c: Interrupting... Please be patient this may take some time.
 
 
 cmd-usage: Usage: java org.apache.hive.cli.beeline.BeeLine \n \


Mime
View raw message