hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xu...@apache.org
Subject svn commit: r1562973 - in /hive/trunk: beeline/src/java/org/apache/hive/beeline/DatabaseConnection.java jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
Date Thu, 30 Jan 2014 21:25:48 GMT
Author: xuefu
Date: Thu Jan 30 21:25:47 2014
New Revision: 1562973

URL: http://svn.apache.org/r1562973
Log:
HIVE-6217: Refactor Beeline's JDBC connection to use property map instead of long url (reviewed
by Prasad)

Modified:
    hive/trunk/beeline/src/java/org/apache/hive/beeline/DatabaseConnection.java
    hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java

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=1562973&r1=1562972&r2=1562973&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 Thu Jan 30
21:25:47 2014
@@ -28,10 +28,10 @@ import java.sql.DatabaseMetaData;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 import java.util.TreeSet;
 
@@ -39,6 +39,10 @@ import jline.ArgumentCompletor;
 import jline.Completor;
 
 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 final BeeLine beeLine;
   private Connection connection;
   private DatabaseMetaData meta;
@@ -56,38 +60,9 @@ class DatabaseConnection {
     this.driver = driver;
     this.username = username;
     this.password = password;
-    this.url = appendHiveVariables(beeLine, url);
+    this.url = url;
   }
 
-/**
- * Append hive variables specified on the command line to the connection url
- * (after #). They will be set later on the session on the server side.
- */
-  private static String appendHiveVariables(BeeLine beeLine, String url) {
-    StringBuilder sb = new StringBuilder( url );
-    Map<String, String> hiveVars = beeLine.getOpts().getHiveVariables();
-    if (hiveVars.size() > 0) {
-      if (url.indexOf("#") == -1) {
-        sb.append("#");
-      } else {
-        sb.append(";");
-      }
-      Set<Map.Entry<String, String>> vars = hiveVars.entrySet();
-      Iterator<Map.Entry<String, String>> it = vars.iterator();
-      while (it.hasNext()) {
-        Map.Entry<String, String> var = it.next();
-        sb.append(var.getKey());
-        sb.append("=");
-        sb.append(var.getValue());
-        if (it.hasNext()) {
-          sb.append(";");
-        }
-      }
-    }
-    return sb.toString();
-  }
-
-
   @Override
   public String toString() {
     return getUrl() + "";
@@ -157,7 +132,14 @@ class DatabaseConnection {
       return beeLine.error(e);
     }
 
-    setConnection(DriverManager.getConnection(getUrl(), username, password));
+    Properties info = new Properties();
+    info.put(HIVE_AUTH_USER, username);
+    info.put(HIVE_AUTH_PASSWD, password);
+    Map<String, String> hiveVars = beeLine.getOpts().getHiveVariables();
+    for (Map.Entry<String, String> var : hiveVars.entrySet()) {
+      info.put(HIVE_VAR_PREFIX + var.getKey(), var.getValue());
+    }
+    setConnection(DriverManager.getConnection(getUrl(), info));
     setDatabaseMetaData(getConnection().getMetaData());
 
     try {

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=1562973&r1=1562972&r2=1562973&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 Thu Jan 30 21:25:47
2014
@@ -84,6 +84,7 @@ public class HiveConnection implements j
   private static final String HIVE_USE_SSL = "ssl";
   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 final String jdbcURI;
   private final String host;
@@ -116,7 +117,17 @@ public class HiveConnection implements j
     port = connParams.getPort();
     sessConfMap = connParams.getSessionVars();
     hiveConfMap = connParams.getHiveConfs();
+
     hiveVarMap = connParams.getHiveVars();
+    for (Map.Entry<Object, Object> kv : info.entrySet()) {
+      if ((kv.getKey() instanceof String)) {
+        String key = (String) kv.getKey();
+        if (key.startsWith(HIVE_VAR_PREFIX)) {
+          hiveVarMap.put(key.substring(HIVE_VAR_PREFIX.length()), info.getProperty(key));
+        }
+      }
+    }
+
     isEmbeddedMode = connParams.isEmbeddedMode();
 
     if (isEmbeddedMode) {



Mime
View raw message