HIVE入门_3_数据导入导出
2015-10-23 09:34
295 查看
数据导出方式
导出到本地文件系统
导出到HDFS上
导出到HIVE的另一个表中
数据导入方式
从本地文件导入
从HDFS上导入
创建表后从别的表查询出的相应数据导入
创建表的时候通过别的表查询记录插入
参考资料
因此,HIVE也支持将数据直接从HDFS上的一个目录移动到相应HIVE表的目录中去。
和本地文件系统导入的区别只是是否有inpath。
导出到本地文件系统
导出到HDFS上
导出到HIVE的另一个表中
数据导入方式
从本地文件导入
从HDFS上导入
创建表后从别的表查询出的相应数据导入
创建表的时候通过别的表查询记录插入
参考资料
数据导出方式
导出到本地文件系统
hive> insert overwrite local directory '/home/wyp/wyp' > row format delimited > fields terminated by '\t' > select * from wyp; hive -e "select * from wyp" >> local/wyp.txt cat wyp.sql #select * from wyp hive -f wyp.sql >> local/wyp2.txt
导出到HDFS上
hive> insert overwrite directory '/home/wyp/hdfs' > select * from wyp;
导出到HIVE的另一个表中
hive> insert into table test > partition (age='25') > select id, name, tel > from wyp;
数据导入方式
从本地文件导入
hive> create table wyp > (id int, name string, > age int, tel string) > ROW FORMAT DELIMITED > FIELDS TERMINATED BY '\t' > STORED AS TEXTFILE; cat wyp.txt #1 wyp 25 13188888888888 #2 test 30 13888888888888 load data local inpath 'wyp.txt' into table wyp; dfs -ls /user/hive/warehouse/wyp ;
从HDFS上导入
从本地文件系统将数据导入到HIVE表的过程中,其实是现将数据临时复制到HDFS下面的一个目录,然后再将数据从临时目录下移动到对应HIVE表的数据目录中。因此,HIVE也支持将数据直接从HDFS上的一个目录移动到相应HIVE表的目录中去。
和本地文件系统导入的区别只是是否有inpath。
load data inpath '/home/wyp/add.txt' into table wyp;
创建表后从别的表查询出的相应数据导入
hive> create table test(
> id int, name string
> ,tel string)
> partitioned by
> (age int)
> ROW FORMAT DELIMITED
> FIELDS TERMINATED BY '\t'
> STORED AS TEXTFILE;
hive> insert into table test > partition (age='25') > select id, name, tel > from wyp;
##动态指明分区
hive> set hive.exec.dynamic.partition.mode=nonstrict;
hive> insert into table test
> partition (age)
> select id, name,
> tel, age
> from wyp;
#overwrite方式重写原来的数据
hive> insert overwrite table test
> PARTITION (age)
> select id, name, tel, age
> from wyp;
#多表插入,只需要扫描一遍数据生成需要的各种表
hive> from wyp
> insert into table test
> partition(age)
> select id, name, tel, age
> insert into table test3
> select id, name
> where age>25;
创建表的时候通过别的表查询记录插入
hive> create table test4 > as > select id, name, tel > from wyp;
参考资料
过往记忆的blog相关文章推荐
- 分享Hive的一份胶片资料
- Hadoop生态上几个技术的关系与区别:hive、pig、hbase 关系与区别
- 将Hive的默认数据库Derby改为Postgresql
- kettle中对hive操作时需要知道的东西
- #Note# Analyzing Twitter Data with Apache Hadoo...
- [翻译]Hive wiki GettingStarted
- 启动hive命令报错 “Metastore contains multiple versions”
- sparksql与hive整合
- hive on spark 编译
- sqoop 中文文档 User guide 一
- sqoop 中文文档 User guide 二 import
- sqoop 中文文档 User guide 二 import续
- sqoop 中文文档 User guide 三 export
- sqoop 中文文档 User guide 四 validation
- sqoop 中文文档 User guide 五 job,metastore,merge,codegen
- sqoop 中文文档 User guide 六
- sqoop 中文文档 User guide 七
- Hadoop Hive的限制
- HIVEQL
- hive 安装配置