哈尔滨网站建设如何,品牌营销推广策划,建设工程查询系统,南通网站建设公司排名Hive 中的批量数据导入 在博客【大数据】Hive 表中插入多条数据 中#xff0c;我简单介绍了几种向 Hive 表中插入数据的方法。然而更多的时候#xff0c;我们并不是一条数据一条数据的插入#xff0c;而是以批量导入的方式。在本文中#xff0c;我将较为全面地介绍几种向 H… Hive 中的批量数据导入
在博客【大数据】Hive 表中插入多条数据 中我简单介绍了几种向 Hive 表中插入数据的方法。然而更多的时候我们并不是一条数据一条数据的插入而是以批量导入的方式。在本文中我将较为全面地介绍几种向 Hive 中批量导入数据的方法。
1.从本地文件系统加载load数据
load data [local] inpath 路径 [overwrite] into table 表名 [partition (分区字段值,…)];overwrite表示覆盖表中已有数据否则表示追加。此种加载方式是数据的复制。
1创建一张表。
hive (default) create table student(id string, name string) row format delimited fields terminated by \t;2加载本地文件到 Hive。
hive (default) load data local inpath /opt/module/datas/student.txt into table default.student;2.从 HDFS 文件系统加载load数据
从 HDFS 文件系统向表中加载数据其实就是一个移动文件的操作需要提前将数据上传到 HDFS 文件系统。
1上传文件到 HDFSLinux 本地 /opt/module/datas/student.txt 文件传到 /user/victor/hive 目录。
hive (default) dfs -put /opt/module/datas/student.txt /user/victor/hive;2从 HDFS 文件系统向表中加载数据。
hive (default) load data inpath /user/victor/hive/student.txt into table default.student;3.通过 as select 向表中插入数据
hive (default) create table if not exists student3 as select id, name from student;4.通过 insert into 向表中插入数据
insert into table test [partition(partcol1val1, partcol2val2 ...)] select id,name from student;insert into以追加数据的方式插入到表或分区原有数据不会删除。
insert overwrite table test [partition(partcol1val1, partcol2val2 ...)] select id,name from student;insert overwrite覆盖表中已存在的数据。
1创建一张分区表。
hive (default) create table student(id string, name string) partitioned by (month string) row format delimited fields terminated by \t;2基本插入数据。
hive (default) insert into table student partition(month201801) values(1004,wangwu);3基本模式插入根据单张表查询结果。
hive (default) insert overwrite table student partition(month201802) select id, name from student where month201801;4多插入模式只需要扫描一遍源表就可以生成多个不相交的输出。
hive (default) from studentinsert overwrite table student partition(month201803)select id, name where month201801insert overwrite table student partition(month201804)select id, name where month201801;5.通过 location 的方式
直接将数据文件上传到 location 指定的 HDFS 的目录下
1创建表并指定在 HDFS 上的位置。
hive (default) create external table student(id int, name string)row format delimited fields terminated by \tlocation /user/hive/warehouse/student;2上传数据到 HDFS 上。
hive (default) dfs -mkdir -p /user/hive/warehouse/student;
hive (default) dfs -put /opt/module/datas/student.txt /user/hive/warehouse/student;3查询数据。
select * from student;