HIVE 复制行n次直到某一列等于200

例如需要复制tmp_1表n次,每复制一次,gday+1,直到gday=200,

借助 lateral view posexplode,首先用space复制多个空格字符串,复制次数=200-gday

然后split将字符串分割成数组,此时该数组大小为200-gday

然后lateral view posexplode创建虚拟表,虚拟表大小也为200-gday

用gday+虚拟表的索引,即可得到递增的gday,且gday最大值为200

with tmp_1 as (
select 'a' as rearer,
150 as gday,
2.3 as rate
union all
select 'b' as rearer,
160 as gday,
5 as rate
)

select id_start+pos, rate as id 
from( select gday as id_start, 200 as id_end, rate from tmp_1) m 
lateral view posexplode(split(space(id_end-id_start), '')) t as pos, val

你可能感兴趣的:(hive,hadoop,数据仓库)