Hive快速入門系列(9) | Hive表中數(shù)據(jù)的加載與導(dǎo)出

      網(wǎng)友投稿 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上

      Hive快速入門系列(9) | Hive表中數(shù)據(jù)的加載與導(dǎo)出

      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)容。

      上一篇:ClickHouse副本機制簡介
      下一篇:2017年全國大學生電子設(shè)計競賽滾球控制系統(tǒng)設(shè)計
      相關(guān)文章
      久久亚洲国产伦理| 亚洲视频在线观看免费| 亚洲精品熟女国产| 亚洲国产精品VA在线看黑人| 亚洲国产综合久久天堂| 亚洲国产精品自产在线播放| 亚洲成A人片在线观看中文| 另类专区另类专区亚洲| 无码天堂亚洲国产AV| 久久人午夜亚洲精品无码区| 久久人午夜亚洲精品无码区| 男人的天堂av亚洲一区2区| 国产精品亚洲va在线观看| 国产亚洲Av综合人人澡精品| 亚洲乱码中文字幕手机在线| 国产日产亚洲系列最新| 亚洲乱码中文字幕久久孕妇黑人| 亚洲人成色77777| 国产亚洲精品国产| 少妇中文字幕乱码亚洲影视| 亚洲码在线中文在线观看| 亚洲伊人久久大香线蕉啊| 亚洲第一男人天堂| 亚洲AV无码一区二区一二区 | 亚洲V无码一区二区三区四区观看| 国产成人无码综合亚洲日韩| 亚洲AV成人片色在线观看 | 国产精品久久久久久亚洲影视| 亚洲国产AV无码一区二区三区| 久久亚洲精品无码gv| 亚洲国产婷婷综合在线精品| 亚洲情XO亚洲色XO无码| 亚洲人成电影在线天堂| 亚洲白嫩在线观看| 中文字幕亚洲精品无码| 国产AV无码专区亚洲AV琪琪| 国产亚洲精品福利在线无卡一| 国产亚洲人成网站在线观看不卡| 亚洲一区二区三区高清| 亚洲人成片在线观看| 亚洲成在人线aⅴ免费毛片|