导入数据到hive的几种方式

–创建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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值