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;
————————————————
版权声明:本文为CSDN博主「thelostxxx」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/thelostxxx/article/details/64920020