大数据之hive表操作

 

hive安装

 



1,xuhaitao,36
2,hunkxu,63
3,zhouwa,13

 create table biao001(id int,name string,age int) row format delimited fields terminated by ',';

034,1:2:3:4
035,5:6
036,7:8:9:10

 create table class_test(name string, student_id_list array<INT>)
 ROW FORMAT DELIMITED 
 FIELDS TERMINATED BY ','
 COLLECTION ITEMS TERMINATED BY ':';

  

 或者使用下面命令查询list中指定索引值

 select   likes[1]  from table03;

注意下面的空格是tab键的空格,而非空格键的空格

xuhaitao        唱歌,跳舞
hunkxu  练武,写代码

 create table table03(name string,likes array<string>)
 ROW FORMAT DELIMITED
 FIELDS TERMINATED BY '\t'
 COLLECTION ITEMS TERMINATED BY ',';

 


分区表,注意分区表的字段一定不能够在表中存在


create table tb01(id int,city  string) partitioned by (country string)  row format 
delimited fields terminated by ',';

准备两批数据,,分别是1.txt和2.txt


1.txt

1,郑州
2,信阳
3,洛阳

 

 分区表,必须使用load加载数据

load data local  inpath '/1.txt' into table tb01  partition (country='henan');

 

 

 


 接着加载第二段数据

1,深圳
2,珠海
3,广州

load data local inpath '/2.txt' into table tb01  partition (country='guangdong');

 

 


分桶表,注意分桶表中字段必须是表中存在的


 做分桶需要打开分桶开关,默认是关着的 

set hive.enforce.bucketing =true;
set mapreduce.job.reduces=4;

 


 创建一个桶表

create table stu_bucket (bianhao int ,name string,sex string ,age int )
clustered by (bianhao)
into 4 buckets
row format delimited 
fields  terminated by ',';

还需要准备一张临时表

create table stu (bianhao int ,name string,sex string ,age int )
row format delimited 
fields  terminated by ',';

下面准备一些分桶数据 students.txt

22,xuhaitao,nan,30
24,hunkxu,nan,25
25,xiaoxu,nan,39
26,xiaotao,nan,40
27,xiaohuan,nan,35
28,xuaishuo,nan,3
29,daiping,nv,46
30,guozhu,nan,49
31,xiaojie,nv,31
32,xxx,nv,19

  将上面数据导入到stu表中

load data local inpath  '/students.txt' into table  stu;

 


 然后执行下面指令进行分桶

    insert overwrite table stu_bucket
    select * from stu cluster by (bianhao);

 


 

 

FR:徐海涛(hunk Xu)
QQ技术交流群:386476712

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值