Hive Learning Notes---Array, Map, struct type use

Source: Internet
Author: User

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>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.