Hive - 在连接表上使用横向视图 explode(split())
Posted
技术标签:
【中文标题】Hive - 在连接表上使用横向视图 explode(split())【英文标题】:Hive - Use lateral view explode(split()) on join table 【发布时间】:2019-07-29 14:25:43 【问题描述】:我想在一个更复杂的例子中使用this 简单主题。这是我的尝试:
SELECT maxxx.COD_ENTREP as ID_ENTITE,
maxxx.COD_ENTREP_ASSU as ID_ENTITE_GARANTE,
maxxx.ID_NOTIFICATION as ID_NOTIFICATION,
maxxx.OBJET_METIER as OBJET_METIER,
REF_EXT_OBJET_METIER,
case when maxxx.typ_mvt="S" then 1 else 0 end AS TOP_SUPP,
case when maxxx.typ_mvt = "S" then to_date(substr(maxxx.dt_capt, 1, 11)) else null end AS DT_SUPP,
minnn.typ_mvt as MIN_MVT,
maxxx.typ_mvt as MAX_MVT,
case when minnn.typ_mvt = 'C' then 'C' else 'M' end as TYP_MVT
FROM
(select s.id_notification, s.dt_capt, s.typ_mvt from $use_database.pz_send_notification as s
join
(select id_notification, min(dt_capt) as dtmin from $use_database.pz_send_notification group by id_notification) as minn
on s.id_notification=minn.id_notification and s.dt_capt=minn.dtmin) as minnn
join
(select s.id_notification, s.dt_capt, s.typ_mvt, s.cod_entrep, s.cod_entrep_assu, s.objet_metier from $use_database.pz_send_notification as s
join
(select id_notification, max(dt_capt) as dtmax from $use_database.pz_send_notification group by id_notification) as maxx
on s.id_notification=maxx.id_notification and s.dt_capt=maxx.dtmax) as maxxx
on minnn.id_notification=maxxx.id_notification
lateral view explode(split(maxxx.OBJET_METIER, ";")) maxxx.OBJET_METIER as ee;
我想在使用多个连接创建的表上应用拆分功能。
但我一直有这个错误:
Error while compiling statement: FAILED: ParseException line 28:0 missing EOF at 'lateral' near 'id_notification'
编辑
这是查询的结果没有最后一行(侧视图爆炸):
我想要的是一个有 4 行的表格。前三个是 ref_ext_objet_metier_column 使用 split on ";" 复制的结果。
【问题讨论】:
您能向我们展示表格数据和预期结果吗? 我刚刚编辑了我的问题 【参考方案1】:分号在 Hive 中有特殊含义,应该被屏蔽。在 Hive 中使用双斜线:
split(maxxx.OBJET_METIER, '\\;')
别名也是错误的。为横向视图提供正确的别名,如下所示:
lateral view explode(split(maxxx.OBJET_METIER, '\\;')) om as splitted_col
例如,在查询中将其寻址为om.splitted_col
。
如果你使用beeline并且'\\;'
不起作用,试试'\073'
:
lateral view explode(split(maxxx.OBJET_METIER, '\073')) om as splitted_col
【讨论】:
以上是关于Hive - 在连接表上使用横向视图 explode(split())的主要内容,如果未能解决你的问题,请参考以下文章