記錄一次HIVE執行查詢的報錯。
CDH平台搭建大數據平台,使用HIVE測試select count(1) from test,報錯如下:
java.sql.SQLException: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask
at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:292)
at org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:393)
at com.QueryHiveUtils.countData(QueryHiveUtils.java:16)
at com.QueryHiveTest.main(QueryHiveTest.java:42)
解決:
之前使用了root運行報錯,修改為hdfs用戶可正常返回查詢的結果。
private static String driverName ="org.apache.hive.jdbc.HiveDriver";
private static String user = "hdfs"; --使用root用戶報錯
private static String password = "hdfs";
private static String Url="jdbc:hive2://192.168.0.108:10000/default"; //填寫hive的IP,之前在配置文件中配置的IP
private static Connection conn;
public static Connection getConnnection()
{
try
{
Class.forName(driverName);
conn = DriverManager.getConnection(Url,user,password); //此處的用戶名一定是有權限操作HDFS的用戶,否則程序會提示"permission deny"異常
}
catch(ClassNotFoundException e) {
e.printStackTrace();
System.exit(1);
}
catch (SQLException e) {
e.printStackTrace();
}
return conn;
}