日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Hive常用命令

系統(tǒng) 4775 0

本文轉(zhuǎn)載自:http://blog.csdn.net/an342647823/article/details/19624733

1.hive模糊搜索表
? show tables like '*name*';

2.查看表結(jié)構(gòu)信息
? desc formatted table_name;
? desc table_name;

3.查看分區(qū)信息
? show partitions table_name;

4.根據(jù)分區(qū)查詢數(shù)據(jù)
? select table_coulm from table_name where partition_name = '2014-02-25';

5.查看hdfs文件信息
? dfs -ls /user/hive/warehouse/table02;

6.從文件加載數(shù)據(jù)進(jìn)表(OVERWRITE覆蓋,追加不需要OVERWRITE關(guān)鍵字)
? LOAD DATA LOCAL INPATH 'dim_csl_rule_config.txt' OVERWRITE into table dim.dim_csl_rule_config;
? --從查詢語(yǔ)句給table插入數(shù)據(jù)
? INSERT OVERWRITE TABLE test_h02_click_log PARTITION(dt) select *?
? from stage.s_h02_click_log where dt='2014-01-22' limit 100;

7.導(dǎo)出數(shù)據(jù)到文件
? insert overwrite directory '/tmp/csl_rule_cfg' select a.* from dim.dim_csl_rule_config a;
? hive -e "select day_id,pv,uv,ip_count,click_next_count,second_bounce_rate,return_visit,pg_type from tmp.tmp_h02_click_log_baitiao_ag_sum where day_id in ('2014-03-06','2014-03-07','2014-03-08','2014-03-09','2014-03-10');"> /home/jrjt/testan/baitiao.dat;

8.自定義udf函數(shù)
? 1.繼承UDF類(lèi)
? 2.重寫(xiě)evaluate方法
? 3.把項(xiàng)目打成jar包
? 4.hive中執(zhí)行命令add jar /home/jrjt/dwetl/PUB/UDF/udf/GetProperty.jar;
? 5.創(chuàng)建函數(shù)create temporary function get_pro as 'jd.Get_Property'//jd.jd.Get_Property為類(lèi)路徑;
?
9.查詢顯示列名 及 行轉(zhuǎn)列顯示?
? set hive.cli.print.header=true; // 打印列名
? set hive.cli.print.row.to.vertical=true; // 開(kāi)啟行轉(zhuǎn)列功能, 前提必須開(kāi)啟打印列名功能
? set hive.cli.print.row.to.vertical.num=1; // 設(shè)置每行顯示的列數(shù)

10.查看表文件大小,下載文件到某個(gè)目錄,顯示多少行到某個(gè)文件
?? dfs -du hdfs://BJYZH3-HD-JRJT-4137.jd.com:54310/user/jrjt/warehouse/stage.db/s_h02_click_log;
?? dfs -get /user/jrjt/warehouse/ods.db/o_h02_click_log_i_new/dt=2014-01-21/000212_0 /home/jrjt/testan/;
?? head -n 1000 文件名 > 文件名

11.殺死某個(gè)任務(wù)? 不在hive shell中執(zhí)行
?? hadoop job -kill job_201403041453_58315
?
12.hive-wui路徑
?? http://172.17.41.38/jobtracker.jsp

13.刪除分區(qū)
?? alter table tmp_h02_click_log_baitiao drop partition(dt='2014-03-01');
?? alter table d_h02_click_log_basic_d_fact drop partition(dt='2014-01-17');
? ?

14.hive命令行操作
?? 執(zhí)行一個(gè)查詢,在終端上顯示mapreduce的進(jìn)度,執(zhí)行完畢后,最后把查詢結(jié)果輸出到終端上,接著hive進(jìn)程退出,不會(huì)進(jìn)入交互模式。
?? hive -e 'select table_cloum from table'
?? -S,終端上的輸出不會(huì)有mapreduce的進(jìn)度,執(zhí)行完畢,只會(huì)把查詢結(jié)果輸出到終端上。這個(gè)靜音模式很實(shí)用,,通過(guò)第三方程序調(diào)用,第三方程序通過(guò)hive的標(biāo)準(zhǔn)輸出獲取結(jié)果集。
?? hive -S -e 'select table_cloum from table'
?? 執(zhí)行sql文件
?? hive -f hive_sql.sql

?15.hive上操作hadoop文件基本命令
??? 查看文件大小
??? dfs -du /user/jrjt/warehouse/tmp.db/tmp_h02_click_log/dt=2014-02-15;
??? 刪除文件
??? dfs -rm /user/jrjt/warehouse/tmp.db/tmp_h02_click_log/dt=2014-02-15;

?16.插入數(shù)據(jù)sql、導(dǎo)出數(shù)據(jù)sql
?? ?1.insert 語(yǔ)法格式為:
?? ?基本的插入語(yǔ)法:
?? ?INSERT OVERWRITE TABLE tablename [PARTITON(partcol1=val1,partclo2=val2)]select_statement FROM from_statement
?? ?insert overwrite table test_insert select * from test_table;

?? ?對(duì)多個(gè)表進(jìn)行插入操作:
?? ?FROM fromstatte
?? ?INSERT OVERWRITE TABLE tablename1 [PARTITON(partcol1=val1,partclo2=val2)]select_statement1
?? ?INSERT OVERWRITE TABLE tablename2 [PARTITON(partcol1=val1,partclo2=val2)]select_statement2

