Import and Export hive data

Source: Internet
Author: User
1/export hive data

Many times, we execute the SELECT statement in hive to save the final result to a local file, to the HDFS system, or to a new table, hive provides convenient keywords to implement the functions described above.

 

1. Place the select result in a table (first, create a new table using create table)

Insert overwrite Table Test

Select uid, name from Test2;

 

2. Place the select result to the local file system.

Insert overwrite local directory '/tmp/reg_3' select a. * from events;

 

3. Place the select result in the HDFS File System

Insert overwrite directory '/tmp/hdfs_out' select a. * From invites a where a. DS = '<date> ';

 

2/hive Data Import

Load data [local] inpath '/data/userdata' [overwrite] into Table user;

 # specify the path create external table page_view (viewtime int, userid bigint, page_url string, referrer_url string, IP string comment 'IP address of the user' when creating a table ', country string comment 'country of origination ') comment 'this is the staging page view table' row format delimited fields terminated by '44' lines terminated by '12' stored as textfilelocation '/user/data/staging/page_view '; # You can import data to a table after creating a table # Local path (stepping stone) load data local inpath '/tmp/date.txt' overwrite into Table page_view partition (Pt = '2017-06-08 ') # hadoop path load data inpath '/tmp/date.txt' overwrite into Table page_view partition (Pt = '2017-06-08 ') # The above overwrite key will cover the entire table, if you only want to append the data, remove overwrite. # Add a partition to the alter table tmp_xx add partition (Pt = '000000') location'/group/mywork/hive/XX/Pt = 100 '; # Of course, you can drag data from other tables directly to insert overwrite table tmp_t1 select * From tmp_t2; 

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.