Hive实现自增列

1、用row_number()函数生成代理键

insert into table id_test 

select row_number() over() + t2.max_id as id, t1.name
from (select name from nametb) t1

cross join (select coalesce(max(id),0) max_id from id_test) t2;

 

2、用UDFRowSequence生成代理键              ——报错?

add jar /usr/local/hive.bak/lib/hive-contrib-2.1.1.jar;

create temporary function row_sequence as 'org.apache.hadoop.hive.contrib.udf.udfrowsequence'; insert into tbl_dim select row_sequence() + t2.sk_max,
nametb.* from nametb
cross join (select coalesce(max(sk),0) sk_max from tbl_dim) t2;

 

posted @ 2017-10-17 20:45  hongma  阅读(8345)  评论(0编辑  收藏  举报