Hive中近似计算Histogram的验证

简介:

Histogram可以更直观的反映数据的分布情况,有了Histogram就可以对执行参数和执行计划有着更有针对性的优化。但想要得到准确的Histogram,需要巨大的计算量。如果能近似得到相对准确Histogram,就会变得很有价值。
目前HIVE中实现了针对Numeric的近似的Histogram的计算逻辑。NumericHistogram的实现说明如下:

/**
 * A generic, re-usable histogram class that supports partial aggregations.
 * The algorithm is a heuristic adapted from the following paper:
 * Yael Ben-Haim and Elad Tom-Tov, "A streaming parallel decision tree algorithm",
 * J. Machine Learning Research 11 (2010), pp. 849--872. Although there are no approximation
 * guarantees, it appears to work well with adequate data and a large (e.g., 20-80) number
 * of histogram bins.
 */

感兴趣的可以参考论文,“A streaming parallel decision tree algorithm”。

我简单的测试了下:

package sunwg.test;

public class testHis {

    public static void main(String[] args) {

        NumericHistogram numericHistogram = new NumericHistogram();
        numericHistogram.allocate(10);
        
        for (double i=1.0; i<=50.0; i++) {
            numericHistogram.add(i);
        }
                
        System.out.println(Math.round(numericHistogram.quantile(0.1)));
        System.out.println(Math.round(numericHistogram.quantile(0.2)));
        System.out.println(Math.round(numericHistogram.quantile(0.3)));
        System.out.println(Math.round(numericHistogram.quantile(0.4)));
        System.out.println(Math.round(numericHistogram.quantile(0.5)));
        System.out.println(Math.round(numericHistogram.quantile(0.6)));
        System.out.println(Math.round(numericHistogram.quantile(0.7)));
        System.out.println(Math.round(numericHistogram.quantile(0.8)));
        System.out.println(Math.round(numericHistogram.quantile(0.9)));
        System.out.println(Math.round(numericHistogram.quantile(1.0)));
}

结果如下:

3
8
12
18
24
29
33
38
42
48

基本上还是挺靠谱的,如果想提高准确率,可以增加num_bins的个数,也就是上面的10。

numericHistogram.allocate(10);

并且,NumericHistogram也支持多个partial Histogram的merge操作。

之所以要看这些内容,主要希望数据集成可以通过对数据的研究,获得数据的特征,选择更合适的splitpk,将任务可以拆分得更加平均,减少长尾task,也把用户从优化中解放出来。

目录
相关文章
|
5天前
|
SQL 分布式计算 数据处理
【Hive】请说明hive中 Sort By,Order By,Cluster By,Distrbute By各代表什么意思?
【4月更文挑战第17天】【Hive】请说明hive中 Sort By,Order By,Cluster By,Distrbute By各代表什么意思?
|
5月前
|
SQL HIVE
51 Hive的Load操作
51 Hive的Load操作
56 0
|
7月前
|
SQL HIVE 数据安全/隐私保护
Hive整合Hue组件使用
Hive整合Hue组件使用
91 0
|
存储 SQL 算法
Hive-加载数据与数据null值处理
本文讲述了实战中Hive加载业务数据基础全过程,以及加载数据的null值处理。这是一篇讲述了比较简单的案例,后面会分享其他实战经验。
Hive-加载数据与数据null值处理
|
SQL HIVE
hive查询的相关示例
hive查询的相关示例
|
SQL 分布式计算 负载均衡
hive 参数设置大全
hive 参数设置大全
|
SQL 分布式计算 HIVE
Hive----优化参数
优化参数
366 0
|
SQL 分布式计算 Hadoop
Hive Tips
在Hive中,某些小技巧可以让我们的Job执行得更快,有时一点小小的改动就可以让性能得到大幅提升,这一点其实跟SQL差不多。 首先,Hive != SQL,虽然二者的语法很像,但是Hive最终会被转化成MapReduce的代码去执行,所以数据库的优化原则基本上都不适用于 Hive。
1405 0
|
SQL HIVE 索引
Hive优化相关设置
Hive优化相关设置
1436 0

热门文章

最新文章