hive中orc格式表的數(shù)據(jù)導(dǎo)入

Hive系列文章

  1. Hive表的基本操作
  2. Hive中的集合數(shù)據(jù)類型
  3. Hive動態(tài)分區(qū)詳解
  4. hive中orc格式表的數(shù)據(jù)導(dǎo)入
  5. Java通過jdbc連接hive
  6. 通過HiveServer2訪問Hive
  7. SpringBoot連接Hive實現(xiàn)自助取數(shù)
  8. hive關(guān)聯(lián)hbase表
  9. Hive udf 使用方法
  10. Hive基于UDF進行文本分詞
  11. Hive窗口函數(shù)row number的用法
  12. 數(shù)據(jù)倉庫之拉鏈表

hive創(chuàng)建orc格式表不能像textfile格式一樣直接load數(shù)據(jù)到表中,需要創(chuàng)建臨時textfile表,然后通過insert into 或者insert overwrite到orc存儲格式表中。

如果你直接load數(shù)據(jù)到orc格式表中,這個步驟可以成功,但是會發(fā)現(xiàn)select * from table limit 1;這個語句都會報錯,也就是說直接load數(shù)據(jù)是不可行的。對于hive中orc格式表可以參見:大數(shù)據(jù):Hive - ORC 文件存儲格式

1)、創(chuàng)建表

需要創(chuàng)建臨時表和數(shù)據(jù)表。

臨時表

create table if not exists db.tmp
(
name string,
age int
)
partitioned by (dt string, hour string, msgtype string, action string)
row format delimited fields terminated by '\t';
SQL

數(shù)據(jù)表

create external table if not exists db.people
(
name string,
age int
)
partitioned by (dt string, hour string, msgtype string, action string)
row format delimited fields terminated by '\t'
stored as orc;
SQL

2)、 導(dǎo)入數(shù)據(jù)

需要先用load命令將數(shù)據(jù)導(dǎo)入textfile格式表,然后再通過insert into插入orc格式表。
(1) 導(dǎo)入數(shù)據(jù)到textfile

load data inpath 'hdfs://path' into table db.tmp partition(dt="2018-06-22",hour="00",msgtype="web", action="click");
SQL

(2)查詢數(shù)據(jù)插入orc格式表

insert into db.people partition(dt="2018-06-22",hour="00",msgtype="web", action="click")
select name,age
from db.tmp where dt = "2018-06-22" and hour = "00" 
and msgtype = "web" and action = "click";









作者:柯廣的網(wǎng)絡(luò)日志

微信公眾號:Java大數(shù)據(jù)與數(shù)據(jù)倉庫