使用 JDBC API 在 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 into table installbase.IB_log select
25,'2016-02-12 12:26:43.037', '2016-02-12
12:31:09.057',22982400,来自 installbase.dual limit 1 的 'SUCCESS';
12/02/16 12:31:09 信息 hiveconnector.JobMailer:使用 :IB 发送邮件
加载成功 16/02/12 12:31:09 INFO
hiveconnector.MainApp:已将记录插入安装库
.data_usage_governance_log 表 16/02/12 12:31:10 错误
hiveconnector.CommonDBUtilities:运行插入查询:Insert
进入表 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、地理_限制、组_包含、组_限制、保留
编辑自 installbase.data_usage_governance_master
太糟糕了,你被 Hive 0.13 困住了,因为......
从Hive 0.14.0开始,HiveServer2操作日志可用
对于直线客户。https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-HiveServer2Logging https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-HiveServer2Logging
一旦在服务器端激活日志分派,您就可以从 Java 代码中检索这些日志条目——异步或en masse当执行结束时,类似...
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)) ;
}
}
这些东西并没有真正记录下来,但是有源代码HiveStatement
显示了几种非 JDBC 标准方法,例如getQueryLog
and hasMoreLogs
- 还getYarnATSGuid
适用于 Hive 2+ 以及适用于 Hive 3+ 的其他内容。
这里是链接到 GitHub 上的“master”分支 https://github.com/apache/hive/blob/master/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java,切换到您正在使用的版本(可能是旧的 1.2,以便与 Spark 兼容).
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)