hive的case when then和cast

记录一个因为本人弱智脑子不清醒导致搞了很长时间的bug:写hive sql的时候,把cast写成了case,还神奇的一直没有发现,在积极百度查报错原因╮(╯▽╰)╭

hive的case when then和cast

这里记录下两个方法的用法,来涨涨记性!

cast

用法

CAST(<timestamp/date> AS <varchar/char/string> [FORMAT <template>])
CAST(<varchar/char/string> AS <timestamp/date> [FORMAT <template>])

示例

select cast(dt as string format 'DD-MM-YYYY')
select cast('01-05-2017' as date format 'DD-MM-YYYY')
case when then

CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END

当a = b时,返回c;当a = d时,返回e; 否则返回f。

CASE WHEN a THEN b [WHEN c THEN d]* [ELSE e] END

当a = true时,返回b; 当c = true时,返回d; 否则返回e。

 hive的case when then和cast

hive的case when then和cast 

hive的case when then和cast

cast:https://blog.****.net/xiaoshunzi111/article/details/54343291/

case when:https://blog.****.net/ygdlx521/article/details/71156354