You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by sp...@apache.org on 2016/09/28 21:18:09 UTC

[3/4] hive git commit: HIVE-14538: beeline throws exceptions with parsing hive config when using !sh statement (Yongzhi Chen, reviewed by Chaoyu Tang)

HIVE-14538: beeline throws exceptions with parsing hive config when using !sh statement (Yongzhi Chen, reviewed by Chaoyu Tang)


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

Branch: refs/heads/branch-2.1
Commit: a8e101bbda99b92b8d62a3bbb8d6d56bf00bcce0
Parents: fc902ff
Author: Sergio Pena <se...@cloudera.com>
Authored: Wed Sep 28 16:07:59 2016 -0500
Committer: Sergio Pena <se...@cloudera.com>
Committed: Wed Sep 28 16:07:59 2016 -0500

----------------------------------------------------------------------
 .../java/org/apache/hive/beeline/Commands.java  | 36 +++++++++++++-------
 .../hive/beeline/TestBeeLineWithArgs.java       |  8 +++++
 2 files changed, 31 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/a8e101bb/beeline/src/java/org/apache/hive/beeline/Commands.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/Commands.java b/beeline/src/java/org/apache/hive/beeline/Commands.java
index 3a204c0..7160788 100644
--- a/beeline/src/java/org/apache/hive/beeline/Commands.java
+++ b/beeline/src/java/org/apache/hive/beeline/Commands.java
@@ -742,10 +742,12 @@ public class Commands {
   private Map<String, String> getHiveVariables() {
     Map<String, String> result = new HashMap<>();
     BufferedRows rows = getConfInternal(true);
-    while (rows.hasNext()) {
-      Rows.Row row = (Rows.Row) rows.next();
-      if (!row.isMeta) {
-        result.put(row.values[0], row.values[1]);
+    if (rows != null) {
+      while (rows.hasNext()) {
+        Rows.Row row = (Rows.Row) rows.next();
+        if (!row.isMeta) {
+          result.put(row.values[0], row.values[1]);
+        }
       }
     }
     return result;
@@ -784,13 +786,19 @@ public class Commands {
     Statement stmnt = null;
     BufferedRows rows = null;
     try {
-      boolean hasResults;
-      if (call) {
-        stmnt = beeLine.getDatabaseConnection().getConnection().prepareCall("set");
-        hasResults = ((CallableStatement) stmnt).execute();
-      } else {
-        stmnt = beeLine.createStatement();
-        hasResults = stmnt.execute("set");
+      boolean hasResults = false;
+      DatabaseConnection dbconn = beeLine.getDatabaseConnection();
+      Connection conn = null;
+      if (dbconn != null)
+        conn = dbconn.getConnection();
+      if (conn != null) {
+        if (call) {
+          stmnt = conn.prepareCall("set");
+          hasResults = ((CallableStatement) stmnt).execute();
+        } else {
+          stmnt = beeLine.createStatement();
+          hasResults = stmnt.execute("set");
+        }
       }
       if (hasResults) {
         ResultSet rs = stmnt.getResultSet();
@@ -823,7 +831,8 @@ public class Commands {
       return;
     } else {
       String[] kv = val.split("=", 2);
-      hiveConf.set(kv[0], kv[1]);
+      if (kv.length == 2)
+        hiveConf.set(kv[0], kv[1]);
     }
   }
 
@@ -1088,7 +1097,8 @@ public class Commands {
     }
 
     line = line.substring("sh".length()).trim();
-    line = substituteVariables(getHiveConf(false), line.trim());
+    if (!beeLine.isBeeLine())
+      line = substituteVariables(getHiveConf(false), line.trim());
 
     try {
       ShellCmdExecutor executor = new ShellCmdExecutor(line, beeLine.getOutputStream(),

http://git-wip-us.apache.org/repos/asf/hive/blob/a8e101bb/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 ae68f62..9159957 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
@@ -864,4 +864,12 @@ public class TestBeeLineWithArgs {
 
     testScriptFile( SCRIPT_TEXT, EXPECTED_PATTERN, true, argList);
   }
+
+  @Test
+  public void testBeelineShellCommandWithoutConn() throws Throwable {
+    List<String> argList = new ArrayList<String>();
+    final String SCRIPT_TEXT = "!sh echo hello world";
+    final String EXPECTED_PATTERN = "hello world";
+    testScriptFile(SCRIPT_TEXT, EXPECTED_PATTERN, true, argList,true,false);
+  }
 }