空值字段的hive处理

当遇到某个字段的属性值为空时,可使用IF、ISNULL函数进行处理。函数

hive的IF函数:string

IF(expr1,expr2,expr3) - If expr1 is TRUE (expr1 <> 0 and expr1 <> NULL) then IF() returns expr2; otherwise it returns expr3. IF() returns a numeric or string value, depending on the context in which it is used.it

hive的ISNULL函数:sed

isnull a - Returns true if a is NULL and false otherwisedi

案例:co

某个表的某个字段read_num,字段中可能某个属性值为空/null,能够表示为:return

IF(ISNULL(read_num),0,SUM(read_num))。context

解释:若是read_num为空,则返回值为0,不然返回的结果为:SUM(read_num)。