I am trying to connect to Hive, although login is successful I am getting the following error:
java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://server.domain.com:10000/default;principal=hive/server@CORPDEV.DOMAIN.COM;auth-kerberos?hive.mapred.mode=nonstrict: Could not establish connection to jdbc:hive2://server.domain.com:10000/default;principal=hive/server@CORPDEV.DOMAIN.COM;auth-kerberos?hive.mapred.mode=nonstrict: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null, configuration:{set:hiveconf:hive.mapred.mode=nonstrict, set:hiveconf:hive.server2.thrift.resultset.default.fetch.size=1000, use:database=default})
at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:224)
at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:107)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at com.hive.util.JdbcClient.getConnection(JdbcClient.java:29)
at com.hive.util.JdbcClient.getResultSet(JdbcClient.java:151)
at com.hive.dbwrapper.HiveWrapper.getResultset(HiveWrapper.java:195)
at com.hive.Application.main(Application.java:24)
Caused by: java.sql.SQLException: Could not establish connection to jdbc:hive2://server.domain.com:10000/default;principal=hive/server@CORPDEV.DOMAIN.COM;auth-kerberos?hive.mapred.mode=nonstrict: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null, configuration:{set:hiveconf:hive.mapred.mode=nonstrict, set:hiveconf:hive.server2.thrift.resultset.default.fetch.size=1000, use:database=default})
at org.apache.hive.jdbc.HiveConnection.openSession(HiveConnection.java:699)
at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:200)
... 7 more
Caused by: org.apache.thrift.TApplicationException: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null, configuration:{set:hiveconf:hive.mapred.mode=nonstrict, set:hiveconf:hive.server2.thrift.resultset.default.fetch.size=1000, use:database=default})
at org.apache.thrift.TApplicationException.read(TApplicationException.java:111)
at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:79)
at org.apache.hive.service.rpc.thrift.TCLIService$Client.recv_OpenSession(TCLIService.java:168)
at org.apache.hive.service.rpc.thrift.TCLIService$Client.OpenSession(TCLIService.java:155)
at org.apache.hive.jdbc.HiveConnection.openSession(HiveConnection.java:680)
... 8 more
Exception in thread "main" java.lang.NullPointerException
at com.hive.Application.main(Application.java:25)
2020-12-03 15:18:33.860 ERROR 14297 --- [ main] org.apache.hive.jdbc.HiveConnection : Error opening session
org.apache.thrift.TApplicationException: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null, configuration:{set:hiveconf:hive.mapred.mode=nonstrict, set:hiveconf:hive.server2.thrift.resultset.default.fetch.size=1000, use:database=default})
at org.apache.thrift.TApplicationException.read(TApplicationException.java:111) ~[libthrift-0.9.3.jar:0.9.3]
at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:79) ~[libthrift-0.9.3.jar:0.9.3]
at org.apache.hive.service.rpc.thrift.TCLIService$Client.recv_OpenSession(TCLIService.java:168) ~[hive-service-rpc-2.3.0.jar:2.3.0]
at org.apache.hive.service.rpc.thrift.TCLIService$Client.OpenSession(TCLIService.java:155) ~[hive-service-rpc-2.3.0.jar:2.3.0]
at org.apache.hive.jdbc.HiveConnection.openSession(HiveConnection.java:680) [hive-jdbc-2.3.0.jar:2.3.0]
at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:200) [hive-jdbc-2.3.0.jar:2.3.0]
at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:107) [hive-jdbc-2.3.0.jar:2.3.0]
at java.sql.DriverManager.getConnection(DriverManager.java:664) [na:1.8.0_161]
at java.sql.DriverManager.getConnection(DriverManager.java:208) [na:1.8.0_161]
at com.hive.util.JdbcClient.getConnection(JdbcClient.java:29) [classes/:na]
at com.hive.util.JdbcClient.getResultSet(JdbcClient.java:151) [classes/:na]
at com.hive.dbwrapper.HiveWrapper.getResultset(HiveWrapper.java:195) [classes/:na]
at com.hive.Application.main(Application.java:24) [classes/:na]`
Following is the code snippet
public class HiveWrapper
public ResultSet getResultset(String query) {
try {
preConfig();
this.client = new JdbcClient();
if (this.extraJarPath != null && !this.extraJarPath.equals("")) {
this.client.executeQuery(HIVEDRIVER, this.ctnString, prop, "ADD JAR " + this.extraJarPath);
}
return this.client.getResultSet(HIVEDRIVER, this.ctnString, prop, query);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
private void preConfig() {
if (this.ctnString == null || this.ctnString.equals("")) {
generateConnectionString();
}
try {
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
System.setProperty("java.security.krb5.conf", "hive/krb5.conf");
Configuration conf = new Configuration();
conf.addResource(new Path("hive/hive-site.xml"));
conf.addResource(new Path("hive/core-site.xml"));
conf.addResource(new Path("hive/hdfs-site.xml"));
conf.set("hadoop.security.authentication", "kerberos");
conf.set("hadoop.security.auth_to_local", this.securityAuth);
UserGroupInformation.setConfiguration(conf);
if (this.user != null && this.keytabPath != null) {
UserGroupInformation.loginUserFromKeytab(this.user, this.keytabPath);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public class JdbcClient {
public ResultSet getResultSet(String driverName, String connectionString, Properties prop,
String sql) throws SQLException {
getConnection(driverName, connectionString, prop);
if (this.con != null) {
log.info("Connection created for " + connectionString);
try {
log.info("Running SQL: " + sql);
stmt.setFetchSize(1000);
resultSet = stmt.executeQuery(sql);
return resultSet;
} catch (SQLException e) {
log.debug(e.getMessage());
throw new SQLException(e.getMessage());
}
}
return null;
}
private void getConnection(String driverName, String connectionString, Properties prop)
throws SQLException {
try {
if (this.con == null) {
Class.forName(driverName);
this.con = DriverManager.getConnection(connectionString, prop);
this.stmt = this.con.createStatement();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
The hive is running on a remote server. For hive I am adding the hive-site.xml, core-site.xml, hdfs-site.xml. Can anyone please help me on this. I am new to hive. Not able to find the issue. May be I am missing something.