hive的集合数据类型包括三种,分别是Array、Map和Struct |
|
|
建表 create table test ( id INT, name STRING, hobby ARRAY<STRING>, //array中元素为String类型 friend MAP<STRING,STRING>, //map中键和值均为String类型 mark struct<math:int,english:int> //Struct中元素为Int类型 ) row format delimited fields terminated by ',' //字段之间用','分隔 collection items terminated by '_' //集合中的元素用'_'分隔 map keys terminated by ':' //map中键值对之间用':'分隔 lines terminated by '\n //行之间用'\n'分隔 |
|
|
load 装载数据
load data inpath '/uesr/xiaoming/11.txt' overwrite into table test; |
对于数据量较大,常用的一种方法是通过文件批量导入的方法 |
|
insert 插入数据 INSERT INTO test SELECT 2, 'xiaohua', array('basketball','read'), str_to_map('xiaoming:no,xiaohong:no'), named_struct('math',90,'english',90) from tmp; |
|
|
查询数据 select id, name, hobby[0], //查询第一个hobby friend['xiaohong'], //查询map键为xiaohong的value mark.math //查询struct中math的值 from test where name = 'xiaoming';
|
|
|
|
|