?? ?from test_table??????????????????? ?
?? ?insert overwrite table test_insert1?
?? ?select key
?? ?insert overwrite table test_insert2
?? ?select value;

?? ?insert的時(shí)候,from子句即可以放在select 子句后面,也可以放在 insert子句前面。
?? ?hive不支持用insert語(yǔ)句一條一條的進(jìn)行插入操作,也不支持update操作。數(shù)據(jù)是以load的方式加載到建立好的表中。數(shù)據(jù)一旦導(dǎo)入就不可以修改。

?? ?2.通過(guò)查詢將數(shù)據(jù)保存到filesystem
?? ?INSERT OVERWRITE [LOCAL] DIRECTORY directory SELECT.... FROM .....

?? ?導(dǎo)入數(shù)據(jù)到本地目錄:
?? ?insert overwrite local directory '/home/zhangxin/hive' select * from test_insert1;
?? ?產(chǎn)生的文件會(huì)覆蓋指定目錄中的其他文件,即將目錄中已經(jīng)存在的文件進(jìn)行刪除。

?? ?導(dǎo)出數(shù)據(jù)到HDFS中:
?? ?insert overwrite directory '/user/zhangxin/export_test' select value from test_table;

?? ?同一個(gè)查詢結(jié)果可以同時(shí)插入到多個(gè)表或者多個(gè)目錄中:
?? ?from test_insert1
?? ?insert overwrite local directory '/home/zhangxin/hive' select *?
?? ?insert overwrite directory '/user/zhangxin/export_test' select value;

?17.mapjoin的使用 應(yīng)用場(chǎng)景:1.關(guān)聯(lián)操作中有一張表非常小 2.不等值的鏈接操作
??? select /*+ mapjoin(A)*/ f.a,f.b from A t join B f? on ( f.a=t.a and f.ftime=20110802)?

?18.perl啟動(dòng)任務(wù)
?? perl /home/jrjt/dwetl/APP/APP/A_H02_CLICK_LOG_CREDIT_USER/bin/a_h02_click_log_credit_user.pl?
?? APP_A_H02_CLICK_LOG_CREDIT_USER_20140215.dir >& /home/jrjt/dwetl/LOG/APP/20140306/a_h02_click_log_credit_user.pl.4.log

?19.查看perl進(jìn)程
?? ps -ef|grep perl

?20.hive命令移動(dòng)表數(shù)據(jù)到另外一張表目錄下并添加分區(qū)
?? dfs -cp /user/jrjt/warehouse/tmp.db/tmp_h02_click_log/dt=2014-02-18 /user/jrjt/warehouse/ods.db/o_h02_click_log/;
?? dfs -cp /user/jrjt/warehouse/tmp.db/tmp_h02_click_log_baitiao/* /user/jrjt/warehouse/dw.db/d_h02_click_log_baitiao_basic_d_fact/;--復(fù)制所有分區(qū)數(shù)據(jù)
?? alter table d_h02_click_log_baitiao_basic_d_fact add partition(dt='2014-03-11') location '/user/jrjt/warehouse/dw.db/d_h02_click_log_baitiao_basic_d_fact/dt=2014-03-11';
??
?21.導(dǎo)出白條數(shù)據(jù)
??? hive -e "select day_id,pv,uv,ip_count,click_next_count,second_bounce_rate,return_visit,pg_type from tmp.tmp_h02_click_log_baitiao_ag_sum where day_id like '2014-03%';"> /home/jrjt/testan/baitiao.xlsx;
? ?
?22.hive修改表名
??? ALTER TABLE o_h02_click_log_i RENAME TO o_h02_click_log_i_bk;
??
?23.hive復(fù)制表結(jié)構(gòu)
?? CREATE TABLE d_h02_click_log_baitiao_ag_sum LIKE tmp.tmp_h02_click_log_baitiao_ag_sum;


?24.hive官網(wǎng)網(wǎng)址
?? https://cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-InstallationandConfiguration
?? http://www.360doc.com/content/12/0111/11/7362_178698714.shtml
?25.hive添加字段
?? alter table tmp_h02_click_log_baitiao_ag_sum add columns(current_session_timelenth_count bigint comment '頁(yè)面停留總時(shí)長(zhǎng)');
?? ALTER TABLE tmp_h02_click_log_baitiao CHANGE current_session_timelenth current_session_timelenth bigint comment '當(dāng)前會(huì)話停留時(shí)間';
? ?
?26.hive開(kāi)啟簡(jiǎn)單模式不啟用mr
?? set hive.fetch.task.conversion=more;
?27.以json格式輸出執(zhí)行語(yǔ)句會(huì)讀取的input table和input partition信息
?? Explain dependency query?

Hive常用命令


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 玉屏| 阿荣旗| 图木舒克市| 平昌县| 固镇县| 陆丰市| 南岸区| 宝鸡市| 辛集市| 肃南| 阿坝县| 武陟县| 汾阳市| 青铜峡市| 绿春县| 揭东县| 鄂尔多斯市| 盐亭县| 抚宁县| 凯里市| 乐亭县| 道孚县| 屏东市| 武城县| 成都市| 密山市| 蒲江县| 石泉县| 扎赉特旗| 哈密市| 岐山县| 合水县| 浑源县| 阜宁县| 宿松县| 阿合奇县| 邯郸市| 康定县| 凤台县| 滦平县| 元谋县|