当前位置: 代码网 > it编程>游戏开发>ar > 导入数据到hive的几种方式

导入数据到hive的几种方式

2024年08月02日 ar 我要评论
3.创建外部表映射hdfs文件。

–创建hive表
create table test(
id string,
name string)
row format serde
‘org.apache.hadoop.hive.serde2.lazy.lazysimpleserde’
with serdeproperties (
‘field.delim’=‘|’,
‘line.delim’=‘\n’,
‘serialization.format’=‘|’)
stored as inputformat
‘org.apache.hadoop.mapred.textinputformat’
outputformat
‘org.apache.hadoop.hive.ql.io.hiveignorekeytextoutputformat’
location
‘hdfs://hacluster/user/hive/warehouse/test/test’
tblproperties (
‘bucketing_version’=‘2’,
‘transient_lastddltime’=‘1715822045’)
;

–查询hive表
select * from test;
±---------±-----------+
| test.id | test.name |
±---------±-----------+
±---------±-----------+
no rows selected (0.623 seconds)

1.load导入
cat test.txt
1|one
2|two

load data local inpath ‘/tpdata/ypg/shell/work/work0625/test.txt’ into table test_db.test;
load data inpath ‘/user/hive/warehouse//test2/test.txt’ into table test_db.test;
select * from test_db.test;
±---------±-----------+
| test.id | test.name |
±---------±-----------+
| 1 | one |
| 2 | two |
±---------±-----------+

2.sql导入
insert导入
insert into test_db.test values(‘1’,‘one’);
insert into test_db.test values(‘2’,‘two’);
select * from test_db.test;
±---------±-----------+
| test.id | test.name |
±---------±-----------+
| 1 | one |
| 2 | two |
±---------±-----------+

insert into test_db.test
select ‘1’ as id, ‘one’ as name union all select ‘2’ as id, ‘two’ as name
select * from test_db.test;
±---------±-----------+
| test.id | test.name |
±---------±-----------+
| 1 | one |
| 2 | two |
±---------±-----------+

3.创建外部表映射hdfs文件
create external table test_copy(
id string,
name string)
row format serde
‘org.apache.hadoop.hive.serde2.lazy.lazysimpleserde’
with serdeproperties (
‘field.delim’=‘|’,
‘line.delim’=‘\n’,
‘serialization.format’=‘|’)
stored as inputformat
‘org.apache.hadoop.mapred.textinputformat’
outputformat
‘org.apache.hadoop.hive.ql.io.hiveignorekeytextoutputformat’
location
‘hdfs://hacluster/user/hive/warehouse/test2’
tblproperties (
‘bucketing_version’=‘2’,
‘transient_lastddltime’=‘1715822045’)
;
msck repair table test_db.test_copy;

insert into test_db.test
select * from test_db.test_copy;

select * from test_db.test;
±---------±-----------+
| test.id | test.name |
±---------±-----------+
| 1 | one |
| 2 | two |
±---------±-----------+

4.sqoop导入
sqoop import
-dorg.apache.sqoop.splitter.allow_text_splitter=true
–connect jdbc:mysql://11.22.33.44:2883/test
–username dmltest
–password ‘test#123’
–table test
–fields-terminated-by ‘,’
–delete-target-dir
–hive-import
–hive-table test_db.test
-m 1

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com