hadoop - 如何在Hive中模拟BigQuery的分位数

标签 hadoop apache-spark hive google-bigquery quantile

我想在Hive中模拟BigQuery的QUANTILES函数。

数据集:1,2,3,4

BigQuery的查询结果将返回值2

select nth(2, quantiles(col1, 3))



但是在Hive中:

select percentile(col1, 0.5)



我有2.5

注意:对于奇数个记录,我得到相同的结果。

Hive的udf功能是否足够?

最佳答案

我猜您在寻找的是percentile_approx UDF。

This page为您提供Hive中所有内置UDF的列表。

percentile_approx(DOUBLE col, p [, B])

Returns an approximate pth percentile of a numeric column (including floating point types) in the group. The B parameter controls approximation accuracy at the cost of memory. Higher values yield better approximations, and the default is 10,000. When the number of distinct values in col is smaller than B, this gives an exact percentile value.

关于hadoop - 如何在Hive中模拟BigQuery的分位数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46098725/

相关文章:

hadoop - DataFrame对象未显示任何数据

mysql - Sqoop 语法错误,意外的 tIdentifier

hadoop - 如何关联 RDD 中数组的所有组合?

apache-spark - 将新的拟合阶段添加到现有的 PipelineModel 中而无需再次拟合

sql - HIVE 中的 LIMIT 子句真的是随机的吗?

hadoop - 将运行多少映射器?

apache-spark - KryoSerializer 缓冲区溢出

apache-spark - 压缩 Spark 输出文件

hadoop - Hive 改变 serde 属性不起作用

hadoop - 默认情况下,HIVE 元数据存储在哪里?