zoukankan      html  css  js  c++  java
  • hive 排序

    1、全局排序(order by)

    Order by:全局排序,只有一个reducer

    ASC(ascend):升序(默认)

    DESC(descend):降序

    2、每个MR内部排序(sort by)

    sort By:对于大规模的数据集order by的效率非常低。在很多情况下,并不需要全局排序,此时可以使用sort by

    Sort By为每个Reducer产生一个排序文件。每个Reducer内部进行排序,对全局结果集来说不是排序。

    (1)设置reduce个数

    hive (default)> set mapreduce.job.reduces=3;
    

    (2)根据部分编号降序查看员工信息

    hive (default)> select * from emp sort by empno desc;
    

    3、分区排序(Distribute By)

    Distribute By:在某些情况下,我们需要控制某个特定行应该到哪个Reducer,通常是为了后续的聚集操作。

    Distribute by类似MR中partition(自定义分区),进行分区,结合sort by使用

    测试时要分配多个reduce进行处理,否则无法看到Distribute by的效果

     set mapreduce.job.reduces=3;
    

    注意:

    • Distribute by的分区规则是根据分区字段的hashcode与reduce的个数进行取模后,余数相同的分到一个区
    • hive要求Distribute by语句要写在sort by语句之前

    4、cluster by

    当Distribute by 和sort by 字段相同时,可以使用cluster by 方式

    cluster by除了具有distribute by的功能外还兼具sort by的功能。但是排序只能是升序排序,不能指定排序规则为ASC或者DESC。

    1)以下两种写法等价

    hive (default)> select * from emp cluster by deptno;
    
    hive (default)> select * from emp distribute by deptno sort by deptno;
    
  • 相关阅读:
    代理支持
    CGI
    SSI(服务器端嵌入)
    SSL/TLS 配置
    JSPs
    类加载机制
    JDBC 数据源
    安全管理
    Realm 配置
    Js将序列化成Json格式后日期(毫秒数)转成日期格式
  • 原文地址:https://www.cnblogs.com/hyunbar/p/11728550.html
Copyright © 2011-2022 走看看