Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hive JDBC getConnection does not return

Tags:

jdbc

hadoop

hive

I'm following the hive JDBC tutorial. I could not get it working. When it try to get the connection it just hangs. It does not report any error either. I'm sure the Hive server is running. Any help?

public class HiveJdbcClient {
  private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
  public static void main(String[] args){
      try {
      Class.forName(driverName);
    } catch (ClassNotFoundException e) {
           e.printStackTrace();
      System.exit(1);
    }

    try{
        Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/default", "", "");
        System.out.println("got the connection");

    }catch(SQLException e){
        e.printStackTrace();
    }
  }
}

output of the netstat:

$ sudo netstat -anlp | grep 10000
Password:
tcp        0      0 0.0.0.0:10000               0.0.0.0:*                   LISTEN      27738/java
tcp      107      0 127.0.0.1:10000             127.0.0.1:45910             ESTABLISHED 27738/java
tcp        0      0 127.0.0.1:33665             127.0.0.1:10000             ESTABLISHED 24475/java
tcp        0      0 127.0.0.1:45910             127.0.0.1:10000             ESTABLISHED 7445/java
tcp      107      0 127.0.0.1:10000             127.0.0.1:33665             ESTABLISHED 27738/java
like image 841
FourOfAKind Avatar asked Nov 04 '22 19:11

FourOfAKind


2 Answers

Naresh: Try stopping the triffserver, then move to the HIVE_HOME/bin directory from your terminal, then start the hive trift server using the ./hive --service hiveserver 10000 & command. Then try running the program. Do a create table as per the hive client wiki example . Then do a show tables query in the next step. Let us know the result once this steps are followed. We can have a discussion after that.

like image 96
Arun A K Avatar answered Nov 09 '22 08:11

Arun A K


You can do the following to pinpoint where the hang is happening. Here is an example that I did to trace it in my broken Hive JDBC connection. Note that this is not a concrete solution to any generic hive connection hanging error.

This is an answer to the question: "how can I find out where my JDBC hive connection is hanging? "

What makes this hard to trace is the JDBC dynamic invocation. Instead, you can just manually createa HiveConnection() class. That allows you to add some tracing into the code directly, to see where the hang is happening.

I've traced this by doing the following.

* USING LOG4J *

The thrift and other JDBC hive classes use log4j when connecting, if you turn DEBUG logging on, you can see fine grained errors. You can do this easily by adding

BasicConfigurator.configure()

To your client app. In any case, doing this led me to find that this seems to be stalling in the SASL transport layer. I guess it could be security related but I would assume that a security error would STILL return, and not hang... So I think this may be worthy of a JIRA. I've pasted a follow up question:

How can I trace the failure ot TSaslTransport (hive related)

* ANOTHER METHOD *

1) You can grab a copy of the "HiveConnection" class from github, or wherever, and instantiate a new one:

String url=String.format("jdbc:hive2://%s:%s/default", server, port) Properties p = new Properties(); p.setProperty("host", con); Connection jdbc = new HiveConnection(url,p);

Then, you can add your debugger hooks or log statements to the HiveConnection() class.

Ulitmately, when i had this error, I traced it to:

openTransport

Which ultimately creates a

org.apache.thrift.transport.TSaslClientTransport

instance.

And the hang happens in this code block:

try { System.out.println(".....1 carrying on... attempting to open. " + transport.getClass().getName()); transport.open(); System.out.println("done open."); } catch (TTransportException e) { System.out.println("2 fail ."); e.printStackTrace(); throw new SQLException("Could not establish connection to " + uri + ": " + e.getMessage(), " 08S01"); }

FYI I've posted a follow up regarding why MY connection failed. It might be related to yours as well... How can I trace the failure ot TSaslTransport (hive related)

like image 42
jayunit100 Avatar answered Nov 09 '22 09:11

jayunit100