select a.id
,a.name
,b.desc
from table_a as a
left join (select b.min_num + pe.pos as num
,b.desc
from table_b as b
lateral view
posexplode(split(space(b.max_num-b.min_num),' ')) pe
) b
on b.num =
a.num
;
使用此解决方案,您可以控制性能。 b 范围正在被拆分为子范围,如您所愿( x ). 太大了 x 实际上会引起交叉连接。 太小了 x 可能会从 b ( x =1将生成所有 b 范围值)。
set hivevar:x=100;
select a.id
,a.name
,b.desc
from table_a as a
left join
(select a.id
,b.desc
from table_a as a
inner join
(select b.min_num div ${hivevar:x} + pe.pos as sub_range_id
,b.*
from table_b as b
lateral view
posexplode(split(space(cast (b.max_num div ${hivevar:x} - b.min_num div ${hivevar:x} as int)),' ')) pe
) as b
on a.num div ${hivevar:x} =
b.sub_range_id
where a.num between b.min_num and b.max_num
) b
on b.id =
a.id
;
select a.id
,a.name
,b.desc
from table_a as a
left join (select a.id
,b.desc
from table_a as a
cross join table_b as b
where a.num between b.min_num and b.max_num
) b
on b.id =
a.id
;
3条答案
按热度按时间rsaldnfx1#
l3zydbqr2#
使用此解决方案,您可以控制性能。
b
范围正在被拆分为子范围,如您所愿(x
).太大了
x
实际上会引起交叉连接。太小了
x
可能会从b
(x
=1将生成所有b
范围值)。6yjfywim3#