hive 数据导入 导出

hive outline

链接

数据导入hive

本地文件

注意:所谓本地文件,指的是源数据文件(这里是studet.txt)和hiveserver2在同一节点上

1、 加载本地文件studet.txt到hive默认数据库student表中(拷贝+追加)

拷贝:本地文件依然存在
追加:如果hive表student有数据,会追加
注:

  1. /opt/modules/hive-1.2.1/input是本地文件所在路径
  2. 不走mr
 load data local inpath '/opt/modules/hive-1.2.1/inpu/student.txt' into table default.student;
2、加载本地文件studet.txt到hive默认数据库student表中(拷贝+覆盖)

覆盖:如果hive表student有数据,会覆盖

 load data local inpath '/opt/modules/hive-1.2.1/inpu/student.txt' overwrite  into table default.student;

hdfs

1、加载hdfs文件到hive默认数据库student表中(移动+追加)

移动:hdfs上的input目录下的student.txt文件从input目录移动了hive数据仓库所在的地方
追加:如果hive表student有数据,会追加
注解:

  1. 其中/input/student.txt是hdfs的文件路径
  2. 不走mr
 load data inpath '/input/student.txt' into table default.student;
2、加载hdfs文件到hive默认数据库student表中(移动+覆盖)

移动: hdfs上的input目录下的student.txt文件从input目录移动了hive数据仓库所在的地方

覆盖:如果hive表student有数据,会覆盖

注解:

  1. 其中/input/student.txt是hdfs的文件路
  2. 不走mr
 load data inpath '/input/student.txt' overwrite into table default.student;

hql

1、insert+values (很少使用)

注解:会走mr

insert overwrite table student
values (1, 'x'),
       (2, 'y'),
       (3, 'z');
2、insert + select (大量使用)

注解:

  1. 会走mr
  2. 在数据文件存储格式转换时经常用(例如把文件存储格式由textfile—>sequencefile)

这里会把对people 表的查询结果插入到表student表 中

insert overwrite table student select * from people;
或者
insert overwrite table student select 5, 'a';             
动态分区插入

hive 动态分区

hive cte

从其他表中查询数据,然后插入

数据从hive导出

本地

1、将查询的结果导出到本地

注意:

  1. /opt/modules/output/hive/student是本地路径
  2. 如果不指定分隔符,默认为\001
 insert overwrite local directory '/opt/modules/output/hive/student' select * from student;
2、将查询的结果格式化导出到本地

/opt/modules/output/hive/student1是本地路径

insert overwrite local directory '/opt/modules/output/hive/student1' row format delimited fields terminated by '\t' select * from student;

hdfs

将查询的结果导出到 hdfs 上(没有 local 关键字)
 insert overwrite directory '/output/hive/student2' row format delimited fields terminated by '\t' select * from student;

hive shell 命令导出

基本语法:(hive -f/-e 执行语句或者脚本 > file)

bin/hive  -e  'select * from default.student;' > /opt/modules/output/hive/student3.txt;
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值