目录
[order by (全局排序asc ,desc)](#order by (全局排序asc ,desc))
[sort by(reduce 内排序)](#sort by(reduce 内排序))
[Distribute by(分区排序)](#Distribute by(分区排序))
[Cluster By(当 distribute by 和 sorts by 字段相同时 ,可以使用 )](#Cluster By(当 distribute by 和 sorts by 字段相同时 ,可以使用 ))
order by (全局排序asc ,desc)
sql
INSERT OVERWRITE LOCAL DIRECTORY '/home/test2'
ROW FORMAT DELIMITED FIELDS TERMINATED by '\t'
select * from emp_partition order by emp_no desc;
sort by(reduce 内排序)
--根据设置的reduce个数,如果是2个reduce,则最少生成2个文件,每个reduce内部排序
--设置reduce个数
set mapred.reduce.tasks; -- (默认 -1 为无限制)
set mapred.reduce.tasks = 2; -- 设置 reduce 个数
sql
INSERT OVERWRITE LOCAL DIRECTORY '/home/test2'
ROW FORMAT DELIMITED FIELDS TERMINATED by '\t'
select * from emp_partition sort by emp_no desc ;
Distribute by(分区排序)
类似于partition,进行分区,只是分成不同文件,文件中没有排序,生成文件受reduce数量影响
一般和sort by一起使用,可以每个分区内排序
sql
INSERT OVERWRITE LOCAL DIRECTORY '/home/test2'
ROW FORMAT DELIMITED FIELDS TERMINATED by '\t'
select * from emp_partition Distribute by gender sort by emp_no desc ;
Cluster By(当 distribute by 和 sorts by 字段相同时 ,可以使用 )
除具有distribute by 的功能,还有 sort by的功能, 但只能升序
sql
INSERT OVERWRITE LOCAL DIRECTORY '/home/test2'
ROW FORMAT DELIMITED FIELDS TERMINATED by '\t'
select * from emp_partition Cluster By emp_no;