标签:country table 1.3 field creat 字段 first tab back
Structs: structs内部的数据可以通过DOT(.)来存取,例如,表中一列c的类型为STRUCT{a INT; b INT},我们可以通过c.a来访问域a
Maps(K-V对):访问指定域可以通过["指定域名称"]进行,例如,一个Map M包含了一个group-》gid的kv对,gid的值可以通过M[‘group‘]来获取
Arrays:array中的数据为相同类型,例如,假如array A中元素[‘a‘,‘b‘,‘c‘],则A[1]的值为‘b‘
类型 | 解释 | 举例 |
struct | 与c++中的结构体类似,可通过‘.’访问每个域的值,比如Struct{first string,last string},可以通过name.first访问第一个成员 | struct(‘john‘,‘doe’) |
map | 存储key/value对,可通过[‘key‘]获取每个key的值,比如‘first’-->‘john‘ 可通过name[‘last‘]获取last name。 |
map(‘first‘,‘john‘,last,‘doe‘) |
array | 同种类型的数据集合,从0开始索引,比如[‘john‘,‘doe‘],可通过name[1]获取doe |
array(‘john‘,‘doe‘) |
1.创建数据表
create table test1.employess1( name string, salary FLOAT, subordinates ARRAY<string>, deductions MAP<string,FLOAT>, address STRUCT<stree:string,city:string,state:string,zip:int>) partitioned by(country string,state string) row format delimited fields terminated by ‘\t‘ COLLECTION ITEMS TERMINATED BY ‘,‘ MAP KEYS TERMINATED BY ‘:‘ stored as textfile;
2.测试数据
John Doe 10000.0 Mary Sith,Todd Jones Federal Taxes:0.2,State Taxes:0.1,Insurance:0.1 1 Michigan Ave.,Chicago,IL,60600 Mary Smith 80000.0 Bill King Federal Taxes:0.2,State Taxes:0.05,Insurance:0.1 100 Ontario St.,Chicago,IL,60601 Todd Jones 70000.0 Federal Taxes:0.15,State Taxes:0.03,Insurance:0.1 200 Chicago Ave.,Oak Park,NY,60700 Bill King 60000.0 Federal Taxes:0.15,State Taxes:0.03,Insurance:0.1 300 Obscure Dr.,Obscur,CA,60100
注意一下字段直接的区分标识和map中key和value的区分标识。
3.查询数据
ARRAY查询:
select subordinates[0] from test1.employess1;
结果:
Mary Sith Bill King NULL NULL
MAP查询:
select deductions[‘Federal Taxes‘] from test1.employess1;
结果:
0.2 0.2 0.15 0.15
查看map中的键值对个数:
select size(deductions) from test1.employess1;
结果:
3 3 3 3
STRUCT查询:
select address.state,address.stree from test1.employess1;
结果:
IL 1 Michigan Ave. IL 100 Ontario St. NY 200 Chicago Ave. CA 300 Obscure Dr.
标签:country table 1.3 field creat 字段 first tab back
原文地址:http://www.cnblogs.com/chushiyaoyue/p/6607916.html