现有数据如下:
1 huangbo guangzhou,xianggang,shenzhen a1:30,a2:20,a3:100 beijing,112233,13522334455,500
2 xuzheng xianggang b2:50,b3:40 tianjin,223344,13644556677,600
3 wangbaoqiang beijing,zhejinag c1:200 chongqinjg,334455,15622334455,20
建表语句
use class; create table cdt( id int, name string, work_location array<string>, piaofang map<string,bigint>, address struct<location:string,zipcode:int,phone:string,value:int>) row format delimited fields terminated by "\t" collection items terminated by "," map keys terminated by ":" lines terminated by "\n";
导入数据
0: jdbc:hive2://hadoop3:10000> load data local inpath "/home/hadoop/cdt.txt" into table cdt;
查询语句
select * from cdt;
select name from cdt;
select work_location from cdt;
select work_location[0] from cdt;
select work_location[1] from cdt;
建表语句、导入数据同1
查询语句
select piaofang from cdt;
select piaofang["a1"] from cdt;
建表语句、导入数据同1
查询语句
select address from cdt;
select address.location from cdt;
很少使用
参考资料:http://yugouai.iteye.com/blog/1849192
和关系型数据库一样,Hive 也提供了视图的功能,不过请注意,Hive 的视图和关系型数据库的数据还是有很大的区别:
(1)只有逻辑视图,没有物化视图;
(2)视图只能查询,不能 Load/Insert/Update/Delete 数据;
(3)视图在创建时候,只是保存了一份元数据,当查询视图的时候,才开始执行视图对应的 那些子查询
create view view_cdt as select * from cdt;
show views; desc view_cdt;-- 查看某个具体视图的信息
select * from view_cdt;
drop view view_cdt;
具体可看http://www.cnblogs.com/qingyunzong/p/8744593.html
show functions;
desc function substr;
desc function extended substr;
当 Hive 提供的内置函数无法满足业务处理需要时,此时就可以考虑使用用户自定义函数。
UDF(user-defined function)作用于单个数据行,产生一个数据行作为输出。(数学函数,字 符串函数)
UDAF(用户定义聚集函数 User- Defined Aggregation Funcation):接收多个输入数据行,并产 生一个输出数据行。(count,max)
UDTF(表格生成函数 User-Defined Table Functions):接收一行输入,输出多行(explode)
原文:https://www.cnblogs.com/qingyunzong/p/8746159.html