使用impala查询引擎的时候,如果count(disticnt column)数据量过大会报错,报错内容
正在提取遇到以下错误的结果:
(370) Query analysis error occurred during query execution: [HY000] : AnalysisException: all DISTINCT aggregate functions need to have the same set of parameters as count(DISTINCT a.udid_); deviating function: count(DISTINCT a.ip_)
Consider using NDV() instead of COUNT(DISTINCT) if estimated counts are acceptable. Enable the APPX_COUNT_DISTINCT query option to perform this rewrite automatically.
. Error 370. SQLSTATE HY000
简单来说就是count(distinct column)让你换成NDV(column),换了之后查询会快很多,
如果想正常使用count()需要设置参数,
官方文档:
set APPX_COUNT_DISTINCT=true;
NDV功能
一个聚合函数,返回一个类似于COUNT(DISTINCT col )结果的近似值,即“不同值的数量” 。 它比COUNT和DISTINCT的组合快得多,并且使用恒定的内存量,因此对于具有高基数的列而言,内存密集度较低。
句法:
NDV([DISTINCT | ALL] expression )
使用说明:
这是COMPUTE STATS语句