导入将本地数据导入hive
load data local inpath ‘/root/tes.txt’ into table 数据库.表;
将hdfs集群导入到hive
load data inpath ‘hdfs://node01:9000/user/tes.txt’ into table 数据库.表;
HIve分区表(静态分区,动态分区)
静态分区:
必须在表定义时指定对应的partition字段-----分区字段一定不能与表中字段重复
1.单分区建表
单分区的表添加数据
类似多分区:
create table hour(id int, content string) partitioned by (dt int, hour int);
分区在hdfs中查看的时候是一文件夹的形式存在的。多分区的存在形式 就会类似/dt/hour的文件夹
增加多分区是
alter table hour add partition(dt=10,hour=40);
删除分区的是
alter table tablename drop partition (sex=‘boy’)
动态分区:在数据多了之后会自动进行简单的分区
需要现在/conf/hive-site.xml添加配置
配置完成之后
动态分区之后添加数据的也可以使用
from a //已经存在的表格并且要有数据
insert overwrite table b partiton (age,sex) overwrite 是在表里覆盖数据 into是追加数据
select * distribute by age,sex
Hive分桶表
在上面的分桶表也已经将分桶开启了,在这就可以直接使用了
创建分桶表
添加数据
insert into table b select id,name from a
按照分桶来找出桶里面的数据
作者:十五亿少女的心
来源:CSDN
原文:https://blog.csdn.net/sksea99/article/details/93121479
版权声明:本文为博主原创文章,转载请附上博文链接!