日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

hive脚本执行方式

發(fā)布時(shí)間:2024/1/17 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hive脚本执行方式 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

1. hive腳本的執(zhí)行方式

hive腳本的執(zhí)行方式大致有三種:?
1.?hive控制臺(tái)執(zhí)行;?
2.?hive -e "SQL"執(zhí)行;?
3.?hive -f SQL文件執(zhí)行;

參考hive的用法

usage: hive-d,--define <key=value> Variable subsitution to apply to hivecommands. e.g. -d A=B or --define A=B--database <databasename> Specify the database to use-e <quoted-query-string> SQL from command line-f <filename> SQL from files-H,--help Print help information-h <hostname> connecting to Hive Server on remote host--hiveconf <property=value> Use value for given property--hivevar <key=value> Variable subsitution to apply to hivecommands. e.g. --hivevar A=B-i <filename> Initialization SQL file-p <port> connecting to Hive Server on port number-S,--silent Silent mode in interactive shell-v,--verbose Verbose mode (echo executed SQL to theconsole)

1.1.?hive控制臺(tái)執(zhí)行

顧名思義,是進(jìn)入hive控制臺(tái)以后,執(zhí)行sql腳本,例如:

hive> set mapred.job.queue.name=pms; hive> select page_name, tpa_name from pms.pms_exps_prepro limit 2; Total MapReduce jobs = 1 Launching Job 1 out of 1 ... Job running in-process (local Hadoop) 2015-10-23 10:06:47,756 null map = 100%, reduce = 0% 2015-10-23 10:06:48,863 null map = 23%, reduce = 0% 2015-10-23 10:06:49,946 null map = 38%, reduce = 0% 2015-10-23 10:06:51,051 null map = 72%, reduce = 0% 2015-10-23 10:06:52,129 null map = 100%, reduce = 0% Ended Job = job_local1109193547_0001 Execution completed successfully Mapred Local Task Succeeded . Convert the Join into MapJoin OK APP首頁 APP首頁_價(jià)格比京東低 APP首頁 APP首頁_價(jià)格比京東低 Time taken: 14.279 seconds hive>

1.2.?hive -e "SQL"方式執(zhí)行

利用hive -e "SQL"的方式進(jìn)入hive控制臺(tái)并直接執(zhí)行sql腳本,例如:

hive -e " set mapred.job.queue.name=pms; set mapred.job.name=[HQL]exps_prepro_query;select page_name, tpa_name from pms.pms_exps_prepro limit 2;"

1.3.?hive -f SQL文件方式執(zhí)行

執(zhí)行sql文件中的sql腳本,例如:

pms_exps_prepro.sql文件內(nèi)容如下:

set mapred.job.queue.name=pms; set hive.exec.reducers.max=48; set mapred.reduce.tasks=48; set mapred.job.name=[HQL]pms_exps_prepro;drop table if exists pms.pms_exps_prepro; create table pms.pms_exps_prepro as select a.provinceid,a.cityid,a.ieversion,a.platform,'${date}' as ds from track_exps a;

上述文件中的sql腳本接收一個(gè)日期,接收參數(shù)寫法類似${date},執(zhí)行時(shí)如下執(zhí)行:

date=2015-10-22 hive -f pms_exps_prepro.sql --hivevar date=$date

2. hive轉(zhuǎn)義字符的問題

下面以一個(gè)業(yè)務(wù)場景闡述關(guān)于hive轉(zhuǎn)義字符的問題

track_exps記錄曝光數(shù)據(jù),現(xiàn)在小A希望獲取2015-10-20有效的曝光數(shù)據(jù)?
其中有效的曝光記錄是指,?
*?relatedinfo字段滿足數(shù)字.數(shù)字.數(shù)字.數(shù)字.數(shù)字的格式,?
例如4.4.5.1080100.1

  • extfield1字段滿足request-字符串,section-數(shù)字的格式,?
    例如request-b470805b620900ac492bb892ad7e955e,section-4

對于這個(gè)問題,小A寫出了如下sql腳本:

select * from track_exps where ds = '2015-10-20'and relatedinfo rlike '^4.\d+.\d+.\d+.\d+$' and extfield1 rlike '^request.+section-\d+$';

但是由于正則表達(dá)式是被包含在sql里面,所以里面的特殊字符需要轉(zhuǎn)義

2.1.?hive -e "SQL"的方式執(zhí)行

改動(dòng)如下:

hive -e " set mapred.job.queue.name=pms;explain select cityid from track_exps where ds = '2015-10-20'and relatedinfo rlike '\\^4\\.\\\d\\+\\.\\\d\\+\\.\\\d\\+\\.\\\d\\+\\$' and extfield1 rlike '\\^request\\.\\+section\\-\\\d\\+\\$';"

查看執(zhí)行計(jì)劃,可以確定正則表達(dá)式解析正確了:

... predicate:expr: ((relatedinfo rlike '^4.\d+.\d+.\d+.\d+$') and (extfield1 rlike '^request.+section-\d+$'))type: boolean ...

分析如下:

在hive -e "SQL"的執(zhí)行方式中,"'正則表達(dá)式'",正則表達(dá)式先被一個(gè)單引號(hào)括起來,再被一個(gè)雙引號(hào)括起來的,所以正則表達(dá)式里面,\\^的第一個(gè)\用來解析第二個(gè)\,第二個(gè)\才真正起到了轉(zhuǎn)義的作用

2.2.?hive -f SQL文件的方式執(zhí)行

改動(dòng)如下:

pms_exps_prepro.sql文件內(nèi)容如下:

select * from track_exps where ds = '2015-10-20'and relatedinfo rlike '\^4\.\\d\+\.\\d\+\.\\d\+\.\\d\+\$' and extfield1 rlike '\^request\.\+section\-\\d\+\$';

分析如下:

不同于hive -e "SQL"的執(zhí)行方式,因?yàn)槭莝ql文件,所以正則表達(dá)式只被一個(gè)單引號(hào)括起來而已,一個(gè)\就起到了轉(zhuǎn)義的作用了

轉(zhuǎn)載于:https://my.oschina.net/u/2000675/blog/1920416

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的hive脚本执行方式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。