Metadata
Metadata

Reputation: 2083

Exception while connecting to Hive using JDBC and Kerberos authentication

I am trying to connect to Hive using JDBC and Kerberos authentication in Java. To do that, I came up with the following code.

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.UserGroupInformation;

public class DbManager {
private static Connection hiveConnection;
// get Hive Connection
public static Connection qwtHiveConnection() throws IOException, SQLException {

    System.out.println("Preparing Hive connection1");
    Configuration conf = new Configuration();
    conf.set("hadoop.security.authentication", "Kerberos");
    UserGroupInformation.setConfiguration(conf);
    UserGroupInformation.loginUserFromKeytab("[email protected]", "path of keytab");
    // Hive Connection
    try {
        Class.forName("org.apache.hive.jdbc.HiveDriver");
        if(hiveConnection == null) {
            hiveConnection = DriverManager.getConnection("jdbc:hive2://abcd1dq000.hlc.abc.qw.com:10000/finance;principal=hive/[email protected]", "usrname", "pwd");
            return hiveConnection;
        } else {
        return hiveConnection;
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        return null;
    } catch (SQLException e) {
        e.printStackTrace();
        return null;
    }
}
}

The Hadoop version I see from the command 'hadoop version': Hadoop 2.7.3.2.6.2.0-205 This command was run using /usr/hdp/2.6.2.0-205/hadoop/hadoop-common-2.7.3.2.6.2.0-205.jar

I am using the following jar files in the project:

hive-jdbc-2.2.0.jar,
postgresql-9.4.1212.jar,
apache-commons.jar,
slf4j-api-1.7.25.jar,
hadoop-commons-2.6.2.jar,
guava-18.0.jar,
commons-configuration-1.9.jar,
commons-lang-2.6.jar,
hadoop-auth-2.6.2.jar,
hadoop-core-1.2.0.jar

When I run the jar, I get the exception:

Preparing Hive connection1
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Kerberos Connected
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hive/service/rpc/thrift/TCLIService$Iface
    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:247)
    at com.dbconnections.gphive.DbManager.getHiveConnection(DbManager.java:35)
    at com.recordcount.dao.GpHiveRecords.getHiveTableCount(GpHiveRecords.java:93)
    at com.recordcount.entry.StartCount.main(StartCount.java:13)
Caused by: java.lang.ClassNotFoundException: org.apache.hive.service.rpc.thrift.TCLIService$Iface
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 6 more

Upvotes: 0

Views: 924

Answers (1)

Jens
Jens

Reputation: 69450

Looks like you miss the following dependency:

<dependency>
    <groupId>org.apache.hive</groupId>
    <artifactId>hive-service-rpc</artifactId>
    <version>2.2.0</version>
</dependency>

This jar contains the missing interface.

UPDATE:

Looks like you need also:

<dependency>
    <groupId>org.apache.hive</groupId>
    <artifactId>hive-service</artifactId>
    <version>2.2.0</version>
</dependency>

And mybe other jar's.

Upvotes: 2

Related Questions