You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ai...@apache.org on 2018/03/30 17:57:47 UTC

hive git commit: HIVE-19018: beeline -e now requires semicolon even when used with query from command line (Aihua Xu, reviewed by Yongzhi Chen)

Repository: hive
Updated Branches:
  refs/heads/master eea736134 -> 52290e72b


HIVE-19018: beeline -e now requires semicolon even when used with query from command line (Aihua Xu, reviewed by Yongzhi Chen)


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

Branch: refs/heads/master
Commit: 52290e72b3029eddc17f0a0482fd6c1a05840bb0
Parents: eea7361
Author: Aihua Xu <ai...@apache.org>
Authored: Wed Mar 21 17:36:50 2018 -0700
Committer: Aihua Xu <ai...@apache.org>
Committed: Fri Mar 30 10:59:02 2018 -0700

----------------------------------------------------------------------
 .../src/java/org/apache/hive/beeline/BeeLine.java   |  2 ++
 .../src/java/org/apache/hive/beeline/Commands.java  |  1 -
 .../test/org/apache/hive/beeline/TestCommands.java  | 16 ++++++++++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/52290e72/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 402fadd..c6d009c 100644
--- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java
+++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java
@@ -795,6 +795,8 @@ public class BeeLine implements Closeable {
     int code = 0;
     if (cl.getOptionValues('e') != null) {
       commands = Arrays.asList(cl.getOptionValues('e'));
+      opts.setAllowMultiLineCommand(false); //When using -e, command is always a single line
+
     }
 
     if (!commands.isEmpty() && getOpts().getScriptFile() != null) {

http://git-wip-us.apache.org/repos/asf/hive/blob/52290e72/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 d5806a4..e46c0cf 100644
--- a/beeline/src/java/org/apache/hive/beeline/Commands.java
+++ b/beeline/src/java/org/apache/hive/beeline/Commands.java
@@ -1072,7 +1072,6 @@ public class Commands {
    * Check if the input line is a multi-line command which needs to read further
    */
   public String handleMultiLineCmd(String line) throws IOException {
-    //When using -e, console reader is not initialized and command is always a single line
     int[] startQuote = {-1};
     line = HiveStringUtils.removeComments(line, startQuote);
     while (isMultiLine(line) && beeLine.getOpts().isAllowMultiLineCommand()) {

http://git-wip-us.apache.org/repos/asf/hive/blob/52290e72/beeline/src/test/org/apache/hive/beeline/TestCommands.java
----------------------------------------------------------------------
diff --git a/beeline/src/test/org/apache/hive/beeline/TestCommands.java b/beeline/src/test/org/apache/hive/beeline/TestCommands.java
index 8a51f98..567ca25 100644
--- a/beeline/src/test/org/apache/hive/beeline/TestCommands.java
+++ b/beeline/src/test/org/apache/hive/beeline/TestCommands.java
@@ -23,6 +23,8 @@ import org.junit.Test;
 import static org.apache.hive.common.util.HiveStringUtils.removeComments;
 import static org.junit.Assert.assertEquals;
 
+import java.io.IOException;
+
 public class TestCommands {
 
   @Test
@@ -43,5 +45,19 @@ public class TestCommands {
     assertEquals("'show --comments tables'", removeComments("'show --comments tables' --comments",escape));
     assertEquals("'\"show --comments tables\"'", removeComments("'\"show --comments tables\"' --comments",escape));
   }
+
+  /**
+   * Test the commands directly call from beeline.
+   * @throws IOException
+   */
+  @Test
+  public void testBeelineCommands() throws IOException {
+ // avoid System.exit() call in beeline which causes JVM to exit and fails the test
+    System.setProperty(BeeLineOpts.PROPERTY_NAME_EXIT, "true");
+    // Verify the command without ';' at the end also works fine
+    BeeLine.mainWithInputRedirection(new String[] {"-u", "jdbc:hive2://", "-e", "select 3"}, null);
+    BeeLine.mainWithInputRedirection(
+        new String[] {"-u", "jdbc:hive2://", "-e", "create table t1(x int); show tables"}, null);
+  }
 }