码迷,mamicode.com
首页 > 编程语言 > 详细

python 调用hive查询实现类似存储过程

时间:2014-07-14 14:29:01      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:des   文件   os   数据   2014   art   

需求:数据仓库中所有表的定义结构保存到新的文件中,保存后类似下面数据,重复的数据只保留7月份即可


****************ods_log_info*****************
lid string
uid string
mb_uid string
operation string
module string
result string
ts string
remark1 string
remark2 string
remark3 string

****************ods_mbportal_201407*****************
data_time_thread string
data_module string
data_operation string
data_result string
data_ipaddess string
day string

 

****************************************************************************

 

#!/usr/bin/env python

import sys
import re

from hive_service import ThriftHive
from hive_service.ttypes import HiveServerException
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol

try:
transport = TSocket.TSocket(‘localhost‘, 10000)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)

client = ThriftHive.Client(protocol)
transport.open()

query = ‘‘‘
show tables ‘‘‘

client.execute(query)
row = client.fetchAll()
fp = open(r"dw_struct.txt","w")
p = re.compile("201[34][01][0-6|8-9]")
print "Excuting ZZZZZZZZZZ"
for line in row:
m = p.search(line)
if m == None:

qq = "desc " + line
client.execute(qq)
result = client.fetchAll()

fp.write("****************" + line + "*****************\n")
for resLine in result:
if not resLine.startswith("col"):
fp.write(resLine + "\n")
fp.write("\n")
fp.close()
print "Excute OK"

transport.close()
except Thrift.TException, tx:
print ‘%s‘ % (tx.message)

python 调用hive查询实现类似存储过程,布布扣,bubuko.com

python 调用hive查询实现类似存储过程

标签:des   文件   os   数据   2014   art   

原文地址:http://www.cnblogs.com/charlie-badegg/p/3841872.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!