重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

hive怎么导入mysql脚本

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

创新互联公司-专业网站定制、快速模板网站建设、高性价比仓山网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式仓山网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖仓山地区。费用合理售后完善,十载实体公司更值得信赖。

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脚本”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!


名称栏目:hive怎么导入mysql脚本
分享URL:http://cqcxhl.com/article/gjdshj.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP