hive复合数据类型之array
生活随笔
收集整理的這篇文章主要介紹了
hive复合数据类型之array
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
概述
ARRAY:ARRAY類(lèi)型是由一系列相同數(shù)據(jù)類(lèi)型的元素組成,這些元素可以通過(guò)下標(biāo)來(lái)訪問(wèn)。比如有一個(gè)ARRAY類(lèi)型的變量fruits,它是由['apple','orange','mango']組成,那么我們可以通過(guò)fruits[1]來(lái)訪問(wèn)元素orange,因?yàn)锳RRAY類(lèi)型的下標(biāo)是從0開(kāi)始的;
操作實(shí)例
1、創(chuàng)建表
hive> create table array_test(name string,list array<int>) > row format delimited fields terminated by ',' > collection items terminated by ':'; OK
2、準(zhǔn)備文件
[root@hello110 data]# vi ?array_test
zhangsan,1:2:3:4:5
lisi,6:7:8:9:10
xiaoming,11:12:13:14:15
xiaoxiao,21:22:23:24:25
dingding,33:34:35:36:37
3、文件導(dǎo)入表
hive> load data local inpath "/data/array_test" into table array_test; Loading data to table default.array_test
4、查看表
hive> select * from array_test; OK zhangsan [1,2,3,4,5] lisi [6,7,8,9,10] xiaoming [11,12,13,14,15] xiaoxiao [21,22,23,24,25] dingding [33,34,35,36,37] Time taken: 5.293 seconds, Fetched: 5 row(s) ------------- hive> select name from array_test; OK zhangsan lisi xiaoming xiaoxiao dingding Time taken: 4.278 seconds, Fetched: 5 row(s) ----------------- hive> select name,list[1] from array_test; OK zhangsan 2 lisi 7 xiaoming 12 xiaoxiao 22 dingding 34 Time taken: 4.857 seconds, Fetched: 5 row(s) -----------下標(biāo)從0開(kāi)始------------- hive> select name,list[0] from array_test; OK zhangsan 1 lisi 6 xiaoming 11 xiaoxiao 21 dingding 33 Time taken: 4.175 seconds, Fetched: 5 row(s) ---------當(dāng)序號(hào)不存在的時(shí)候返回null------ hive> select name,list[-1] from array_test; OK zhangsan NULL lisi NULL xiaoming NULL xiaoxiao NULL dingding NULL Time taken: 4.195 seconds, Fetched: 5 row(s) --------------------------------- hive> select name,list[100] from array_test; OK zhangsan NULL lisi NULL xiaoming NULL xiaoxiao NULL dingding NULL Time taken: 4.256 seconds, Fetched: 5 row(s) hive>
5、hadoop中文件內(nèi)容
總結(jié)
以上是生活随笔為你收集整理的hive复合数据类型之array的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Thrift介绍与应用(三)—hbase
- 下一篇: jdbc开发优缺点