有没有办法将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错误:
失败:ParseException第1行:1599失踪)在' OVER'靠近'(' in 子查询源代码行1:1603缺少FROM'(' near'('在子查询中) 源代码行1:1604无法识别' PARTITION'附近的输入。 ' BY' ' EV_ID'在子查询源
中
答案 0 :(得分:1)
在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;
这使得start_date
的某些假设在给定组中是唯一的,但它可能适用于您的目的。