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';