This is an automated email from the ASF dual-hosted git repository.

dengzh pushed a commit to branch branch-3
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/branch-3 by this push:
     new d1b1479126d HIVE-27619: Backport of HIVE-12371: Adding a timeout 
connection parameter for JDBC (#1611) (#4599)
d1b1479126d is described below

commit d1b1479126d55f852128a722dfde4302599d3728
Author: Aman Raj <[email protected]>
AuthorDate: Thu Aug 17 15:48:47 2023 +0530

    HIVE-27619: Backport of HIVE-12371: Adding a timeout connection parameter 
for JDBC (#1611) (#4599)
---
 jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java | 14 +++++++++++---
 jdbc/src/java/org/apache/hive/jdbc/Utils.java          |  2 ++
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java 
b/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
index cf1d29debb9..98448bb8201 100644
--- a/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
+++ b/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
@@ -163,7 +163,6 @@ public class HiveConnection implements java.sql.Connection {
   }
 
   public HiveConnection(String uri, Properties info) throws SQLException {
-    setupLoginTimeout();
     try {
       connParams = Utils.parseURL(uri, info);
     } catch (ZooKeeperHiveClientException e) {
@@ -176,6 +175,7 @@ public class HiveConnection implements java.sql.Connection {
     // hive_conf_list -> hiveConfMap
     // hive_var_list -> hiveVarMap
     sessConfMap = connParams.getSessionVars();
+    setupLoginTimeout();
     if (isKerberosAuthMode()) {
       host = Utils.getCanonicalHostName(connParams.getHost());
     } else {
@@ -825,11 +825,19 @@ public class HiveConnection implements 
java.sql.Connection {
     return varValue;
   }
 
-  // copy loginTimeout from driver manager. Thrift timeout needs to be in 
millis
+  // use socketTimeout from jdbc connection url. Thrift timeout needs to be in 
millis
   private void setupLoginTimeout() {
-    long timeOut = TimeUnit.SECONDS.toMillis(DriverManager.getLoginTimeout());
+    String socketTimeoutStr = 
sessConfMap.getOrDefault(JdbcConnectionParams.SOCKET_TIMEOUT, "0");
+    long timeOut = 0;
+    try {
+      timeOut = Long.parseLong(socketTimeoutStr);
+    } catch (NumberFormatException e) {
+      LOG.info("Failed to parse socketTimeout of value " + socketTimeoutStr);
+    }
     if (timeOut > Integer.MAX_VALUE) {
       loginTimeout = Integer.MAX_VALUE;
+    } else if (timeOut < 0) {
+      loginTimeout = 0;
     } else {
       loginTimeout = (int) timeOut;
     }
diff --git a/jdbc/src/java/org/apache/hive/jdbc/Utils.java 
b/jdbc/src/java/org/apache/hive/jdbc/Utils.java
index 881c1d958e4..324776d3d5a 100644
--- a/jdbc/src/java/org/apache/hive/jdbc/Utils.java
+++ b/jdbc/src/java/org/apache/hive/jdbc/Utils.java
@@ -134,6 +134,8 @@ public class Utils {
     // Cookie prefix
     static final String HTTP_COOKIE_PREFIX = "http.cookie.";
 
+    public static final String SOCKET_TIMEOUT = "socketTimeout";
+
     // We support ways to specify application name modeled after some existing 
DBs, since
     // there's no standard approach.
     // MSSQL: applicationName 
https://docs.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url

Reply via email to