我在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
我在这里做错了什么建议?
最佳答案 看起来像第二个错误说你必须明确地返回布尔值,而不是在case语句中返回0和1.
隐式转换表here表示不会自动处理boolean-to-int.
对于BOOLEAN值,文字为TRUE和FALSE,没有引号和不区分大小写.