【问题标题】:Handling null values on hive处理 hive 上的空值
【发布时间】:2013-08-10 09:32:28
【问题描述】:

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

select columnA from table;

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

select count(*) from table where columnA = "NULL";
select count(*) from table where columnA = NULL;

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

【问题讨论】:

    标签: hadoop hive


    【解决方案1】:

    正确的查询是:

    select count(*) from table where columnA is null;
    

    【讨论】:

    • Olaf,你知道我如何对表中的每一列执行此操作吗?该表有大量列,我宁愿不必为每一列运行一个查询。
    • @user2932774:我没有在 Hive 中尝试过,但在标准 SQL 中,您可以使用“case”。请参阅:stackoverflow.com/questions/12789396/…
    • 感谢您的参考!
    • 但是 columnA = null 代表什么?它不会抛出异常,这表明“columnA = null”至少工作正常。
    【解决方案2】:

    在 Hive 中,count(*) 会计算所有行,而 count(columnA) 只会计算 columnA 为非 NULL 的行。如果您想做多列,可以将查询编写为:

    select count(*)-count(columnA), count(*)-count(columnB) from table;
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-27
      • 1970-01-01
      • 2017-06-05
      相关资源
      最近更新 更多