Hive版本:Hive 1.1.0-cdh5.14.2
INSERT導出到目錄
Standard syntax:
INSERT OVERWRITE [LOCAL] DIRECTORY directory1
[ROW FORMAT row_format] [STORED AS file_format] (Note: Only available starting with Hive 0.11.0)
SELECT … FROM …
Hive extension (multiple inserts):
FROM from_statement
INSERT OVERWRITE [LOCAL] DIRECTORY directory1 select_statement1
[INSERT OVERWRITE [LOCAL] DIRECTORY directory2 select_statement2] …
舉例如下:
(1)導出到本地目錄
insert overwrite local directory '/home/hadoop/hive/data_export/score'
row format delimited fields terminated by ','
select * from score;
(2)導出到hdfs目錄
insert overwrite directory '/score'
row format delimited fields terminated by ','
select * from score;
Hive客戶端導出
(1)hive -e “sql語句” > file
(2)hive -f sql文件 > file
舉例如下:
hive -e 'select * from myhive.score;' > /home/hadoop/hive/data/score.txt
export導出表
EXPORT TABLE tablename [PARTITION (part_column=“value”[, …])] TO ‘export_target_path’ [ FOR replication(‘eventid’) ]
舉例如下:
注:只能導出到hdfs目錄
export table department to 'hdfs_exports_location/department';
export table employee partition (emp_country="in", emp_state="ka") to 'hdfs_exports_location/employee';