Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

CASE statement Error in Beeline HIVE

Solved Go to solution

CASE statement Error in Beeline HIVE

New Contributor
 
1 ACCEPTED SOLUTION

Accepted Solutions

Re: CASE statement Error in Beeline HIVE

Hi @Gayathri Devi

sample nested case which can be used in hive.

Select case 
when hour(split(split(hbid,"#")[1],"_")[1])== 0 then concat(split(split(split(hbid,"#")[1],"_")[1]," ")[0],"/","0-2") 
when hour(split(split(hbid,"#")[1],"_")[1]) ==1 then concat(split(split(split(hbid,"#")[1],"_")[1]," ")[0],"/","0-2")]
when hour(split(split(hbid,"#")[1],"_")[1]) ==2 then concat(split(split(split(hbid,"#")[1],"_")[1]," ")[0],"/","2-4")]
when hour(split(split(hbid,"#")[1],"_")[1]) ==2 then concat(split(split(split(hbid,"#")[1],"_")[1]," ")[0],"/","2-4")]
when hour(split(split(hbid,"#")[1],"_")[1]) ==3 then concat(split(split(split(hbid,"#")[1],"_")[1]," ")[0],"/","2-4")]
else 'NA'
end as column1 from table_name; 

If it helps then please accept it as the best answer! Happy Hadooping!!

3 REPLIES 3

Re: CASE statement Error in Beeline HIVE

@Gayathri Devi

You have missed end in the statement. This should work.

case when hour(split(split(hbid,"#")[1],"_")[1])==0<br>then concat(split(split(split(hbid,"#")[1],"_")[1]," ")[0],"/","0-2") else 'NA' end

Hope it helps!!

Re: CASE statement Error in Beeline HIVE

Hi @Gayathri Devi

sample nested case which can be used in hive.

Select case 
when hour(split(split(hbid,"#")[1],"_")[1])== 0 then concat(split(split(split(hbid,"#")[1],"_")[1]," ")[0],"/","0-2") 
when hour(split(split(hbid,"#")[1],"_")[1]) ==1 then concat(split(split(split(hbid,"#")[1],"_")[1]," ")[0],"/","0-2")]
when hour(split(split(hbid,"#")[1],"_")[1]) ==2 then concat(split(split(split(hbid,"#")[1],"_")[1]," ")[0],"/","2-4")]
when hour(split(split(hbid,"#")[1],"_")[1]) ==2 then concat(split(split(split(hbid,"#")[1],"_")[1]," ")[0],"/","2-4")]
when hour(split(split(hbid,"#")[1],"_")[1]) ==3 then concat(split(split(split(hbid,"#")[1],"_")[1]," ")[0],"/","2-4")]
else 'NA'
end as column1 from table_name; 

If it helps then please accept it as the best answer! Happy Hadooping!!

Re: CASE statement Error in Beeline HIVE

New Contributor

Will Try and let u know. thanks a lot.