本文主要是介绍Hive中not in函数的小坑,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Hive中的not in函数有一个隐藏的陷阱,当not in() 中的数值包含NULL,匹不上的数据会返回NULL而不是True。
所以当在where中使用not in子查询进行筛选,一定要记得去除NULL值。
样例代码:
--not in的原始结果
select num,num not in (null,'2'), num not in (null,'2') and true from
(select explode(split('1,2,3,4',',')) as num)t;
--not in 中包含NULL的筛选结果
select num,num not in (null,'2'), num not in (null,'2') and true from
(select explode(split('1,2,3,4',',')) as num)t
where num not in (null,'2') and true;
--not in 中不包含NULL的筛选结果
select num,num not in ('2'),num not in ('2') and true from
(select explode(split('1,2,3,4',',')) as num)t
where num not in ('2') and true;
这篇关于Hive中not in函数的小坑的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!