我可以在hive中执行左连接吗?

unhi4e5o  于 2021-05-30  发布在  Hadoop
关注(0)|答案(1)|浏览(318)

我想在 hive 里做一个横向连接。有什么办法支持这一点吗?实际上,我想使用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;
a8jjtwal

a8jjtwal1#

配置单元不支持左连接,请使用与您的查询等效的“下查询”。我已经用示例数据进行了测试,它产生了相同的结果。

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;

希望我能帮你制定一些事情,你怎么能在Hive里做到一样。

相关问题