Hadoop 配置单元中的空检查

Hadoop 配置单元中的空检查,hadoop,hive,Hadoop,Hive,我在蜂箱查询中遇到了一个奇怪的行为。根据输入参数插入值时,我将属性设置为NULL。当我执行count时 select count(id) from hive_table where val1 is NULL; 结果我得到了0。但我知道大约有7.5k条记录被设置为空。而下面的查询将返回准确的结果 select count(id) from hive_table where trim(val1) is NULL; 我使用的是ApacheHive版本1.2和Hortonworks Hadoop 2

我在蜂箱查询中遇到了一个奇怪的行为。根据输入参数插入值时,我将属性设置为NULL。当我执行count时

select count(id) from hive_table where val1 is NULL;
结果我得到了0。但我知道大约有7.5k条记录被设置为空。而下面的查询将返回准确的结果

select count(id) from hive_table where trim(val1) is NULL;

我使用的是ApacheHive版本1.2和Hortonworks Hadoop 2.7。了解发生这种情况的原因。

count
忽略
null
值,这就是将
0
作为输出的原因。你应该改为数行

select count(*) from hive_table where val1 is NULL;
编辑:我假设您将空字符串解释为
null
s。试试这个来检查

select sum(cast(trim(val1)='' as int)) as empty_str_count
,sum(cast(val1 is null as int)) as null_count
from hive_table 

我不知道为什么第二个有效。但如果要计算
NULL
值,请使用:

select count(*)
from hive_table
where val1 is NULL;

您可以尝试另一种方法从配置单元中查找空记录计数

select count(id) from hive_table where length(val1)=0;

实际上,计数是在id上的,id不是空的。我的坏消息在第一次编辑中漏掉了。你是如何插入NULL的?你说“我将属性设置为NULL”,请将此代码显示为val1。。。