将行号插入 table

Insert row number into table

我正在尝试将行号插入 table。 row_number() 函数在执行 select 查询时有效,但当我将它用作 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 的一部分。

我已经尝试了你想做的事情并且它正在工作。这是我的 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               |
+------------+--------------+-----------------+--+

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