hive复杂数据类型嵌套

需求:在创建表的时候有一列类型为array<struct:”id”:string,”l”:string>想要自己造数据向表里insert格式应该怎么写呢?
建表语句如下:

CREATE EXTERNAL TABLE `test.test_imp06`(
`exps` array<struct<id:string,l:string>> COMMENT ‘ceshi')
1
2
insert into 的select语句

insert into test.test_imp06
select array(named_struct('id','exp6','l','layer_3'),named_struct('id','exp7','l','layer_6')) as exps
1
2
结果:

还有一种写法如下:

select array(struct('id','exp6','l','layer_3'),struct('id','exp7','l','layer_6')) as exps
1
结果:

两种方法,但是如果使用struct会导致和之前的列名定义的列名无法对应。。最后还是使用name_struct喽
 

-------------------------

Hive 
hive 除了支持基本的数据结构
hive 复杂的数据结构:

{
 array
 map
 struct
}

数据格式

221190xxx9	0401:0.30 0402:0.81 1303:0.23 1502:0.21 1503:0.11 0307:0.17 1003:0.35 	
22119xxxx2	0508:0.58 0402:0.25 0403:0.24 0405:0.30 0503:0.55 1502:0.26 0208:0.29 	
22119xxx63	0405:0.18 0408:0.22 0905:0.89 1503:0.16 0301:0.14 0307:0.12 0208:0.17 

hive 表结构设计:

create table genomeplatform.user_tags (uid string ,tag array<struct<tagid:string,weight:string>>)

ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
COLLECTION ITEMS TERMINATED BY ' '
MAP KEYS TERMINATED BY ':'
STORED AS TEXTFILE;

select :

100xxxx0	[{"tagname":"0101","weight":"0.44"},{"tagname":"1103","weight":"0.90"},{"tagname":"","weight":null}]
100xxxx7	[{"tagname":"0508","weight":"1.00"},{"tagname":"","weight":null}]
100xxxx9	[{"tagname":"1701","weight":"0.79"},{"tagname":"1606","weight":"0.62"},{"tagname":"","weight":null}]
130xxxx9	[{"tagname":"1503","weight":"1.00"},{"tagname":"","weight":null}]

https://wwangcg.iteye.com/blog/1829402

https://www.cnblogs.com/leodaxin/p/9898080.html

https://blog.csdn.net/lykke2012/article/details/84407971

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值