Skip to content

Commit

Permalink
set hive jdbc connection loginTimeout ,fixed the hive connection time…
Browse files Browse the repository at this point in the history
…out error
  • Loading branch information
awol2005ex committed Nov 11, 2024
1 parent 6f33396 commit a1b83cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@
import org.slf4j.LoggerFactory;

import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -58,6 +53,7 @@ public final class DBUtil
{
private static final Logger LOG = LoggerFactory.getLogger(DBUtil.class);
private static final int DEFAULT_SOCKET_TIMEOUT_SEC = 20_000;
private static final int DEFAULT_LOGIN_TIMEOUT_SEC = 1000;

private static final ThreadLocal<ExecutorService> rsExecutors = ThreadLocal.withInitial(() -> Executors.newFixedThreadPool(1, new ThreadFactoryBuilder()
.setNameFormat("rsExecutors-%d")
Expand Down Expand Up @@ -245,6 +241,11 @@ private static synchronized Connection connect(DataBaseType dataBaseType, String
bds.setDriverClassName("org.apache.hive.jdbc.HiveDriver");
}
else {
if("org.apache.hive.jdbc.HiveDriver".equals(bds.getDriverClassName())){
DriverManager.setLoginTimeout(DEFAULT_LOGIN_TIMEOUT_SEC);
}


LOG.debug("Connecting to database with driver {}", dataBaseType.getDriverClassName());
bds.setDriverClassName(dataBaseType.getDriverClassName());
}
Expand Down
4 changes: 2 additions & 2 deletions plugin/reader/hivereader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<packaging>jar</packaging>

<properties>
<hadoop.version>2.7.5</hadoop.version>
<hive.jdbc.version>2.1.1</hive.jdbc.version>
<hadoop.version>3.2.4</hadoop.version>
<hive.jdbc.version>3.1.3</hive.jdbc.version>
<curator.version>4.2.0</curator.version>
</properties>

Expand Down

0 comments on commit a1b83cd

Please sign in to comment.