【问题标题】:Hive - Case statement in join - errorHive - 连接中的案例语句 - 错误
【发布时间】: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

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

【问题讨论】:

    标签: hadoop hive hiveql


    【解决方案1】:

    看起来第二个错误表明您必须在 case 语句中显式返回布尔值而不是 0 和 1。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多