Hive - 连接中的Case语句 - 错误

时间:2014-03-10 22:06:00

标签: hadoop hive hiveql

在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

关于我在这里做错了什么建议?

1 个答案:

答案 0 :(得分:2)

看起来第二个错误说你必须明确地返回布尔值,而不是在case语句中返回0和1。

隐式转换表here表示不会自动处理boolean-to-int。

对于BOOLEAN值,文字为TRUE和FALSE,没有引号和不区分大小写。