我可以在Hive中进行LEFT JOIN LATERAL吗?

时间:2015-04-04 17:36:14

标签: hadoop join hive lateral

我想在Hive做一个LATERAL JOIN。 有没有办法支持这个?本质上,我想使用LHS上的行中的值作为RHS上任意SQL的参数。

以下是Postgres的一个例子:(原谅我粗略的例子):

create table lhs (
    subject_id integer,
    date_time  BIGINT );

create table events (
    subject_id  integer,
    date_time   BIGINT,
    event_val   integer );

SELECT * from lhs LEFT JOIN LATERAL ( select SUM(event_val) as val_sum, count(event_val) as ecnt from events WHERE date_time < lhs.date_time and subject_id = lhs.subject_id ) rhs1 ON true;

1 个答案:

答案 0 :(得分:0)

Hive不支持 LEFT JOIN LATERAL ,使用下面的查询等同于你的查询。我已经测试了样本数据,它产生了相同的结果。

select subject_id,date_time,SUM(event_val) as val_sum,COUNT(event_val) as ecnt 
from (SELECT a.subject_id as subject_id ,
      a.date_time as date_time, b.date_time as bdate , b.event_val as event_val
      FROM events b LEFT OUTER JOIN lhs a 
      ON b.subject_id = a.subject_id) abc 
where bdate < date_time group by subject_id,date_time;

希望我能帮助你制定出如何在蜂巢中实现同样目标的事情。