【发布时间】:2014-03-21 00:50:11
【问题描述】:
在 Hive 的左连接中使用 case 语句时遇到问题。
下面的 Hive 查询 -
select
m.InventoryId,
m.dataproviderid,
m.dealerid,
case when ti.makeid is null then T.MakeId else ti.makeid end,
ti.makename,
ti.modelname,
ti.yearindependentmodelid,
from InventoryMRout111 m
join InventoryTrim111 T on (m.InventoryId = T.InventoryId)
left join Styleinfo TI on ti.configuratorsourceid = 2122
and
(case
when t.chid is not null and
t.chid = ti.chid then 1
when t.mdlid is not null and t.mdlid =
ti.mdlid then 1
when t.makeid is not null and t.makeid = ti.makeid
then 1
else 0
end )
left join NewMinYear111 MY on (1=1)
where T.Trimsource in ('ranker','Match')
and m.Status = 'SUCCESS'
错误:
FAILED: SemanticException [Error 10017]: Line 20:26 Both left and right aliases encountered in JOIN '0'
有什么想法可以在这里解决吗?
我还尝试将 case 语句移至 where 子句..
select
m.InventoryId,
m.dataproviderid,
m.dealerid,
case when ti.makeid is null then T.MakeId else ti.makeid end,
ti.makename,
ti.modelname,
ti.yearindependentmodelid,
from InventoryMRout111 m
join InventoryTrim111 T on (m.InventoryId = T.InventoryId)
left join Styleinfo TI on ti.configuratorsourceid = 2122
left join NewMinYear111 MY on (1=1)
where T.Trimsource in ('ranker','Match')
and m.Status = 'SUCCESS'
and
(case
when t.chid is not null and
t.chid = ti.chid then 1
when t.mdlid is not null and t.mdlid =
ti.mdlid then 1
when t.makeid is not null and t.makeid = ti.makeid
then 1
else 0
end ) ;
但我得到了这个错误 -
FAILED: ClassCastException org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableIntObjectInspector cannot be cast to org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector
关于我在这里做错了什么有什么建议吗?
【问题讨论】: