ARRAY
数组类型,取值:列名[index],取长度size(列名)
MAP
键-值对元组集合,使用数组表示法可以访问数据。例如,如果某个列的数据类型是MAP,其中键->值对是’first’->’John’和’last’->’Doe’,那么可以通过字段名[‘last’]获取最后一个元素
STRUCT
和java中的javaBean类似,都可以通过“点”符号访问元素内容。例如,如果某个列的数据类型是STRUCT{first STRING, last STRING},那么第1个元素可以通过字段.first来引用。
示例:
假设某表有如下一行,我们用JSON格式来表示其数据结构。在Hive下访问的格式为
{"name": "songsong","friends": ["bingbing" , "lili"] , //列表Array, "children": { //键值Map,"xiao song": 18 ,"xiaoxiao song": 14}"address": { //结构Struct,"street": "hui long guan" ,"city": "beijing" }
}
转换为本地数据 test.txt
songsong,bingbing_lili,xiao song:18_xiaoxiao song:19,hui long guan_beijing
yangyang,caicai_susu,xiao yang:18_xiaoxiao yang:19,chao yang_beijing
创建测试表导入数据:
create table test(
name string,
friends array<string>,
children map<string, int>,
address struct<street:string, city:string>
)
row format delimited fields terminated by ','
collection items terminated by '_'
map keys terminated by ':'
lines terminated by '\n';