简体   繁体   English

HIVE-QL中的LEAD函数语法

[英]LEAD function syntax in HIVE-QL

Is there any way to convert below LEAD function into HIVE QL format?? 有什么方法可以将下面的LEAD函数转换为HIVE QL格式?

NVL(LEAD(START_DT) OVER (PARTITION BY EV_ID,AR_EV_RLTNSHP_TYPE_CD ORDER BY START_DT)-1,'2099-12-31') AS DERIVED_END_DT

PFB the error: PFB错误:

FAILED: ParseException line 1:1599 missing ) at 'OVER' near '(' in subquery source line 1:1603 missing FROM at '(' near '(' in subquery source line 1:1604 cannot recognize input near 'PARTITION' 'BY' 'EV_ID' in subquery source 失败:子查询源行1:1604的'('附近的'OVER'附近的'OVER'处ParseException行1:1599缺少)子查询源行1:1604的'('附近的'('附近缺少FROM ''EV_ID'在子查询源中

It is complicated in HiveSQL but you can do it with a left join and aggregation: 在HiveSQL中它很复杂,但是您可以通过left join和聚合来完成:

select t.ev_id, t.ar_ev_rltnshp_type_cd, t.start_date,
       coalesce(min(tnext.start_dt) - 1, '2099-12-31') as derived_end_dt
from table t left join
     table tnext
     on t.ev_id = tnext.ev_id and t.ar_ev_rltnshp_type_cd = tnext.ar_ev_rltnshp_type_cd and
        tnext.start_date > t.start_date
group by t.ev_id, t.ar_ev_rltnshp_type_cd, t.start_date;

This makes certain assumptions about start_date being unique within a given group, but it will probably work for your purposes. 这使有关start_date在给定组中唯一的某些假设,但可能会满足您的目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM