如何计算 Impala 查询中的 NaN 项?

问题描述 投票:0回答:3

我有一个表,在一个双精度字段中有“NaN”。我只是想计算有多少项目是“NaN”:

Select count(*) from table
where col = 'NaN'

AnalysisException:DOUBLE 和 STRING 类型的操作数不可比较:col = 'NaN'

Select count(*) from table
where col is null

Result = 0(顺便说一句,此列中有大量 NaN 记录)

Select count(*) from table
where cast(col as string) = 'NaN'

结果 = 0

我如何在实际计算 NaN 行的地方执行此操作?

hdfs nan cloudera impala
3个回答
0
投票

我会将 NaNs 转换为字符串,然后与

'nan'

进行比较
Select count(*) from table
where cast(col as string) = 'nan'

0
投票

可以使用is_nan函数

select count(*) from table
where is_nan(col)

0
投票

计算方式略有不同..

select sum(if(is_nan(column_name), 1, 0)) as nan_count, count(column_name) AS total_count
from table_name;
© www.soinside.com 2019 - 2024. All rights reserved.