Hive資料的匯入和匯出
阿新 • • 發佈:2019-01-26
1.Load files into tables
格式:
load data [local] inpath ’ filePath‘[overwrite]into table tablename [partition](partcol1=val1,partcol2 =val2)
- filePath原始檔案儲存的位置
- 本地local
- hdfs
- 對錶的資料操作
- 覆蓋 overwrite
- 追加
- 分割槽表載入,特殊性
- partition()
1) 載入本地檔案到hive表中
load data local inpath '/opt/datas/emp.txt'into
load data '/user/huangxgc/hive/datas/emp.txt' into table default.emp;
load data '/user/huangxgc/hive/datas/emp.txt overwrite into table default.emp;
create table default.emp like emp
insert intoselect*from emp;
2.資料的匯出 insert
- 從hive將資料覆蓋匯出到本地(檔案未進行格式化)
insert overwrite local directory '/opt/datas/hive_exp_emp'
select*fromdefault.emp;
- 匯出的檔案時進行格式化
insert overwrite local directory '/opt/datas/hive_exp_emp'
row format delimited fields terminated by '\t' # 行內個欄位採用製表符進行分割
- collection items terminated by '\n'
select*fromdefault.emp;
- 用hive指令碼的-e匯出檔案,檔案已格式化
bin/hive -e "select *from default.emp;">/opt/datas/exp_res.txt
- Export 匯出 :將hive中的資料匯出到hdfs
EXPORT TABLE TABLENAME [PARTITION(part_column="value"[,....])]
TO 'exportt_target_path'
- IMPORT 匯入
IMPORT [EXTERNAL] TABLE new_or_original_tablename [PARTITION(part_column="value"[....])]
From'source_path'
[LOCATION 'import_target_path']