hive 中复杂类型的使用

hive 中的复杂类型包括 array(数组)、map(字典)、struct(结构体)等,下面分别介绍。

  • array 
1. 创建临时表
hive -e "use dataalgo; create table cb_array_test(citeid int, order_id_list array<int>) row format delimited fields terminated by '\t' collection items terminated by ','";
2. 写入数据 cat cb_array_test.txt
1 1,2,3 2 4,5,6 3 7,8,9 hive -e "use dataalgo; load data inpath '/tmp/cb_array_test.txt' overwrite into table cb_array_test"
3. 测试结果 hive
-e "use dataalgo; select * from dataalgo.cb_array_test" 1 [1,2,3] 2 [4,5,6] 3 [7,8,9]

 

  • struct
1. 创建临时表
hive -e "use dataalgo; drop table if exists cb_test; create table cb_test(id int, name struct<first:string, last:string>) row format delimited fields terminated by '\t' collection items terminated by ':' "
2. 写入数据 cat struct.txt
1 'a':'a' 1 'b':'b' 1 'c':'c' 1 'd':'d' hive -e "use dataalgo; load data inpath '/tmp/struct.txt' overwrite into table cb_test"
3. 测试结果 hive
-e "use dataalgo; select * from cb_test"
1 {"first":"'a'","last":"'a'"}
1 {"first":"'b'","last":"'b'"}
1 {"first":"'c'","last":"'c'"}
1 {"first":"'d'","last":"'d'"}
  • map
1. 创建临时表
hive -e "use dataalgo; drop table if exists cb_test_map; create table cb_test_map(id int, name map<string, string>) row format delimited fields terminated by '\t' collection items terminated by ',' map keys terminated by ':'"

2. 写入数据 cat cb_map_test.txt
1   a:a,b:b
2   c:c,d:d
3   e:e,f:f hive
-e "use dataalgo; load data inpath '/tmp/cb_map_test.txt' overwrite into table cb_test_map"

3. 测试结果
hive -e "use dataalgo; select * from cb_test_map"
1 {"a":"a","b":"b"}
2 {"c":"c","d":"d"}
3 {"e":"e","f":"f"}

 

转载于:https://www.cnblogs.com/cbffr/p/4955692.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值