python 调用hive查询实现类似存储过程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python 调用hive查询实现类似存储过程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1633字,纯文字阅读大概需要3分钟。
内容图文
需求:数据仓库中所有表的定义结构保存到新的文件中,保存后类似下面数据,重复的数据只保留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)
原文:http://www.cnblogs.com/charlie-badegg/p/3841872.html
内容总结
以上是互联网集市为您收集整理的python 调用hive查询实现类似存储过程全部内容,希望文章能够帮你解决python 调用hive查询实现类似存储过程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。