I am using CDH 4.2.1-1.cdh4.2.1.p0.5 in a cluster set-up with Cloudera Manager and I am trying to get the Hive example working using the Hive API in Java. The hive version I am using is 0.10 (hive-hwi-0.10.0-cdh4.2.1.jar) and I am trying to setup a simple example following the instructions in this url: https://cwiki.apache.org/confluence/display/Hive/HiveClient
When running my code (the source code at the end of the post), I am getting the following error:
Exception in thread "main" java.sql.SQLException: org.apache.thrift.TApplicationException: Invalid method name: 'execute'
at org.apache.hadoop.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:191)
at org.apache.hadoop.hive.jdbc.HiveStatement.execute(HiveStatement.java:127)
at org.apache.hadoop.hive.jdbc.HiveConnection.configureConnection(HiveConnection.java:126)
at org.apache.hadoop.hive.jdbc.HiveConnection.<init>(HiveConnection.java:121)
at org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:104)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:221)
I've been searching in Google for a while now and I cannot find any solution to this problem. Anyone can give me a hint what could be causing the issue?
Thanks in advance,
Robbbie
Code causing the error:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.log4j.Logger;
public class HiveJob {
private static Logger mLogger = Logger.getLogger(HiveJob.class);
private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException {
HiveJob myJob = new HiveJob();
myJob.execute();
}
public void execute() throws SQLException {
mLogger.info("Start HiveJob");
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
Connection con = DriverManager.getConnection("jdbc:hive://myHiveServer:9083/default", "", "");
Statement stmt = con.createStatement();
String sql = "SHOW TABLES";
System.out.println("Running: " + sql);
ResultSet res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(res.getString(1));
}
mLogger.info("HiveJob executed!");
}
}
The jdbc url points to myHiveServer:9083 , which is the metastore default port. You are getting that error because metastore does not support the same thrift api as hive server. You need to specify the host + port of hiveserver(1 or 2). The default port for it is 10000.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With