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

感谢:

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

https://www.deeplearn.me/1536.html

 动态分区:

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

静态分区:

在对分区表插入数据的时候,通过手动指定全部分区字段的值来把数据插入到确定分区。

动态分区的相关属性:

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

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

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

  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;

1、严格模式

##创建动态分区表

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;

2、非严格模式

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

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参数,使其支持事务

 

 

静态分区和动态分区

 

posted on 2019-06-09 10:34  at_today  阅读(313)  评论(0编辑  收藏  举报

导航