处理配置单元上的空值

use*_*713 3 hadoop hive

我在hive中有一个类型为double的列,但是当我这样做时,有些行是NULL:

select columnA from table;
Run Code Online (Sandbox Code Playgroud)

现在,如果我运行以下命令,则两个查询都得到0:

select count(*) from table where columnA = "NULL";
select count(*) from table where columnA = NULL;
Run Code Online (Sandbox Code Playgroud)

如何计算我的表中的行为NULL?

Ola*_*laf 6

正确的查询是:

select count(*) from table where columnA is null;
Run Code Online (Sandbox Code Playgroud)


小智 5

在Hive中,count(*)计算所有行和count(columnA)将仅计算columnA为非NULL的行.如果您想要执行多个列,可以将查询编写为:

select count(*)-count(columnA), count(*)-count(columnB) from table;
Run Code Online (Sandbox Code Playgroud)

并获取每列中的空值数. https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF