• HQL之动态分区调整


    动态分区插入可以基于查询语句分出出要插入的分区名称。比如,下面向分区表插入数据的SQL:

    insert into table chavin.emp_pat partition(dname,loc)

    select e.empno,e.ename,e.job,e.mgr,e.hiredate,e.sal,e.comm,e.deptno,d.dname,d.loc

    from dept d join emp e on d.deptno=e.deptno;

    hive会根据select字段的最后两个字段确定分区字段的值(上面sql中即根据d.dname,d.loc的值确定partition(dname,loc)中dname和loc的值),分区字段值的确定是根据位置而不是根据内容确定的,这点尤其需要注意。当然,对于多分区表的插入,可以混合使用静态分区和动态分区的方法,并且静态分区字段必须出现在动态分区字段之前,如下:

    insert into table chavin.emp_pat partition(dname=' NEW YORK',loc)

    select e.empno,e.ename,e.job,e.mgr,e.hiredate,e.sal,e.comm,e.deptno,d.dname,d.loc

    from dept d join emp e on d.deptno=e.deptno

    where d.dname=' NEW YORK';

    针对于hive 0.13.1版本,动态分区插入默认是开启的,但是默认是以strict模式执行。在strict模式下,要求至少有一个分区字段是静态分区字段。

    hive动态分区插入的一些属性如下:

    hive (chavin)> set hive.exec.dynamic.partition;

    hive.exec.dynamic.partition=true

    --true表示开启动态分区插入功能。

    hive (chavin)> set hive.exec.dynamic.partition.mode;

    hive.exec.dynamic.partition.mode=strict

    --设置为nonstrict模式,表示所有分区都可以是动态分区字段。

    hive (chavin)> set hive.exec.max.dynamic.partitions.pernode;

    hive.exec.max.dynamic.partitions.pernode=100

    --每个mapper或reduce任务可以创建的最大分区数,如果mapper或reduce任务创建了比这个值大的分区数,则抛出致命错误。

    hive (chavin)> set hive.exec.max.dynamic.partitions;

    hive.exec.max.dynamic.partitions=1000

    --一个动态分区创建语句可以创建的最大动态分区数,如果创建数量超过这个值,则抛出致命错误。

    hive (chavin)> set hive.exec.max.created.files;    

    hive.exec.max.created.files=100000

    --全局可以创建的最大文件个数,有一个全局hadoop计数器会跟踪记录创建的文件数,如果超过了限制值则抛出致命错误信息。

    hive (chavin)> set dfs.datanode.max.xcievers;

    dfs.datanode.max.xcievers=4096

    --datanode参数,配置在hdfs-site.xml中,表示一次可以打开的最大文件个数。

    如下是动态分区插入的一个小例子:

    1)创建分区表:

    create table chavin.EMP_pat

    (

    EMPNO    int,

    ENAME    string,

    JOB      string,

    MGR      int,

    HIREDATE string,

    SAL      float,

    COMM     float,

    DEPTNO   int

    ) partitioned by(dname string,loc string)

    row format delimited fields terminated by ' ';

    2)设置动态分区参数,向分区表插入数据:

    set hive.exec.dynamic.partition=true;

    set hive.exec.dynamic.partition.mode=nonstrict;

    set hive.exec.max.dynamic.partitions.pernode=100;

    insert into table chavin.emp_pat partition(dname,loc)

    select e.empno,e.ename,e.job,e.mgr,e.hiredate,e.sal,e.comm,e.deptno,d.dname,d.loc

    from dept d join emp e on d.deptno=e.deptno;

  • 相关阅读:
    leetcode------Clone Graph
    leetcode------Anagrams
    leetcode------Simplify Path
    leetcode------Number of Islands
    leetcode------3Sum Closest
    leetcode------4Sum
    leetcode------3Sum
    leetcode------Binary Tree Right Side View
    leetcode------Word Break
    leetcode------House Robber
  • 原文地址:https://www.cnblogs.com/wcwen1990/p/7601256.html
Copyright © 2020-2023  润新知