当遇到某个字段的属性值为空时,可以使用IF、ISNULL函数进行处理。
hive的IF函数:
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.
hive的ISNULL函数:
isnull a - Returns true if a is NULL and false otherwise
案例:
某个表的某个字段read_num,字段中可能某个属性值为空/null,可以表示为:
IF(ISNULL(read_num),0,SUM(read_num))。
解释:如果read_num为空,则返回值为0,否则返回的结果为:SUM(read_num)。