Hive实现自增列
Posted hongma
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
以上是关于Hive实现自增列的主要内容,如果未能解决你的问题,请参考以下文章