【问题标题】:Insert row number into table将行号插入表格
【发布时间】:2016-08-24 13:28:06
【问题描述】:

我正在尝试将行号插入表中。 row_number() 函数在执行选择查询时起作用,但当我将它用作 INSERT INTO TABLE 查询的一部分时,该查询不起作用。我也尝试过通过 Create Table As Select 但我得到了同样的看似通用的错误。

FAILED: Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask (state=08S01,code=2)

示例:这不起作用。

INSERT INTO TABLE tablea
SELECT
column1,
column2,
row_number() over (order by column2 desc)
FROM
tableb;

示例:这确实有效

SELECT
column1,
column2,
row_number() over (order by column2 desc)
FROM
tableb;

有什么建议吗?谢谢!

编辑:我使用 Hive 1.1.0 作为 CDH 5.4.8 的一部分。

【问题讨论】:

  • 您能否指定您遇到错误的配置单元版本?
  • 我完全忘记了。我使用 Hive 1.1.0 作为 CDH 5.4.8 的一部分。
  • 我已经在 Hive 1.2.1 上执行了给定的脚本(作为答案)作为 HDP 2.3 的一部分,但我没有 CDH

标签: hive hiveql


【解决方案1】:

我已经尝试过您想要做的事情并且它正在工作。这是我的 HQL 语句:

create table tablea (id int, string name);

insert into tablea values (1, 'test1');
insert into tablea values (2, 'test2');

create table tableb (id int, name string, row_num int);

insert into tableb select id, name, row_number() over ( order by name desc) from tablea;
select * from tableb;

结果

+------------+--------------+-----------------+--+
| tableb.id  | tableb.name  | tableb.row_num  |
+------------+--------------+-----------------+--+
| 2          | test2        | 1               |
| 1          | test1        | 2               |
+------------+--------------+-----------------+--+

【讨论】:

  • 我运行了这个脚本,它可以工作(在第一行交换了名称和字符串)。我必须有另一个不相关的错误。我会将此标记为答案。
【解决方案2】:

好吧,看起来这是因为存储格式是 ORC。将表设置为 TEXTFILE,问题就消失了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多