【问题标题】:Hive auto incrementHive 自动增量
【发布时间】:2015-09-19 19:21:16
【问题描述】:

我想在 Hive 中创建一个 auto_increment 列。 我在 hive 文档上没有看到任何关于此的内容,但我发现我们可以使用: 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 列的表以及如何在其中插入数据?

【问题讨论】:

    标签: java hadoop hive auto-increment hiveql


    【解决方案1】:

    表已正常创建。但是在添加的时候,可能会用到自己创建的函数。

    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 了解更多信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-28
      • 1970-01-01
      • 2022-01-06
      • 2010-10-21
      • 2013-10-12
      • 2014-02-21
      相关资源
      最近更新 更多