java - 使用Hive JDBC连接的Hive ACID事务属性

标签 java hadoop jdbc hive hortonworks-data-platform

我试图在Hive 0.14中执行Hive ACID事务属性,例如通过Java进行插入,删除和更新。我能够设置所需的ACID事务属性。还能够使用事务属性创建表。但这是失败的。下面是示例代码:

public class HiveJdbcClient {
    private static String driverName = "org.apache.hive.jdbc.HiveDriver";

    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);
        }
        Connection con = DriverManager.getConnection("jdbc:hive2://ipaddress:port/default", "user", "password");
        Statement stmt = con.createStatement();

        stmt.execute("set set hive.support.concurrency=true");
        stmt.execute("set hive.enforce.bucketing=true");
        stmt.execute("set hive.exec.dynamic.partition.mode=nonstrict");
        stmt.execute("set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager");
        stmt.execute("set hive.compactor.initiator.on=true");
        stmt.execute("set hive.compactor.worker.threads=2");



        String tableName = "hive_acid_test";

        stmt.execute("drop table if exists " + tableName);


        stmt.execute("create table " + tableName + " (id int, name string,department string) clustered by (department) into 3 buckets stored as orc TBLPROPERTIES   ('transactional'='true')");


        stmt.execute("insert into table hive_acid_test values(1,'jon','sales')");
    }
}

尝试插入时收到以下异常:

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:296) at promo.hive.sample.HiveJdbcClient.main(HiveJdbcClient.java:49)



从命令行运行相同的插入命令。请帮助我找到问题。

最佳答案

我能够重现问题,并检查了Hive服务器日志-hiveserver2.log。
现在这是一个已知问题-https://issues.apache.org/jira/browse/HIVE-8326
在Hive 1.1版中已修复

问题与您的ACID配置中使用的DbTxManager有关。

错误日志:

java.lang.NullPointerException
        at org.apache.hadoop.hive.ql.lockmgr.DbTxnManager.heartbeat(DbTxnManager.java:254)
        at org.apache.hadoop.hive.ql.exec.Heartbeater.heartbeat(Heartbeater.java:81)
        at org.apache.hadoop.hive.ql.exec.mr.HadoopJobExecHelper.progress(HadoopJobExecHelper.java:242)
        at org.apache.hadoop.hive.ql.exec.mr.HadoopJobExecHelper.progress(HadoopJobExecHelper.java:547)
        at org.apache.hadoop.hive.ql.exec.mr.ExecDriver.execute(ExecDriver.java:435)
        at org.apache.hadoop.hive.ql.exec.mr.MapRedTask.execute(MapRedTask.java:137)
        at org.apache.hadoop.hive.ql.exec.Task.executeTask(Task.java:160)
        at org.apache.hadoop.hive.ql.exec.TaskRunner.runSequential(TaskRunner.java:85)
        at org.apache.hadoop.hive.ql.Driver.launchTask(Driver.java:1604)
        at org.apache.hadoop.hive.ql.Driver.execute(Driver.java:1364)
        at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1177)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1004)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:999)

关于java - 使用Hive JDBC连接的Hive ACID事务属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29398785/

相关文章:

java - 在 Java 中连接到 Microsoft Access 2007 数据库的正确方法是什么?

java - Spring REST @RequestMapping 实践

map - JobConf 中未设置输出目录

hadoop - 无法读取现有文件 - 没有这样的文件或目录

java - 将PreparedStatement批处理与Statement批处理混合使用,可能吗?

java - 延迟初始化完整性检查 : Variable might not have been initialized

java - 如何在Rest客户端中发送Curl的-u数据

hadoop - FIWARE-Cosmos 头节点的 SSH 访问

java - Postgres JDBC 驱动程序 `org.postgresql.ds.PGSimpleDataSource` 是线程安全的吗?

mysql - InnoDB/MySQL - 新事务在 SELECT 上使用旧数据而不是返回更新后的数据