hadoop生态--Hive(4)--Hive分区中的动态分区、静态分区

感谢:html

http://bbs.elecfans.com/jishu_1600211_1_1.htmlnode

https://www.deeplearn.me/1536.html服务器

 动态分区:app

在对分区表插入数据时,不指定(或不所有指定)分区字段的值,数据会插入到哪一个分区由数据自身值决定。ui

静态分区:spa

在对分区表插入数据的时候,经过手动指定所有分区字段的值来把数据插入到肯定分区。code

动态分区的相关属性:

hive.exec.dynamic.partition=true :是否容许动态分区orm

hive.exec.dynamic.partition.mode=strict :分区模式设置htm

  strict:最少须要有一个是静态分区blog

  nostrict:能够所有是动态分区

hive.exec.max.dynamic.partitions=1000 :容许动态分区的最大数量

hive.exec.max.dynamic.partitions.pernode =100 :单个节点上的mapper/reducer容许建立的最大分区

动态分区的操做

##建立临时表

create table if not exists tmp(uid int,commentid bigint,recommentid bigint,year int,month int,day int)
row format delimited fields terminated by '\t';

##临时表加载数据

load data local inpath '/root/Desktop/comm' into table tmp;

一、严格模式

##建立动态分区表

create table if not exists dyp1(uid int,commentid bigint,recommentid bigint)
partitioned by(year int,month int,day int)
row format delimited fields terminated by '\t';

##向动态分区表中插入数据--严格模式

insert into table dyp1 partition(year=2016,month,day)
select uid,commentid,recommentid,month,day from tmp;

二、非严格模式

##设置非严格模式动态分区

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

##建立动态分区表

create table if not exists dyp2(uid int,commentid bigint,recommentid bigint)
partitioned by(year int,month int,day int)
row format delimited fields terminated by '\t';

##为非严格模式动态分区加载数据

insert into table dyp2 partition(year,month,day)
select uid,commentid,recommentid,year,month,day from tmp;
 

分区注意细节

(1)、尽可能不要用动态分区,由于动态分区的时候,将会为每个分区分配reducer数量,当分区数量多的时候,reducer数量将会增长,对服务器是一种灾难。

(2)、动态分区和静态分区的区别,静态分区无论有没有数据都将会建立该分区,动态分区是有结果集将建立,不然不建立。

(3)、hive动态分区的严格模式和hive提供的hive.mapred.mode的严格模式。

hive提供咱们一个严格模式:为了阻止用户不当心提交恶意hql

hive.mapred.mode=nostrict : strict

若是该模式值为strict,将会阻止如下三种查询:

(1)、对分区表查询,where中过滤字段不是分区字段。

(2)、笛卡尔积join查询,join查询语句,不带on条件或者where条件。

(3)、对order by查询,有order by的查询不带limit语句。

 

 

 

 

 

 

 

全部事务自动提交

指支持orc格式

使用bucket表

配置hive参数,使其支持事务

 

 

静态分区和动态分区

相关文章
相关标签/搜索