Hive——集合数据类型

hive的集合数据类型包括三种,分别是Array、Map和Struct    


建表    

create table test
(
    id INT,
    name STRING,
    hobby ARRAY<STRING>,                        //array中元素为String类型
    friend MAP<STRING,STRING>,                  //map中键和值均为String类型
    mark struct<math:int,english:int>           //Struct中元素为Int类型
)
row format delimited fields terminated by ','   //字段之间用','分隔
collection items terminated by '_'              //集合中的元素用'_'分隔
map keys terminated by ':'                      //map中键值对之间用':'分隔
lines terminated by '\n                         //行之间用'\n'分隔
;


load 装载数据    

对于数据量较大,常用的一种方法是通过文件批量导入的方法

文本内容:
        1,xiaoming,basketball_game,xiaohong:yes_xiaohua:no,99_75
        1,xiaohong,watch_study,xiaoming:no_xiaohua:not,95_95
        

load data inpath '/uesr/xiaoming/11.txt' overwrite into table test;
//insert 插入数据 
INSERT INTO test     
        2,    
        'xiaohua',
        array('basketball','read'),
        str_to_map('xiaoming:no,xiaohong:no'),
        named_struct('math',90,'english',90)
from tmp;


查询数据    

select 
    id,
    name,
    hobby[0],                 //查询第一个hobby
    friend['xiaohong'],       //查询map键为xiaohong的value
    mark.math                 //查询struct中math的值
from test 
where name = 'xiaoming';


        
    
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值