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 table default.emp;
2)加载 hdfs 文件到hive中
load data '/user/huangxgc/hive/datas/emp.txt' into table default.emp;
3) 加载数据覆盖表中已有的数据
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 table default.emp;
2)加载 hdfs 文件到hive中
load data '/user/huangxgc/hive/datas/emp.txt' into table default.emp;
3) 加载数据覆盖表中已有的数据
load data '/user/huangxgc/hive/datas/emp.txt overwrite into table default.emp;
4) 创建表时通过insert 加载
create table default.emp like emp
insert into select*from emp;
5) 创建表的时候通过location指定加载
2.数据的导出 insert
- 从hive将数据覆盖导出到本地(文件未进行格式化)
insert overwrite local directory '/opt/datas/hive_exp_emp'
select*from default.emp;
- 导出的文件时进行格式化
insert overwrite local directory '/opt/datas/hive_exp_emp'
row format delimited fields terminated by '\t' # 行内个字段采用制表符进行分割
- collection items terminated by '\n' # 每行采用换行进行分割
select*from default.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'
export_target_path:指的是hdfs的路径
- IMPORT 导入
语法:
IMPORT [EXTERNAL] TABLE new_or_original_tablename [PARTITION(part_column="value"[....])]
From'source_path'
[LOCATION 'import_target_path']
import_target_path:指的是hdfs的路径