当前位置:   article > 正文

Hive--导入数据的6种方式_hive向表中导入数据

hive向表中导入数据

总结:

  • 本地文件导入到Hive表–
load data local inpath '路径' into/overwrite table 表名
  • 1
  • HDFS文件导入到Hive表
load data inpath 'hdfs路径' into/overwrite table 表名
  • 1
  • Hive表导入到Hive表(select 或者insert )
    • 创建表的过程中从其他表导入
create table ... as select xxx from 其他表
  • 1
  • 从其他表导入
insert into/overwrite table 表名  select xxx from 其他表
  • 1
  • 指定数据库目录在HDFS上的地址
location 'hdfs路径'
  • 1

load会搬移数据,location是指定数据

1、加载本地文件到hive表

语法
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2、加载hdfs文件到hive中

在这里插入图片描述

3、通过select加载

create table if not exists default.dept_cats
as select * from dept;
  • 1
  • 2

4、通过insert加载

在这里插入图片描述

5、创建表的时候通过location指定加载

  • 外部表方式
create external table if not exists emp_partition(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int
)
partitioned by (month string)
row format delimited fields terminated by '\t'

load data local inpath '/opt/datas/emp.txt' into table default.emp_partition partition (month='201803');
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/384803
推荐阅读
相关标签
  

闽ICP备14008679号