這篇文章主要介紹“hive怎么導(dǎo)入MySQL腳本”,在日常操作中,相信很多人在hive怎么導(dǎo)入mysql腳本問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”hive怎么導(dǎo)入mysql腳本”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比倉山網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式倉山網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋倉山地區(qū)。費用合理售后完善,十載實體公司更值得信賴。
import subprocess
import sys
print "腳本名:", sys.argv[0]
tableName=sys.argv[1]
startdate=sys.argv[2]
enddate=sys.argv[3]
if startdate=="":
print "please input statdate !"
sys.exit()
if enddate=="" :
enddate=startdate
com=""
if tableName=="t_netflow_pc_city_cate_pv" :
#t_netflow_pc_city_cate_pv_yyyymm hql
com="hive -e \"use tmpdb; select statdate , chlname, pagetype,area1 ,cate1, cate2 , pv, uv ,newuv , visit,newvisit , avgpage , avgtime , jumpin , jumpout , outrate from ext_pctrack_is where statdate>='"+startdate+"' and statdate<='"+enddate+"' and cate3='A' and cate4='A' and cate5='A' and area2='A' and area3='A' and area4='A' and source1='A' and source2='A';\" > tmp/t_netflow_pc_city_cate_pv_"+startdate+".txt;"
elif tableName=="t_netflow_pc_source_cate_pv":
com="hive -e \"use tmpdb; select statdate , chlname, pagetype,source1 ,source2 , cate1, cate2,cate3 , pv, uv ,newuv , visit,newvisit , avgpage , avgtime , jumpin , jumpout , outrate from ext_pctrack_is where statdate>='"+startdate+"' and statdate<='"+enddate+"' and cate4='all' and cate5='all' and area1='all' and area2='all' and area3='all' and area4='all' ;\" > tmp/t_netflow_pc_source_cate_pv_"+enddate+".txt;"
elif tableName=="t_netflow_pc_pv":
com="hive -e \"use tmpdb; select statdate , chlname,pagetype,source1 , area1,cate1, pv, uv ,newuv , visit,newvisit , avgpage , avgtime , jumpin , jumpout , outrate from ext_pctrack_is where statdate>='"+startdate+"' and statdate<='"+enddate+"' and cate2='all' and cate3='all' and cate4='all' and cate5='all' and area2='all' and area3='all' and area4='all' and source2='all';\" > tmp/t_netflow_pc_pv_"+startdate+".txt;"
print com
def executeHql(hql):
p = subprocess.Popen(hql, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
res="1"
for line in p.stdout.readlines():
print line
if "Exception" in line :
executeHql(com)
res="0"
else :
res="1"
retval = p.wait()
return res
print "hive select start ------------------------------------------"
count=1
while 1:
print "count is ----------------------" +str(count)
count=count+1
res=executeHql(com)
if res=="1":
break
print "hive select end ------------------------------------------"
print "mysql load start ------------------------------------------"
mload="mysql -uXXX -pXXXX -hXXXX -PXXX -DXXX -e\"LOAD DATA LOCAL INFILE 'tmp/"+tableName+"_"+startdate+".txt' INTO TABLE "+tableName+" FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'\""
p = subprocess.Popen(mload, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
print line
retval = p.wait()
print "mysql load end ------------------------------------------"
到此,關(guān)于“hive怎么導(dǎo)入mysql腳本”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
分享題目:hive怎么導(dǎo)入mysql腳本
轉(zhuǎn)載注明:http://weahome.cn/article/gjdshj.html