Hive provides a variety of composite data types:
Array, Struct, Map
struct use:
Hive> CREATE TABLE Student_test (ID INT, info struct<name:string, age:int>)
> ROW FORMAT delimited FIELDS T erminated by ', '
> COLLECTION ITEMS terminated by ': ';
' FIELDS terminated by ': Separator between field and field
' COLLECTION ITEMS terminated by ': separator for each item in a field
Import data:
$ cat Test5.txt
1,zhou:30
2,yan:30
3,chen:20
4,li:80 hive>
LOAD DATA local inpath '/home/work/ Data/test5.txt ' into TABLE student_test;
Copying data from File:/home/work/data/test5.txt
copying file:file:/home/work/data/test5.txt
Loading data To table Default.student_test
OK time
taken:0.35 seconds
Inquire:
Hive> select Info.age from Student_test;
Total MapReduce jobs = 1.
Total MapReduce CPU time spent:490 msec
OK
taken:21.677 seconds
Array uses
Build table:
Hive> CREATE table Class_test (name string, student_id_list array<int>)
> ROW FORMAT delimited
> FIELDS terminated by ', '
> COLLECTION ITEMS terminated by ': ';
OK Time
taken:0.099 seconds
Import data:
$ cat Test6.txt
034,1:2:3:4
035,5:6
036,7:8:9:10
hive> LOAD DATA local inpath '/home/work/ Data/test6.txt ' into TABLE class_test;
Copying data from File:/home/work/data/test6.txt
copying file:file:/home/work/data/test6.txt
Loading data to Table Default.class_test
OK time
taken:0.198 seconds
Inquire:
Hive> Select student_id_list[3] from Class_test;
Total MapReduce jobs = 1.
Total MapReduce CPU time spent:480 msec
OK
4
NULL
time
taken:21.574 seconds
Map uses
Build table:
Hive> CREATE TABLE employee (ID string, perf map<string, int>)
> ROW FORMAT delimited
> FIELDS termi nated by ' \ t '
> COLLECTION ITEMS terminated by ', '
> MAP KEYS terminated by ': ';
OK Time
taken:0.144 seconds
' MAP KEYS terminated by ': Key value Separator
Import data:
$ cat Test7.txt
1 job:80,team:60,person:70
2 job:60,team:80
3 Job:90,team:70,person :
hive> LOAD DATA local inpath '/home/work/data/test7.txt ' into TABLE employee;
Inquire:
hive> Select perf[' person ' from employee;
Total MapReduce jobs = 1.
Total MapReduce CPU time spent:460 msec
OK
NULL-time
taken:20.902 seconds
hive> Select perf[' person ' to from employee where perf[' who ' is not null; Total
MapReduce jobs = 1.
Total MapReduce CPU time spent:610 msec
OK
time
taken:21.989 seconds hive>
& Lt;span style= "font-family:arial, Helvetica, Sans-serif;" ><span style= "White-space:normal;" >
</span></span>