首页 > 技术文章 > hive搜索语句总结

wfswf 2021-10-10 23:29 原文

1.排序order by(在使用order by的时候必须要指定通过那一列进行排序,其中asc升序(默认),desc为降序):

select * from emp order by sal;
 
2.sort by对每个分区内部进行排序:
首先可以通过  set mapreduce.job.reduces=3; 设置分区数,这里是将分区数设置为3,然后可以通过set mapreduce.job.reduces;来查看当前分区的个数。
select * from emp sort by deptno desc;
上面语句的执行结果就是对每个分区的数据进行排序,整体数据局部有序;
 
3.distribute by 进行将指定行分配到指定分区,其中distribute by 的分区规则是根据分区字段的 hash 码与 reduce 的个数进行模除后,余数相同的分到一个区。
select * from emp distribute by deptno sort by empno desc;
 
4.Cluster By,当 distribute by 和 sorts by 字段相同时,可以使用 cluster by 方式,但是排序只能是升序,不能指定排序规则为 ASC 或者 DESC。
select * from emp cluster by deptno;
 
5.修改hive表中某一列的列名:
alter table dept change column deptdesc desc string;
 
6.修改表名:
alter table dept_partition2 rename to dept_partition3;

推荐阅读