Ich verwende Hive 0.12 und versuche die JDBC von Apache. Wenn ich versuche, den Code auszuführen, erhalte ich Apache.thrift.TApplicationException.
import Java.sql.SQLException;
import Java.sql.Connection;
import Java.sql.ResultSet;
import Java.sql.Statement;
import Java.sql.DriverManager;
public class HiveJdbcClient {
private static String driverName = "org.Apache.Hive.jdbc.HiveDriver";
/**
* @param args
* @throws SQLException
*/
public static void main(String[] args) throws SQLException {
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
//replace "Hive" here with the name of the user the queries should run as
Connection con = DriverManager.getConnection("jdbc:Hive2://localhost:10000/default", "Hive", "");
Statement stmt = con.createStatement();
String tableName = "testHiveDriverTable";
stmt.execute("drop table if exists " + tableName);
stmt.execute("create table " + tableName + " (key int, value string)");
// show tables
String sql = "show tables '" + tableName + "'";
System.out.println("Running: " + sql);
ResultSet res = stmt.executeQuery(sql);
if (res.next()) {
System.out.println(res.getString(1));
}
// describe table
sql = "describe " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(res.getString(1) + "\t" + res.getString(2));
}
// load data into table
// NOTE: filepath has to be local to the Hive server
// NOTE: /tmp/a.txt is a ctrl-A separated file with two fields per line
String filepath = "/tmp/a.txt";
sql = "load data local inpath '" + filepath + "' into table " + tableName;
System.out.println("Running: " + sql);
stmt.execute(sql);
// select * query
sql = "select * from " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2));
}
// regular Hive query
sql = "select count(1) from " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(res.getString(1));
}
}
}
Ich habe alle notwendigen Gläser importiert und wenn ich versuche, meinen Code auszuführen, erhalte ich die folgende Fehlermeldung:
org.Apache.thrift.TApplicationException: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null)
Wie kann ich das beheben?
Dies weist auf einen Versionskonflikt zwischen Client und Server hin, dh der Client ist neuer als der Server. Dies ist in Ihrem Fall der Fall.
Ich habe das gleiche Problem. Es funktioniert, wenn du eingestellt hast
Hive JDBC Maven Repo Version als 1.1.0.
Überprüfen Sie diese Jira. Die neueste Hive-JDBC-Version wird mit Hive 0.13 nicht unterstützt. https://issues.Apache.org/jira/browse/Hive-6050
Fügen Sie dies in Ihrem Pom hinzu.
<dependency>
<groupId>org.Apache.Hive</groupId>
<artifactId>Hive-jdbc</artifactId>
<version>1.1.0</version>
<classifier>standalone</classifier>
</dependency>
Jungs, selbst ich hatte das gleiche Problem und ging die Lösung, indem ich die folgenden Schritte durchführte
Schritt 01: - Binden Sie die Hive-Lib-Gläser in Ihre Eclipse (je nach IDE) ein, indem Sie den folgenden Link verwenden.
http://mirrors.supportex.net/Apache/Hive/hive-1.0.1/ (Apache-Hive-1.0.1-bin.tar.gz)
Schritt 02: Füge hadoop-core-1.1.0-Glas hinzu
wie alle bereits erwähnt, tritt dieser Fehler auf, weil die Versionen mit hadoop Standalone und hadoop core nicht übereinstimmen.