hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xu...@apache.org
Subject svn commit: r1563369 - in /hive/trunk: beeline/src/java/org/apache/hive/beeline/ beeline/src/main/resources/ itests/hive-unit/src/test/java/org/apache/hive/beeline/ jdbc/src/java/org/apache/hive/jdbc/
Date Sat, 01 Feb 2014 03:15:49 GMT
Author: xuefu
Date: Sat Feb  1 03:15:47 2014
New Revision: 1563369

URL: http://svn.apache.org/r1563369
Log:
HIVE-6173: Beeline doesn't accept --hiveconf option as Hive CLI does (reviewed by Prasad)

Modified:
    hive/trunk/beeline/src/java/org/apache/hive/beeline/BeeLine.java
    hive/trunk/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java
    hive/trunk/beeline/src/java/org/apache/hive/beeline/DatabaseConnection.java
    hive/trunk/beeline/src/main/resources/BeeLine.properties
    hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java
    hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java

Modified: hive/trunk/beeline/src/java/org/apache/hive/beeline/BeeLine.java
URL: http://svn.apache.org/viewvc/hive/trunk/beeline/src/java/org/apache/hive/beeline/BeeLine.java?rev=1563369&r1=1563368&r2=1563369&view=diff
==============================================================================
--- hive/trunk/beeline/src/java/org/apache/hive/beeline/BeeLine.java (original)
+++ hive/trunk/beeline/src/java/org/apache/hive/beeline/BeeLine.java Sat Feb  1 03:15:47 2014
@@ -126,6 +126,7 @@ public class BeeLine {
   private static final int ERRNO_OTHER = 2;
 
   private static final String HIVE_VAR_PREFIX = "--hivevar";
+  private static final String HIVE_CONF_PREFIX = "--hiveconf";
 
   private final Map<Object, Object> formats = map(new Object[] {
       "vertical", new VerticalOutputFormat(this),
@@ -518,6 +519,16 @@ public class BeeLine {
         continue;
       }
 
+      // Parse hive conf variables
+      if (args[i].equals(HIVE_CONF_PREFIX)) {
+        String[] parts = split(args[++i], "=");
+        if (parts.length != 2) {
+          return false;
+        }
+        getOpts().getHiveConfVariables().put(parts[0], parts[1]);
+        continue;
+      }
+
       // -- arguments are treated as properties
       if (args[i].startsWith("--")) {
         String[] parts = split(args[i].substring(2), "=");

Modified: hive/trunk/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java
URL: http://svn.apache.org/viewvc/hive/trunk/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java?rev=1563369&r1=1563368&r2=1563369&view=diff
==============================================================================
--- hive/trunk/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java (original)
+++ hive/trunk/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java Sat Feb  1 03:15:47
2014
@@ -88,6 +88,7 @@ class BeeLineOpts implements Completor {
   private String scriptFile = null;
 
   private Map<String, String> hiveVariables = new HashMap<String, String>();
+  private Map<String, String> hiveConfVariables = new HashMap<String, String>();
 
   public BeeLineOpts(BeeLine beeLine, Properties props) {
     this.beeLine = beeLine;
@@ -464,6 +465,13 @@ class BeeLineOpts implements Completor {
     return nullEmptyString ? "" : DEFAULT_NULL_STRING;
   }
 
+  public Map<String, String> getHiveConfVariables() {
+    return hiveConfVariables;
+  }
+
+  public void setHiveConfVariables(Map<String, String> hiveConfVariables) {
+    this.hiveConfVariables = hiveConfVariables;
+  }
 
 }
 

Modified: hive/trunk/beeline/src/java/org/apache/hive/beeline/DatabaseConnection.java
URL: http://svn.apache.org/viewvc/hive/trunk/beeline/src/java/org/apache/hive/beeline/DatabaseConnection.java?rev=1563369&r1=1563368&r2=1563369&view=diff
==============================================================================
--- hive/trunk/beeline/src/java/org/apache/hive/beeline/DatabaseConnection.java (original)
+++ hive/trunk/beeline/src/java/org/apache/hive/beeline/DatabaseConnection.java Sat Feb  1
03:15:47 2014
@@ -42,6 +42,7 @@ class DatabaseConnection {
   private static final String HIVE_AUTH_USER = "user";
   private static final String HIVE_AUTH_PASSWD = "password";
   private static final String HIVE_VAR_PREFIX = "hivevar:";
+  private static final String HIVE_CONF_PREFIX = "hiveconf:";
 
   private final BeeLine beeLine;
   private Connection connection;
@@ -139,6 +140,12 @@ class DatabaseConnection {
     for (Map.Entry<String, String> var : hiveVars.entrySet()) {
       info.put(HIVE_VAR_PREFIX + var.getKey(), var.getValue());
     }
+
+    Map<String, String> hiveConfVars = beeLine.getOpts().getHiveConfVariables();
+    for (Map.Entry<String, String> var : hiveConfVars.entrySet()) {
+      info.put(HIVE_CONF_PREFIX + var.getKey(), var.getValue());
+    }
+
     setConnection(DriverManager.getConnection(getUrl(), info));
     setDatabaseMetaData(getConnection().getMetaData());
 

Modified: hive/trunk/beeline/src/main/resources/BeeLine.properties
URL: http://svn.apache.org/viewvc/hive/trunk/beeline/src/main/resources/BeeLine.properties?rev=1563369&r1=1563368&r2=1563369&view=diff
==============================================================================
--- hive/trunk/beeline/src/main/resources/BeeLine.properties (original)
+++ hive/trunk/beeline/src/main/resources/BeeLine.properties Sat Feb  1 03:15:47 2014
@@ -144,6 +144,7 @@ cmd-usage: Usage: java org.apache.hive.c
 \  -d <driver class>               the driver class to use\n \
 \  -e <query>                      query that should be executed\n \
 \  -f <file>                       script file that should be executed\n \
+\  --hiveconf property=value       Use value for given property\n \
 \  --hivevar name=value            hive variable name and value\n \
 \                                  This is Hive specific settings in which variables\n \
 \                                  can be set at session level and referenced in Hive\n \

Modified: hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java
URL: http://svn.apache.org/viewvc/hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java?rev=1563369&r1=1563368&r2=1563369&view=diff
==============================================================================
--- hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java
(original)
+++ hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java
Sat Feb  1 03:15:47 2014
@@ -221,9 +221,20 @@ public class TestBeeLineWithArgs {
     testScriptFile(TEST_NAME, SCRIPT_TEXT, EXPECTED_PATTERN, true, argList);
   }
 
+  @Test
+  public void testBeelineHiveConfVariable() throws Throwable {
+    List<String> argList = getBaseArgs(JDBC_URL);
+    argList.add("--hiveconf");
+    argList.add("hive.table.name=dummy");
+    final String TEST_NAME = "testBeelineHiveConfVariable";
+    final String SCRIPT_TEXT = "create table ${hiveconf:hive.table.name} (d int);\nshow tables;\n";
+    final String EXPECTED_PATTERN = "dummy";
+    testScriptFile(TEST_NAME, SCRIPT_TEXT, EXPECTED_PATTERN, true, argList);
+  }
+
   /**
    * Test Beeline -hivevar option. User can specify --hivevar name=value on Beeline command
line.
-   * This test defines multiple variables using repeated --hivevar flags.
+   * This test defines multiple variables using repeated --hivevar or --hiveconf flags.
    * @throws Throwable
    */
   @Test
@@ -231,13 +242,20 @@ public class TestBeeLineWithArgs {
     List<String> argList = getBaseArgs(JDBC_URL);
     argList.add("--hivevar");
     argList.add("TABLE_NAME=dummy2");
+
+    argList.add("--hiveconf");
+    argList.add("COLUMN_NAME=d");
+
     argList.add("--hivevar");
     argList.add("COMMAND=create");
     argList.add("--hivevar");
     argList.add("OBJECT=table");
 
+    argList.add("--hiveconf");
+    argList.add("COLUMN_TYPE=int");
+
     final String TEST_NAME = "testHiveCommandLineHiveVariable";
-    final String SCRIPT_TEXT = "${COMMAND} ${OBJECT} ${TABLE_NAME} (d int);\nshow tables;\n";
+    final String SCRIPT_TEXT = "${COMMAND} ${OBJECT} ${TABLE_NAME} (${hiveconf:COLUMN_NAME}
${hiveconf:COLUMN_TYPE});\nshow tables;\n";
     final String EXPECTED_PATTERN = "dummy2";
     testScriptFile(TEST_NAME, SCRIPT_TEXT, EXPECTED_PATTERN, true, argList);
   }

Modified: hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java?rev=1563369&r1=1563368&r2=1563369&view=diff
==============================================================================
--- hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java (original)
+++ hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java Sat Feb  1 03:15:47
2014
@@ -63,7 +63,6 @@ import org.apache.hive.service.cli.thrif
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.thrift.TException;
 import org.apache.thrift.protocol.TBinaryProtocol;
-import org.apache.thrift.protocol.TProtocol;
 import org.apache.thrift.transport.THttpClient;
 import org.apache.thrift.transport.TTransport;
 import org.apache.thrift.transport.TTransportException;
@@ -85,6 +84,7 @@ public class HiveConnection implements j
   private static final String HIVE_SSL_TRUST_STORE = "sslTrustStore";
   private static final String HIVE_SSL_TRUST_STORE_PASSWORD = "trustStorePassword";
   private static final String HIVE_VAR_PREFIX = "hivevar:";
+  private static final String HIVE_CONF_PREFIX = "hiveconf:";
 
   private final String jdbcURI;
   private final String host;
@@ -124,6 +124,8 @@ public class HiveConnection implements j
         String key = (String) kv.getKey();
         if (key.startsWith(HIVE_VAR_PREFIX)) {
           hiveVarMap.put(key.substring(HIVE_VAR_PREFIX.length()), info.getProperty(key));
+        } else if (key.startsWith(HIVE_CONF_PREFIX)) {
+          hiveConfMap.put(key.substring(HIVE_CONF_PREFIX.length()), info.getProperty(key));
         }
       }
     }



Mime
View raw message