导入数据到hive的几种方式
创始人
2024-11-15 04:33:11
0

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

相关内容

热门资讯

微信炸金花购买房卡/微信斗牛如... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:8488009许多玩家在游戏中会购买房卡来享受...
炸金花微信群购买房卡/牛牛链接... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:33903369许多玩家在游戏中会购买房卡来享...
拼三张从哪里买房卡/新海贝大厅... 拼三张是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:55051770许多玩家在游戏中会购买房卡来享...
微信炸金花房卡一张多少钱/微信... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:8488009许多玩家在游戏中会购买房卡来享受...
微信链接炸金花房卡在哪买的/微... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:33903369许多玩家在游戏中会购买房卡来享...
微信群链接炸金花房卡/微信里斗... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:55051770许多玩家在游戏中会购买房卡来享...
怎么买炸金花房间链接房卡/微信... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:8488009许多玩家在游戏中会购买房卡来享受...
微信玩链接牛牛房卡/新人皇大厅... 斗牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:33903369许多玩家在游戏中会购买房卡来享受...
拼三张房卡链接去哪里买/橘子大... 拼三张是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:55051770许多玩家在游戏中会购买房卡来享...
微信玩炸金花怎么买房卡/欢乐游... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:8488009许多玩家在游戏中会购买房卡来享受...
炸金花房卡链接在哪买的/狂飙大... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:33903369许多玩家在游戏中会购买房卡来享...
如何创建牛牛房间卡/牛至尊大厅... 牛牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:55051770许多玩家在游戏中会购买房卡来享受...
微信里上玩拼三张购买房卡/神牛... 拼三张是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:8488009许多玩家在游戏中会购买房卡来享受...
微信里面斗牛链接房卡/九酷大厅... 斗牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:33903369许多玩家在游戏中会购买房卡来享受...
炸金花如何开好友房间房卡/微信... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:8488009许多玩家在游戏中会购买房卡来享受...
微信炸金花在哪里充值房卡/新天... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:33903369许多玩家在游戏中会购买房卡来享...
微信里面拼三张房卡哪里买/新皇... 拼三张是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:55051770许多玩家在游戏中会购买房卡来享...
微信群开牛牛房卡/新天地大厅牛... 牛牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:8488009许多玩家在游戏中会购买房卡来享受更...
微信打炸金花链接房卡怎么买/怎... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:33903369许多玩家在游戏中会购买房卡来享...
微信玩炸金花房卡怎么买/开牛牛... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:55051770许多玩家在游戏中会购买房卡来享...