hive的一些概念 外部表 分区分桶

外部表:create external xxx() location默认创建内部表目录在 /user/hive/warehouse

而外部表创建的时候,需要指定 external 关键字 以及location ,外部表与内部表的区别是 外部表可以创建在

hdfs任一目录下,并且在drop table的时候 数据不会被清除;

分区:指的是在创建表时,指定以那个字段分区,即 表目录下的子目录,比如说按日期分开

create table xxx... partition by input_date ,然后上传数据的时候需要指定input_date 具体的值 ,注意partition by 的字段,是自己想出来的字段,并不需要和源表mysql中的某个字段对应,分区是为了以后查询方便

 

分桶:按照字段 hashcode 桶的数量,为了以后join方便

hive 必须启动yarn 因为要跑mr 

hive建表语法

外部表

create external table test(id int,name string)
 row format delimited fields terminated by '\t'
 stored as textfile
location '/test';

 

分区表

create table test2(id int,name string)

                > partitioned by (input_date string)

                  > row format delimited fields terminated by '\t';

 

load data local inpath 'xxx' into table test partition(input_date='2018')字段是自己另外加的,不能为表中已有的字段

select * from xxx where input_date='2018';partition 子等级  

 

分桶表

create table t_buck(id int,name string)
    clustered by(id)    
    sorted by(id)
    into 4 buckets
    row format delimited fields terminated by ',';

 

 分桶表并不会自动给你创建好分同,即当load 数据进去时,不会创建四个同,分同表不适用在load数据场景,使用在

select 别的表然后group by,load 数据就应该是分好桶的,insert into table xxx partition () select * from test cluster by (id) into t_buck; cluster by =distribute by sort by(可以不同字段) sort by 每个分区有序,根据指定的字段

开启分桶 

#设置变量,设置分桶为true, 设置reduce数量是分桶的数量个数

set hive.enforce.bucketing = true;

set mapreduce.job.reduces=4;

 

hive load data 原理是直接将数据移动到hive所在的hdfs目录 

如果不是外部表 默认在 /user/hive/warehouse 下面

外部表在其指定的目录下 删除外部表则原数据不会被删除

所以就不用 在hive 里面 load 了 很慢

直接 hadoop fs -put xxxx /xxx 即可

 

hive 终端执行 hdfs命令 dfs -ls / .....

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值