使用JDBC API在hive中执行插入查询。但查询未运行。有人可以建议出了什么问题。另外,请告诉我如何捕获hive在运行查询时抛出的错误代码。 Hive版本0.13.0
当我在命令行中运行日志中生成的查询时,它们正常工作。
public static void onSuccess() {
// Write to log on Success
LOGGER.info("Job Succeeded, Updating the " + hiveDB + "." + logTable + " with status SUCCESS");
String insertOnSuccess = "insert into table " + hiveDB + "." + logTable + " select " + currentJobID + "," + "'"
+ startTime + "'" + "," + "'" + stopTime + "'" + "," + runTime + "," + "\'SUCCESS\' from " + hiveDB
+ "." + "dual" + " limit 1; ";
commonDB.InsertToTable(insertOnSuccess);
JobMailer.PostMail("IB Load Successfully completed", "Load completed");
}
public void InsertToTable(String insertquery) {
try {
stm = hiveConn.createStatement();
stm.executeUpdate(insertquery);
} catch (SQLException e) {
LOGGER.error("Running the insert query for :" + insertquery);
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
if (stm != null) {
try {
stm.close();
} catch (SQLException e) {
LOGGER.error(e.getMessage());
;
}
}
}
}
这是我的错误日志:
16/02/12 12:31:09错误hiveconnector.CommonDBUtilities:运行 insert quer y for:insert into table installbase.IB_log select 25,'2016-02-12 12:26:43.037','2016-02-12 12:31:09.057',22982400,来自installbase.dual限制1的'SUCCESS'; 16/02/12 12:31:09 INFO hiveconnector.JobMailer:发送邮件:IB 加载Succe ssfully完成16/02/12 12:31:09 INFO hiveconnector.MainApp:将记录插入到installbase中 .data_usage_governance_log表16/02/12 12:31:10错误 hiveconnector.CommonDBUtilities:运行插入查询:插入 进入表installbase.data_usage_governance_log选择Data_Asset _Reference,File_Name,Origin_System,Transfer_System,'2016-02-12 12:26:43.037',Col umn_Reference,Element_Reference,Rule_Priority,Delete_By_Date,分类,地理 raphic_Inclusion,Geographic_Restriction,Group_Inclusion,Group_Restriction,RESERV 来自installbase.data_usage_governance_master
答案 0 :(得分:0)
太糟糕了,你被Hive 0.13困住了,因为......
从Hive 0.14.0开始,HiveServer2操作日志可用 为直线客户。 https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-HiveServer2Logging
在服务器端激活日志调度后,您可以从Java代码中检索这些日志条目 - 异步或整体执行结束时,使用类似...... < / p>
private static void DumpHiveMessages (java.sql.Statement stmtGeneric)
{ org.apache.hive.jdbc.HiveStatement stmtExtended ;
try
{ stmtExtended =(org.apache.hive.jdbc.HiveStatement)stmtGeneric ;
for (String sLogMessage : stmtExtended.getQueryLog())
{ JustTraceIt("HIVE SAYS>" +sLogMessage) ; }
if (stmtExtended.hasMoreLogs())
{ JustTraceIt("WARNING>(...log stream still open...") ; }
}
catch (Exception duh)
{ JustTraceIt("WARNING>Error while accessing Hive log stream");
JustTraceIt("WARNING>" +MakeSenseOfDirtyHadoopException(duh)) ;
}
}
那些东西没有真正记录,但是有源代码,例如 http://grepcode.com/file/repo1.maven.org/maven2/org.apache.hive/hive-jdbc/0.14.0/org/apache/hive/jdbc/HiveStatement.java
答案 1 :(得分:0)
我认为Hive插入/更新/删除功能仍有一些问题是hive 1.2.1。但你好像仍然在蜂巢0.14。所以我不建议使用这些功能。请查看其他用户发生的类似问题: