hive中 order by ,distribute by ,cluster by ,sort by 区别

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_18730505/article/details/82761198
id name old
1 张三 10
1 李四 15
3 王五 20
4 赵六 25

 

 假设表中3个字段

order by old 

展现出的数据将会根据old 这一列降序返回4条记录,不具备任何形式的数据分布

select * from table order by old desc

4 赵 25

3 王 20

1 李 15

1 张 10

distribute by 

map reduce 中,map 端将数据按 字段 分布 分发给 reduce  确保 每个reduce 收到的值 是相同的。具备分布的特性

distibute by  id asc 则会将   数据相同的 分发到 一个 reduce 内。具体怎么实现,字段的哈希值/reduce个数   然后取余,余数相同归为一起

sort by

一般 和 distribute 联用,达到分布数据,并按照 指定列进行排序

cluster by 

将数据按照指定列分布后降序 排序分发到各个reduce中

用cluster by 默认指的是 字段 降序 分发,降序排序

例子

select * from table distribute by id sort by id desc

select * from table cluster by id  具备同样效果

--结果

4 赵 25

3 王 20

1 李 15

1 张 10

例子

select * from table cluster by id sort by old asc

--bucket 1

4 赵 25

--bucket 2

3 王 20

1 张 10

1 李 15

猜你喜欢

转载自blog.csdn.net/qq_18730505/article/details/82761198