蜂巢自动增量

时间:2015-07-02 10:04:00

标签: java hadoop hive auto-increment hiveql

我想在Hive中创建一个auto_increment列。 我没有在蜂巢文档上看到任何关于此的内容,但我发现我们可以使用: UDFRowSequence来做到这一点。

是否有最新的方式或是否有新的方式,最“容易”?

我已经尝试过了:所以在我的Java项目中,我创建了这样的函数:

private static void createAutoIncrFunction() throws SQLException {
    Statement stmt = conn.createStatement();
    String sql = "create function autoincr as \"org.apache.hadoop.hive.contrib.udf.UDFRowSequence\"";
    stmt.execute(sql);
}

该功能的创建正在发挥作用。 但现在我不知道如何使用我尝试的这个函数创建我的表:

private static void createTableLine() throws SQLException {
    String sql =  "CREATE TABLE IF NOT EXISTS line(id_line INT autoincr(), "
                                                + "uid_ticket VARCHAR(64), "
                                                + "number INT, "
                                                + "kind INT)";
    Statement stmt = conn.createStatement();
    stmt.execute(sql);
}

但它没有用,所以我的问题是:如何创建一个包含auto_increment列的表,如何在其中插入数据?

1 个答案:

答案 0 :(得分:0)

表格正常创建。但是在添加时,您可以使用由您创建的功能。

hive> CREATE TABLE increment_table1 (id INT, c1 STRING, c2 STRING, c3 STRING);
hive> INSERT OVERWRITE TABLE increment_table1 SELECT incr() AS inc, id, c1, c2 FROM t1;

您可以使用此link获取更多信息

相关问题