前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HIVE入门_3_数据导入导出

HIVE入门_3_数据导入导出

作者头像
用户1147754
发布2018-01-02 17:05:35
1.3K0
发布2018-01-02 17:05:35
举报
文章被收录于专栏:YoungGyYoungGy
  • 数据导出方式
    • 导出到本地文件系统
    • 导出到HDFS上
    • 导出到HIVE的另一个表中
  • 数据导入方式
    • 从本地文件导入
    • 从HDFS上导入
    • 创建表后从别的表查询出的相应数据导入
    • 创建表的时候通过别的表查询记录插入
  • 参考资料

数据导出方式

导出到本地文件系统

代码语言:javascript
复制
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上

代码语言:javascript
复制
hive> insert overwrite directory '/home/wyp/hdfs'
    > select * from wyp;

导出到HIVE的另一个表中

代码语言:javascript
复制
hive> insert into table test
    > partition (age='25')
    > select id, name, tel
    > from wyp;

数据导入方式

从本地文件导入

代码语言:javascript
复制
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

代码语言:javascript
复制
load data inpath '/home/wyp/add.txt' into table wyp;

创建表后从别的表查询出的相应数据导入

代码语言:javascript
复制
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;

创建表的时候通过别的表查询记录插入

代码语言:javascript
复制
hive> create table test4
    > as
    > select id, name, tel
    > from wyp;

参考资料

  1. 过往记忆的blog
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 数据导出方式
    • 导出到本地文件系统
      • 导出到HDFS上
        • 导出到HIVE的另一个表中
        • 数据导入方式
          • 从本地文件导入
            • 从HDFS上导入
              • 创建表后从别的表查询出的相应数据导入
                • 创建表的时候通过别的表查询记录插入
                • 参考资料
                领券
                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档