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 装载数据对于数据量较大,常用的一种方法是通过文件批量导入的方法
文本内容:
1,xiaoming,basketball_game,xiaohong:yes_xiaohua:no,99_75
1,xiaohong,watch_study,xiaoming:no_xiaohua:not,95_95
load data inpath '/uesr/xiaoming/11.txt' overwrite into table test; //insert 插入数据 INSERT INTO test 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';
Hive——集合数据类型
最新推荐文章于 2025-03-15 13:20:53 发布