【问题标题】:HIVE select count(*) non null returns higher value than select count(*)HIVE select count(*) 非 null 返回高于 select count(*) 的值
【发布时间】:2016-10-07 08:27:19
【问题描述】:

我目前正在使用 Hive 进行一些数据探索,但无法解释以下行为。假设我有一个带有 master_id 字段的表(名为 mytable)。

当我计算得到的行数时

select count(*) as c from mytable 
c
1129563

如果我想计算具有非空 master_id 的行数,我会得到更大的数字

select count(*) as c from mytable where master_id is not null
c
1134041

此外,master_id 似乎永远不会为空。

select count(*) as c from mytable where master_id is null
c
0

我无法解释如何添加 where 语句最终会增加行数。有没有人有任何提示来解释这种行为?

谢谢

【问题讨论】:

  • 该表的架构是什么样的?
  • 提供您的表架构

标签: sql hive hiveql hive-configuration


【解决方案1】:

很可能您的查询没有使用统计信息,因为设置了此参数:

set hive.compute.query.using.stats=true;

尝试将其设置为 false 并再次执行。

或者,您可以计算表的统计信息。 见ANALYZE TABLE SYNTAX

还可以在 INSERT OVERWRITE 期间自动收集统计信息:

set hive.stats.autogather=true;

【讨论】:

  • 非常感谢。实际上,如果我将 hive.compute.query.using.stats 设置为 false,则两个计数都匹配。
  • 这是一个值得分析的新东西。很好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多