hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From na...@apache.org
Subject svn commit: r1345293 - in /hive/trunk/cli/src/java/org/apache/hadoop/hive/cli: CliDriver.java CliSessionState.java OptionsProcessor.java
Date Fri, 01 Jun 2012 18:08:24 GMT
Author: namit
Date: Fri Jun  1 18:08:24 2012
New Revision: 1345293

URL: http://svn.apache.org/viewvc?rev=1345293&view=rev
Log:
HIVE-3066
Add the option -database DATABASE in hive cli to specify a default database to use for the
cli session. (herman via namit)

Modified:
    hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
    hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliSessionState.java
    hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/OptionsProcessor.java

Modified: hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
URL: http://svn.apache.org/viewvc/hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java?rev=1345293&r1=1345292&r2=1345293&view=diff
==============================================================================
--- hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java (original)
+++ hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java Fri Jun  1 18:08:24
2012
@@ -487,6 +487,16 @@ public class CliDriver {
     ss.setIsSilent(saveSilent);
   }
 
+  public void processSelectDatabase(CliSessionState ss) throws IOException {
+    String database = ss.database;
+    if (database != null) {
+      int rc = processLine("use " + database + ";");
+      if (rc != 0) {
+        System.exit(rc);
+      }
+    }
+  }
+
   public static Completor getCommandCompletor () {
     // SimpleCompletor matches against a pre-defined wordlist
     // We start with an empty wordlist and build it up
@@ -635,6 +645,9 @@ public class CliDriver {
     CliDriver cli = new CliDriver();
     cli.setHiveVariables(oproc.getHiveVariables());
 
+    // use the specified database if specified
+    cli.processSelectDatabase(ss);
+
     // Execute -i init files (always in silent mode)
     cli.processInitFiles(ss);
 

Modified: hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliSessionState.java
URL: http://svn.apache.org/viewvc/hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliSessionState.java?rev=1345293&r1=1345292&r2=1345293&view=diff
==============================================================================
--- hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliSessionState.java (original)
+++ hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliSessionState.java Fri Jun  1 18:08:24
2012
@@ -40,6 +40,11 @@ import org.apache.thrift.transport.TTran
  */
 public class CliSessionState extends SessionState {
   /**
+   * -database option if any that the session has been invoked with.
+   */
+  public String database;
+
+  /**
    * -e option if any that the session has been invoked with.
    */
   public String execString;

Modified: hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/OptionsProcessor.java
URL: http://svn.apache.org/viewvc/hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/OptionsProcessor.java?rev=1345293&r1=1345292&r2=1345293&view=diff
==============================================================================
--- hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/OptionsProcessor.java (original)
+++ hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/OptionsProcessor.java Fri Jun  1 18:08:24
2012
@@ -45,6 +45,14 @@ public class OptionsProcessor {
   @SuppressWarnings("static-access")
   public OptionsProcessor() {
 
+    // -database database
+    options.addOption(OptionBuilder
+        .hasArg()
+        .withArgName("databasename")
+        .withLongOpt("database")
+        .withDescription("Specify the database to use")
+        .create());
+
     // -e 'quoted-query-string'
     options.addOption(OptionBuilder
         .hasArg()
@@ -153,6 +161,8 @@ public class OptionsProcessor {
 
     ss.setIsSilent(commandLine.hasOption('S'));
 
+    ss.database = commandLine.getOptionValue("database");
+
     ss.execString = commandLine.getOptionValue('e');
 
     ss.fileName = commandLine.getOptionValue('f');



Mime
View raw message