Hive 从列值生成配置单元行

Hive 从列值生成配置单元行,hive,hiveql,Hive,Hiveql,如何基于单个列值在配置单元中生成行。例如 我有下表的数据。我需要生成类似的行(所有字段都相同),但要使用所有列值进行评级 item_id cost rating 23 1290 0.08 14 1498 0.06 我需要如下所示的输出 item_id cost rating 23 1290 0.08 23 1290 0.07 23 1290 0.06 23 1290 0.

如何基于单个列值在配置单元中生成行。例如

我有下表的数据。我需要生成类似的行(所有字段都相同),但要使用所有列值进行评级

item_id   cost   rating
23        1290   0.08
14        1498   0.06
我需要如下所示的输出

item_id   cost   rating
23        1290   0.08
23        1290   0.07
23        1290   0.06
23        1290   0.05
23        1290   0.04
23        1290   0.03
23        1290   0.02
23        1290   0.01
14        1498   0.06
14        1498   0.05
14        1498   0.04
14        1498   0.03
14        1498   0.02
14        1498   0.01
例如:

with initial_data as(
select stack(2,
23, 1290, 0.08,
14, 1498, 0.06
) as (item_id, cost, rating)
) 

select item_id, cost, (i+1)/100 as rating
from
(
select d.*, cast(d.rating*100 as int)-1 as n --the number of rows to generate
  from initial_data d
)s lateral view posexplode(split(space(s.n),' ')) e as i, x  --generate rows with numbers (i)
order by item_id desc, rating desc; --remove ordering for faster processing if you do not need ordered output
结果:

OK
23      1290    0.08
23      1290    0.07
23      1290    0.06
23      1290    0.05
23      1290    0.04
23      1290    0.03
23      1290    0.02
23      1290    0.01
14      1498    0.06
14      1498    0.05
14      1498    0.04
14      1498    0.03
14      1498    0.02
14      1498    0.01
Time taken: 74.993 seconds, Fetched: 14 row(s)