温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

hive怎么导入mysql脚本

发布时间:2021-09-16 13:42:15 来源:亿速云 阅读:144 作者:chen 栏目:云计算

这篇文章主要介绍“hive怎么导入mysql脚本”,在日常操作中,相信很多人在hive怎么导入mysql脚本问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”hive怎么导入mysql脚本”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

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 ------------------------------------------"

到此,关于“hive怎么导入mysql脚本”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI