原文地址:http://www.folkstalk.com/2011/11/conditional-functions-in-hive.html

CONDITIONAL FUNCTIONS IN HIVE

Hive supports three types of conditional functions. These functions are listed below:

IF( Test Condition, True Value, False Value ) 
The IF condition evaluates the “Test Condition” and if the “Test Condition” is true, then it returns the “True Value”. Otherwise, it returns the False Value.
Example: IF(1=1, 'working', 'not working') returns 'working'

COALESCE( value1,value2,... )

The COALESCE function returns the fist not NULL value from the list of values. If all the values in the list are NULL, then it returns NULL.
Example: COALESCE(NULL,NULL,5,NULL,4) returns 5

CASE Statement

The syntax for the case statement is:

CASE  [ expression ]
  WHEN condition1 THEN result1
  WHEN condition2 THEN result2
  ...
  WHEN conditionn THEN resultn
  ELSE result
END

Here expression is optional. It is the value that you are comparing to the list of conditions. (ie: condition1, condition2, ... conditionn).

All the conditions must be of same datatype. Conditions are evaluated in the order listed. Once a condition is found to be true, the case statement will return the result and not evaluate the conditions any further.

All the results must be of same datatype. This is the value returned once a condition is found to be true.

IF no condition is found to be true, then the case statement will return the value in the ELSE clause. If the ELSE clause is omitted and no condition is found to be true, then the case statement will return NULL

Example:

CASE Fruit
  WHEN 'APPLE' THEN 'The owner is APPLE'
  WHEN 'ORANGE' THEN 'The owner is ORANGE'
  ELSE 'It is another Fruit'
END

The other form of CASE is

CASE 
  WHEN Fruit = 'APPLE' THEN 'The owner is APPLE'
  WHEN Fruit = 'ORANGE' THEN 'The owner is ORANGE'
  ELSE 'It is another Fruit'
END

hive 的条件判断(if、coalesce、case)相关推荐

  1. mysql 查询后根据值的不同进行判断与修改,SQL中的条件判断语句(case when zhen)用法

    需求: mysql 查询后根据值的不同进行判断与修改 语法结构: SQL中的条件判断语句(case when zhen)用法 SELECT A.品号,属性,        CASE           ...

  2. 条件判断语句 if case

    条件判断语句 条件测试操作 文件测试 整数值比较 字符串比较 逻辑测试 双分支 if 语句 多分支 if 语句 case 语句 case 变量值 in 条件测试操作 Shell环境根据命令执行后的返回 ...

  3. shell基础--条件判断if和case

    目录 一.条件判断 1.按照文件类型进行判断 2.按照文件权限进行判断 3.两个文件之间进行比较 4.两个整数之间比较 5.字符串的判断 6.多重条件判断 二.if条件判断 1.单分支if条件语句 2 ...

  4. php case 多个条件判断语句,Shell case语句(多分支条件判断)

    case 语句和 if-elif-else 语句一样都是多分支条件语句,不过和多分支 if 条件语句不同的是,case 语句只能判断一种条件关系,而 if 语句可以判断多种条件关系. case 语句的 ...

  5. SQL中的条件判断语句(case when zhen)用法

    简介: case具有两种格式.简单case函数和case搜索函数.这两种方式,可以实现相同的功能.简单case函数的写法相对比较简洁,但是和case搜索函数相比,功能方面会有些限制,比如写判定式.还有 ...

  6. SQL条件判断语句(case when zhen ,isnull)

    case when then 语法: case when 条件 then 值 else 值 end 说明:case函数只返回第一个符合条件的值 示例: create table #check_wl( ...

  7. case zhen语句_SQL中的条件判断语句(case when zhen if,ifnull)用法

    三.IFNULL(expr1,expr2) 仅适用于mysql 假如expr1 不为 NULL,则 IFNULL() 的返回值为 expr1; 否则其返回值为 expr2.IFNULL()的返回值是数 ...

  8. kettle中的switch_kettle 条件判断 Switch Case

    kettle 条件判断 Switch Case kettle 条件判断 Switch Case 介绍 Switch / Case,顾名思义,类似 Java 中的 Switch / Case,用于进行条 ...

  9. mysql 属性函数_4-MySQL函数(字段处理函数条件判断函数)

    一.字段处理函数 字符串处理函数: concat(field1,field2 -- ) substr(str,pos,len) replace(str,old_str,new_str)[Hive:re ...

最新文章

  1. 使用CNN分类签名和文本图像
  2. 044_CSS33D转换
  3. Linux snmp
  4. HttpHelper之我见
  5. JavaScript设计模式—富有表现力的Javascript(一)
  6. Convert to Ones(CF-998C)
  7. 国内主流Android安卓应用市场简介
  8. java调用linux命令
  9. jango web开发指南_Web前端“月薪过万”必读的一些入门书籍和网站!
  10. SVN仓库安装、备份和迁移基本操作
  11. Mac项目流程管理工具:OmniPlan Pro 4.4
  12. 计算机专业毕业设计题目汇总-最新题目 选题 推荐 毕业设计 - 毕设指导 开题报告 论文
  13. Android之阿里云推送实现
  14. 数字小人时钟windows电脑屏幕保护
  15. 我的世界服务器无限繁殖,村民无限繁殖!我的世界自制超速繁殖机
  16. 游戏设计模式-观察者模式
  17. 文件上传黑名单和白名单校验
  18. RxJava过滤操作符 filter
  19. 个人站——作品集页面设计
  20. Region相关算子

热门文章

  1. eclipse安装jsp
  2. java学习(96):线程的睡眠
  3. Mint-Ui的mt-search点击选中
  4. 互联网大佬学历背景大揭秘,看看是你的老乡还是校友
  5. 百度地图gif图标_华为手机误删照片怎么找回?手机怎么快速制作GIF动图
  6. 穿透内网,连接动态ip,内网ip打洞-----p2p实现原理(转)
  7. 各种排序笔记---基于非比较排序部分
  8. HDOJ2567 ( 寻梦 ) 【切水题,很欢乐~】
  9. Multiple annotations found at this line: ---关于android string.xml %问题
  10. LetCode-MSSQL销售分析-I