elasticsearch入門系列">elasticsearch入門系列
895
2022-05-29
本次博主為大家?guī)淼氖荋ive表中數(shù)據(jù)的加載與導(dǎo)出。希望能夠幫助到大家。
目錄
一. Hive表中加載數(shù)據(jù)
1.1 直接向分區(qū)表中插入數(shù)據(jù)
1.2 通過查詢插入數(shù)據(jù)
1.3 多插入模式
1.4 查詢語句中創(chuàng)建表并加載數(shù)據(jù)(as select)
1.5 創(chuàng)建表時通過location指定加載數(shù)據(jù)路徑
二. Hive表中的數(shù)據(jù)導(dǎo)出(了解就行)
2.1 insert導(dǎo)出
2.2 Hadoop命令導(dǎo)出到本地
2.3 hive shell 命令導(dǎo)出
2.4 export導(dǎo)出到HDFS上(全表導(dǎo)出)
三. 清空表數(shù)據(jù)
一. Hive表中加載數(shù)據(jù)
1.1 直接向分區(qū)表中插入數(shù)據(jù)
create table score3 like score; insert into table score3 partition(month ='201807') values ('001','002','100');
1
2
3
4
1.2 通過查詢插入數(shù)據(jù)
1. 通過load方式加載數(shù)據(jù)
(linux) load data local inpath ‘/export/servers/hivedatas/score.csv’ overwrite into table score partition(month=‘201806’); (HDFS) load data inpath ‘/export/servers/hivedatas/score.csv’ overwrite into table score partition(month=‘201806’);
1
2
3
4
5
2. 通過查詢方式加載數(shù)據(jù)
create table score4 like score; insert overwrite table score4 partition(month = '201806') select s_id,c_id,s_score from score;
1
2
關(guān)鍵字overwrite 必須要有
1.3 多插入模式
常用于實際生產(chǎn)環(huán)境當中,將一張表拆開成兩部分或者多部分
1. 給score表加載數(shù)據(jù)
load data local inpath '/export/servers/hivedatas/score.csv' overwrite into table score partition(month='201806');
1
2. 創(chuàng)建第一部分表:
create table score_first( s_id string,c_id string) partitioned by (month string) row format delimited fields terminated by '\t' ;
1
3. 創(chuàng)建第二部分表:
create table score_second(c_id string,s_score int) partitioned by (month string) row format delimited fields terminated by '\t';
1
4. 分別給第一部分與第二部分表加載數(shù)據(jù)
from score insert overwrite table score_first partition(month='201806') select s_id,c_id insert overwrite table score_second partition(month = '201806') select c_id,s_score;
1
1.4 查詢語句中創(chuàng)建表并加載數(shù)據(jù)(as select)
將查詢的結(jié)果保存到一張表當中去
create table score5 as select * from score;
1
1.5 創(chuàng)建表時通過location指定加載數(shù)據(jù)路徑
1. 創(chuàng)建表,并指定在hdfs上的位置
create external table score6 (s_id string,c_id string,s_score int) row format delimited fields terminated by '\t' location '/myscore6';
1
2. 上傳數(shù)據(jù)到hdfs上
hdfs dfs -mkdir -p /myscore6 hdfs dfs -put score.csv /myscore6;
1
2
3
3. 查詢數(shù)據(jù)
select * from score6;
1
二. Hive表中的數(shù)據(jù)導(dǎo)出(了解就行)
將hive表中的數(shù)據(jù)導(dǎo)出到其他任意目錄,例如linux本地磁盤,例如hdfs,例如mysql等等
2.1 insert導(dǎo)出
1. 將查詢的結(jié)果導(dǎo)出到本地
insert overwrite local directory '/export/servers/exporthive' select * from score;
1
2. 將查詢的結(jié)果格式化導(dǎo)出到本地
insert overwrite local directory '/export/servers/exporthive' row format delimited fields terminated by '\t' collection items terminated by '#' select * from student;
1
3. 將查詢的結(jié)果導(dǎo)出到HDFS上(沒有l(wèi)ocal)
insert overwrite directory '/export/servers/exporthive' row format delimited fields terminated by '\t' collection items terminated by '#' select * from score;
1
2.2 Hadoop命令導(dǎo)出到本地
dfs -get /export/servers/exporthive/000000_0 /export/servers/exporthive/local.txt;
1
2.3 hive shell 命令導(dǎo)出
基本語法:(hive -f/-e 執(zhí)行語句或者腳本 > file)
bin/hive -e "select * from myhive.score;" > /export/servers/exporthive/score.txt
1
2.4 export導(dǎo)出到HDFS上(全表導(dǎo)出)
export table score to '/export/exporthive/score';
1
三. 清空表數(shù)據(jù)
只能清空管理表,也就是內(nèi)部表
truncate table score6;
1
清空這個表會報錯
本次的分享就到這里了,
看 完 就 贊 , 養(yǎng) 成 習 慣 ! ! ! \color{#FF0000}{看完就贊,養(yǎng)成習慣!??!} 看完就贊,養(yǎng)成習慣!!!^ _ ^ ?? ?? ??
碼字不易,大家的支持就是我堅持下去的動力。后不要忘了關(guān)注我哦!
Hadoop Hive
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔相應(yīng)法律責任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實的內(nèi)容,請聯(lián)系我們jiasou666@gmail.com 處理,核實后本網(wǎng)站將在24小時內(nèi)刪除侵權(quán)內(nèi)容。