嵌套的大小写错误:输入'AS'不匹配,期望在表达式表达式中的'end'附近有KW_END:Hive

时间:2016-06-10 16:36:56

标签: hive case

我正在尝试在Hive中执行此案例

select case when (hour(rand_date)>=0 and hour(rand_date)<6) then 'early_morning' else 
case when (hour(rand_date)>=6 and hour(rand_date)<12) then 'morning' else 
case when (hour(rand_date)>=12 and hour(rand_date)<18) then 'afternoon' else
case when (hour(rand_date)>=18 and hour(rand_date)<24) then 'night' else 'other' end AS hourbins,
 rand_date from mock_ads_dates ;

它给我一个错误

  

编译语句时出错:FAILED:ParseException 4:85不匹配的输入'AS'期待KW_END在'end'附近表达式

1 个答案:

答案 0 :(得分:1)

Nested case statements中,

hive有点棘手。它应该是这样的: -

select case when (hour(rand_date)>=0 and hour(rand_date)<6) then 'early_morning' 
when (hour(rand_date)>=6 and hour(rand_date)<12) then 'morning'
when (hour(rand_date)>=12 and hour(rand_date)<18) then 'afternoon'
when (hour(rand_date)>=18 and hour(rand_date)<24) then 'night' else 'other' end AS hourbins,rand_date from mock_ads_dates ;