hive 导入数据的5种方式,
文章目录
- 1. 向表中装载数据(Load)
- 2. 通过查询语句向表中插入数据
- 3. 创建表时加载数据
- 4. Import数据到指定Hive表中
- 5. sqoop导入数据
1. 向表中装载数据(Load)
load data [local] inpath '路径' [overwrite] into table 表名 [partition (分区字段=值,…)];
overwrite
:表示覆盖表中已有数据,否则表示追加
如:
从本地文件系统加载数据到hive表
load data local inpath '/home/hdfs/data/test.txt' into table test;
从hdfs文件系统加载数据覆盖hive表
hive (default)> dfs -put /home/hdfs/data/test.txt /wcinput; hive (default)> load data inpath '/wcinput/test.txt' overwrite into table test;
2. 通过查询语句向表中插入数据
insert into:以追加数据的方式插入到表或分区,原有数据不会删除
INSERT INTO TABLE tablename1 [PARTITION(partcol1=val1, partcol2=val2 ...)] select_statement1 FROM from_statement;
insert overwrite:覆盖表中已存在的数据
INSERT OVERWRITE TABLE tablename1 [PARTITION (partcol1=val1, partcol2=val2 ...) ] select_statement1 FROM from_statement;
3. 创建表时加载数据
(1)创建表时使用查询语句as select
create table if not exists 表名 as select_statement1 FROM from_statement;
(2)创建表时通过location
指定加载数据路径
4. Import数据到指定Hive表中
先用export导出后,再将数据导入(export和import主要用于两个Hadoop平台集群之间Hive表迁移
)
import table 表名 from '路径';
如:
从a集群中导出hive表数据:
export table default.student to '/wcinput/export';
向b集群中导入数据到hive表:
import table student from '/wcinput/export' ;
5. sqoop导入数据
Sqoop User Guide
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。