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/09/28 03:10:34 UTC

[14/33] hive git commit: HIVE-11226 BeeLine-Cli: support hive.cli.prompt in new CLI (Ferdinand Xu, reviewed by Xuefu Zhang)

HIVE-11226 BeeLine-Cli: support hive.cli.prompt in new 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/0ac8f6c4
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/0ac8f6c4
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/0ac8f6c4

Branch: refs/heads/master
Commit: 0ac8f6c485f84c2d306ef8cac97d5ea8b542477d
Parents: 30aa155
Author: Ferdinand Xu <ch...@intel.com>
Authored: Mon Jul 13 21:51:32 2015 -0400
Committer: Ferdinand Xu <ch...@intel.com>
Committed: Mon Jul 13 21:51:32 2015 -0400

----------------------------------------------------------------------
 .../java/org/apache/hive/beeline/BeeLine.java   | 25 ++++++++++++++++----
 .../org/apache/hive/beeline/BeeLineOpts.java    |  6 ++++-
 .../java/org/apache/hive/beeline/Commands.java  | 11 ++++++++-
 .../apache/hive/beeline/cli/TestHiveCli.java    |  8 ++++++-
 4 files changed, 43 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/0ac8f6c4/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 5a22956..d2b8590 100644
--- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java
+++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java
@@ -87,6 +87,7 @@ import org.apache.commons.cli.GnuParser;
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
+import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.io.IOUtils;
 import org.apache.hive.beeline.cli.CliOptionsProcessor;
 import org.apache.hive.jdbc.Utils;
@@ -1082,7 +1083,7 @@ public class BeeLine implements Closeable {
       boolean needsUpdate = isConfNeedsUpdate(line);
       boolean res = commands.sql(line, getOpts().getEntireLineAsCommand());
       if (needsUpdate) {
-        getOpts().setHiveConf(getCommands().getHiveConf(true));
+        getOpts().setHiveConf(getCommands().getHiveConf(false));
       }
       return res;
     }
@@ -1354,19 +1355,35 @@ public class BeeLine implements Closeable {
     }
   }
 
-
   String getPrompt() {
+    if (isBeeLine) {
+      return getPromptForBeeline();
+    } else {
+      return getPromptForCli();
+    }
+  }
+
+  String getPromptForCli() {
+    String prompt;
+    // read prompt configuration and substitute variables.
+    HiveConf conf = getCommands().getHiveConf(true);
+    prompt = conf.getVar(HiveConf.ConfVars.CLIPROMPT);
+    prompt = getCommands().substituteVariables(conf, prompt);
+    return prompt + "> ";
+  }
+
+  String getPromptForBeeline() {
     if (getDatabaseConnection() == null || getDatabaseConnection().getUrl() == null) {
       return "beeline> ";
     } else {
       String printClosed = getDatabaseConnection().isClosed() ? " (closed)" : "";
-      return getPrompt(getDatabaseConnections().getIndex()
+      return getPromptForBeeline(getDatabaseConnections().getIndex()
           + ": " + getDatabaseConnection().getUrl()) + printClosed + "> ";
     }
   }
 
 
-  static String getPrompt(String url) {
+  static String getPromptForBeeline(String url) {
     if (url == null || url.length() == 0) {
       url = "beeline";
     }

http://git-wip-us.apache.org/repos/asf/hive/blob/0ac8f6c4/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 894f74f..0a86c24 100644
--- a/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java
+++ b/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java
@@ -117,7 +117,7 @@ class BeeLineOpts implements Completer {
 
   public String[] possibleSettingValues() {
     List<String> vals = new LinkedList<String>();
-    vals.addAll(Arrays.asList(new String[] {"yes", "no"}));
+    vals.addAll(Arrays.asList(new String[] { "yes", "no" }));
     return vals.toArray(new String[vals.size()]);
   }
 
@@ -538,5 +538,9 @@ class BeeLineOpts implements Completer {
   public void setDelimiterForDSV(char delimiterForDSV) {
     this.delimiterForDSV = delimiterForDSV;
   }
+
+  public HiveConf getConf() {
+    return conf;
+  }
 }
 

http://git-wip-us.apache.org/repos/asf/hive/blob/0ac8f6c4/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 b07388a..8c406a3 100644
--- a/beeline/src/java/org/apache/hive/beeline/Commands.java
+++ b/beeline/src/java/org/apache/hive/beeline/Commands.java
@@ -737,6 +737,15 @@ public class Commands {
    * @return the hive configuration from server side
    */
   public HiveConf getHiveConf(boolean call) {
+    HiveConf hiveConf = beeLine.getOpts().getConf();
+    if (hiveConf != null && call) {
+      return hiveConf;
+    } else {
+      return getHiveConfHelper(call);
+    }
+  }
+
+  public HiveConf getHiveConfHelper(boolean call) {
     HiveConf conf = new HiveConf();
     BufferedRows rows = getConfInternal(call);
     while (rows != null && rows.hasNext()) {
@@ -1015,7 +1024,7 @@ public class Commands {
     return execute(line, false, entireLineAsCommand);
   }
 
-  private String substituteVariables(HiveConf conf, String line) {
+  public String substituteVariables(HiveConf conf, String line) {
     if (!beeLine.isBeeLine()) {
       // Substitution is only supported in non-beeline mode.
       return new VariableSubstitution(new HiveVariableSource() {

http://git-wip-us.apache.org/repos/asf/hive/blob/0ac8f6c4/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 ed4e7c6..542f1ee 100644
--- a/beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java
+++ b/beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java
@@ -78,7 +78,8 @@ public class TestHiveCli {
       int retCode) {
     executeCMD(options, CMD, retCode);
     String output = os.toString();
-    Assert.assertTrue("The expected keyword doesn't occur in the output: " + output,
+    LOG.debug(output);
+    Assert.assertTrue("The expected keyword " + keywords + "doesn't occur in the output: " + output,
         output.contains(keywords));
   }
 
@@ -88,6 +89,11 @@ public class TestHiveCli {
   }
 
   @Test
+  public void testSetPromptValue() {
+    verifyCMD("set hive.cli.prompt=MYCLI;SHOW\nTABLES;", "MYCLI> ", os, null, ERRNO_OK);
+  }
+
+  @Test
   public void testHelp() {
     verifyCMD(null, "usage: hive", os, new String[] { "-H" }, ERRNO_ARGS);
   }