1.4.6、判断函数
1.4.6.1、if
select if(1=1,'a','b'),if(1=2,'a','b') ;

1.4.6.2、isnull
select isnull(1),isnull(null);

1.4.6.3、isnotnull
select isnotnull(1),isnotnull(null);

1.4.6.4、nvl
select nvl(1,1),nvl(null,1);

1.4.6.5、coalesce
select coalesce(1,null,2,3,null,4,null),coalesce(null,null,null,2,3,4),coalesce(null,null,null,null);

1.4.6.6、case when
select case when 1=1 then '1' else 'b' end ,case when 1=1 then '1' end;

1.4.6.7、nullif -->Hive2.3.0
1.4.6.8、assert_true --> Hive0.8.0
select assert_true(1=1),assert_true(1=2);

支持版本 | 返回值类型 | 函数名称 | 功能描述 |
T | if(boolean testCondition, T valueTrue, T valueFalseOrNull) | 当 testCondition 为真时返回 valueTrue,否则返回 valueFalseOrNull | |
boolean | isnull( a ) | 如果 a 为 NULL,则返回 true,否则返回 false。 | |
boolean | isnotnull ( a ) | 如果 a 不是 NULL,则返回 true,否则返回 false。 | |
T | nvl(T value, T default_value) | 如果值为 null 则返回默认值,否则返回值(从 Hive 0.11 开始) | |
T | COALESCE(T v1, T v2, ...) | 返回第一个不是 NULL 的 v,如果所有 v 都是 NULL,则返回 NULL。 | |
T | CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END | 当 a = b 时,返回 c;当 a = d 时,返回 e;否则返回 f | |
T | CASE WHEN a THEN b [WHEN c THEN d]* [ELSE e] END | 当 a = true 时,返回 b;当 c = true 时,返回 d;否则返回 e。 | |
Hive2.3.0 | T | nullif( a, b ) | 如果 a=b,则返回 NULL;否则返回一个(从 Hive 2.3.0 开始)。简写:CASE WHEN a = b then NULL else a |
Hive0.8.0 | void | assert_true(boolean condition) | 如果“条件”不为真,则抛出异常,否则返回 null(从 Hive 0.8.0 开始)。例如,选择 assert_true (2<1) |