hive数据操作,导入导出

数据导入导出

将数据文件导入hive的表

方式1:导入数据的一种方式:

手动用hdfs命令,将文件放入表目录;

 

方式2:在hive的交互式shell中用hive命令来导入本地数据到表目录

hive>load data local inpath '/root/order.data.2' into table t_order;

 

方式3:用hive命令导入hdfs中的数据文件到表目录

hive>load data inpath '/access.log.2017-08-06.log' into table t_access;

注意:导本地文件和导HDFS文件的区别:

本地文件导入表:复制

hdfs文件导入表:移动

 

方式4:如果目标表是一个分区表

hive> load data [local] inpath ‘......’  into table t_dest partition(p=’value’);

 

将hive表中的数据导出到指定路径的文件

将hive表中的数据导入HDFS的文件

insert overwrite directory '/root/access-data'

row format delimited fields terminated by ','

select * from t_access;

 

 

将hive表中的数据导入本地磁盘文件

insert overwrite local directory '/root/access-data'

row format delimited fields terminated by ','

select * from t_access limit 100000;

 

 

hive文件格式(了解)

HIVE支持很多种文件格式: SEQUENCE FILE | TEXT FILE | PARQUET FILE | RC FILE

create table t_text(movie string,rate int)  stored as textfile;

create table t_seq(movie string,rate int)  stored as sequencefile;

create table t_pq(movie string,rate int)  stored as parquetfile;

 

 

演示:

先建一个存储文本文件的表
create table t_access_text(ip string,url string,access_time string)

row format delimited fields terminated by ','

stored as textfile;

 

导入文本数据到表中:

load data local inpath '/root/access-data/000000_0' into table t_access_text;

 

建一个存储sequence file文件的表:

create table t_access_seq(ip string,url string,access_time string)

stored as sequencefile;

 

从文本表中查询数据插入sequencefile表中,生成数据文件就是sequencefile格式的了:

insert into t_access_seq

select * from t_access_text;

 

建一个存储parquet file文件的表:

create table t_access_parq(ip string,url string,access_time string)

stored as parquetfile;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值