hive 的条件判断(if、coalesce、case)

原文地址: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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/423768.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

黑盒测试方法揭密

一、黑盒测试在快速应用开发(rad)环境中的重要作用软件测试方法一般分为两种:白盒测试与黑盒测试。其中,白盒测试又称为结构测试、逻辑驱动测试或基于程序本身的测试,着重于程序的内部结构及算法,通常不关心…

mybatis学习(39):动态sql片段

目录结构 com.geyao.mybatis.mapper BlogMapper类 package com.geyao.mybatis.mapper;import java.util.List; import java.util.Map;import org.apache.ibatis.annotations.Param;import com.geyao.mybatis.pojo.Blog;public interface BlogMapper {Blog selectBlog(Integer…

自定义Flume拦截器,并将收集的日志存储到Kafka中(案例)

1.引入POM文件 如果想调用Flume&#xff0c;需要引入flume相关的jar包依赖&#xff0c;jar包依赖如下&#xff1a; <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://…

中国古代十三美男

一、潘安    潘岳&#xff0c;就是人所周知的潘安&#xff0c;西晋时河南人氏&#xff0c;表字安仁&#xff0c;小字檀奴。其人“姿容既好&#xff0c;神情亦佳”。潘岳年轻时&#xff0c;坐车到洛阳城外游玩&#xff0c;当时不少妙龄姑娘见了他&#xff0c;都会怦然心动给他…

名诗

一&#xff0c;《江城子》 苏轼十年生死两茫茫&#xff0c;不思量&#xff0c;自难忘。千里孤坟&#xff0c;无处话凄凉。纵使相逢应不识&#xff0c;尘满面&#xff0c;鬓如霜。夜来幽梦忽还乡&#xff0c;小轩窗&#xff0c;正梳妆。相顾无言&#xff0c;惟有泪千行。料得年年…

mybatis学习(40):逆向工程的创建

目录 首先导入我们的jar包 链接&#xff1a;https://pan.baidu.com/s/1Ent3kAwOagOZLT0XxDLEeA 提取码&#xff1a;zqpu 建立一个com.geyao.generator的包 generator的java类 package com.geyao.generator; import java.io.File; import java.util.*;import org.mybatis.ge…

SpringBoot中Tomcat配置(学习SpringBoot实战)

1、Tomcat配置 Spring Boot默认内嵌的Tomcat为Servlet容器&#xff0c;所以本节只讲对Tomcat配置&#xff0c;其实本节的配置对Tomcat、Jetty和Undertow都是通用的。 1.1 配置Tomcat 关于Tomcat的所有属性都在org.springframework.boot.autoconfigure.web.ServerProperties配…

axios的数据请求方式及跨域

express 的三大功能&#xff1a;静态资源、路由、模板引擎 app.use(express.static(www));  只要是创建这个静态的目录&#xff0c;这个 www 的静态目录里面的文件就可以被访问 数据的请求方式 axios get 的 请求方式    axios.get(url地址).then(function(success){  //…

WIN server 2003 下无法安装adobe cs3 终极解决方法。

WIN server 2003 下无法安装adobe cs3 当试变了网上的方法还是无法解决时&#xff0c;终极解决方法首先在微软下载一个工具ApplicationVerifier 下载地址在&#xff1a;http://www.microsoft.com/downloads/details.aspx?FamilyIDbd02c19c-1250-433c-8c1b-2619bd93b3a2&Di…

mybatis学习(41):使用逆向工程

新建一个项目&#xff0c;将逆向工程的生成的拷贝进来 配置文件 log4j.properties ### \u914D\u7F6E\u6839 ### log4j.rootLogger debug,console ,fileAppender,dailyRollingFile,ROLLING_FILE,MAIL,DATABASE### \u8BBE\u7F6E\u8F93\u51FAsql\u7684\u7EA7\u522B\uFF0C\u5176…

CentOS 7.2.1511 x64下载地址

CentOS 7.2.1511 x64下载地址 http://kuai.xunlei.com/d/5P9QCQKLGABYmIJW510 #快传关闭&#xff0c;下载链接已经失效 #百度网盘下载 http://pan.baidu.com/s/1jItqJ8y http://pan.baidu.com/s/1kVS08Ph CentOS-7-x86_64-DVD-1511.iso CentOS-7-x86_64-Everything-1…

[Alg] 二叉树的非递归遍历

1. 非递归遍历二叉树算法 (使用stack) 以非递归方式对二叉树进行遍历的算法需要借助一个栈来存放访问过得节点。 (1) 前序遍历 从整棵树的根节点开始&#xff0c;对于任意节点V&#xff0c;访问节点V并将节点V入栈&#xff0c;并判断节点V的左子节点L是否为空。若L不为空&#…

[c++]访MSN浮出窗口的示例

【声明】严格来讲&#xff0c;这篇文章不属于我的原创。我在这里参考了codeproject上的国外作者的模仿MSN浮出窗口的C#代码。换句话说&#xff0c;可以认为我把C#代码翻译成了C代码。另外&#xff0c;为了简化代码&#xff0c;CloseButton我没有采用自己绘制&#xff0c;而是用…

python 读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal multib

python 读取文件时报错UnicodeDecodeError: gbk codec cant decode byte 0x80 in position 205: illegal multibyte sequence python读取文件时提示"UnicodeDecodeError: gbk codec cant decode byte 0x80 in position 205: illegal multibyte sequence" 解决办法1. …

mybatis学习(42):mybatis的一级缓存

目录结构 com.geyao.mybatis.mapper BlogMapper类 package com.geyao.mybatis.mapper;import java.util.List; import java.util.Map;import org.apache.ibatis.annotations.Param;import com.geyao.mybatis.pojo.Blog;public interface BlogMapper {Blog selectBlog(Integer…

linux的nohup命令的用法。

linux的nohup命令的用法。 在应用Unix/Linux时&#xff0c;我们一般想让某个程序在后台运行&#xff0c;于是我们将常会用 & 在程序结尾来让程序自动运行。比如我们要运行mysql在后台&#xff1a; /usr/local/mysql/bin/mysqld_safe –usermysql &。可是有很多程序并不…

防止ASP.NET按钮多次提交的办法

方法一<asp:Button ID"btnSumbit" runat"server" UseSubmitBehavior"false" OnClientClick"this.valueSumbit;this.disabledtrue; " Text"Sumbit" OnClick"btnSumbit_Click" /> 方法二1<html xmlns"…

mybatis学习(43):一级缓存被刷新情况

目录结构 com.geyao.mybatis.mapper BlogMapper类 package com.geyao.mybatis.mapper;import java.util.List; import java.util.Map;import org.apache.ibatis.annotations.Param;import com.geyao.mybatis.pojo.Blog;public interface BlogMapper {Blog selectBlog(Integer…

liunx系统不能登陆的问题

第一装这系统&#xff0c;啥都不懂&#xff0c;设置了密码&#xff0c;好不容易安装完成&#xff0c;竟然不能登陆 有很多人怀疑用户名不是 root&#xff0c; 其实问题是在分配的user 文件夹的空间不足导致的 我在第一次给了3.2G给他&#xff0c;后来我没有自定义了&#xff0c…

提取字典的子集

有时候&#xff0c;需要根据已知的字典对象构造一个新的字典对象。这种场景可以使用字典生成式(dictionary comprehension)。如下&#xff1a; prices {ACME: 45.23,AAPL: 612.78,IBM: 205.55,HPQ: 37.20,FB: 10.75 }# Make a dictionary of all prices over 200 p1 {key: va…