我编写了一个 Java 代码来访问 Apache Hive 表。
import java.sql.*;
public class HiveQL {
private static String drivername = "org.apache.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException
{
try{
Class.forName(drivername);
}catch(ClassNotFoundException e)
{
e.printStackTrace();
System.exit(1);
}
Connection con = DriverManager.getConnection("jdbc:hive2://xxx.xxx.xxx.xxx:10000/db", "", "");
Statement stmt = con.createStatement();
ResultSet res = stmt.executeQuery("select distinct ClientName from leadgen_main");
System.out.println("Output");
while(res.next())
{
System.out.println(res.getString(1));
}
con.close();
}
}
对于上述程序,我收到以下错误:
log4j:WARN No appenders could be found for logger (org.apache.hive.jdbc.Utils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
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.
Exception in thread "main" 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:279)
at org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:375)
at com.dwi.java.hive.HiveQL.main(HiveQL.java:22)
对于不需要 mapreduce 的普通查询,工作正常,但是当我使用执行 mapreduce 任务的这种类型的查询时,我得到了上述错误。
请帮助解决这个问题。