概述
STRUCT:STRUCT可以包含不同数据类型的元素。这些元素可以通过”点语法”的方式来得到所需要的元素,比如user是一个STRUCT类型,那么可以通过user.address得到这个用户的地址。
操作实例
1、创建表
create table student_test(id int,infostruct<name:string,age:int>)
row format delimited fields terminated by ","
collection items terminated by ":";
2、准备文件内容
[root@hello110 data]# vi student_test
1001,zhangsan:24
1002,lisi:25
1003,xiaoming:26
1004,dongdong:27
1001,zhangsan:24
1002,lisi:25
1003,xiaoming:26
1004,dongdong:27
3、文件导入表
load data local inpath "/data/student_test" into table student_test;
4、查看表内容
hive (default)> select * from student_test;
OK
student_test.id student_test.info
1001 {"name":"zhangsan","age":24}
1002 {"name":"lisi","age":25}
1003 {"name":"xiaoming","age":26}
1004 {"name":"dongdong","age":27}
Time taken: 2.76 seconds, Fetched: 4 row(s)
---------------------------
hive (default)> select info.name,info.age from student_test;
OK
name age
zhangsan 24
lisi 25
xiaoming 26
dongdong 27
Time taken: 0.294 seconds, Fetched: 4 row(s)
5、hadoop中的文件内容