python调用hive与java调用区别_python 调用hive查询实现类似存储过程

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

****************ods_log_info*****************

lidstring

uidstring

mb_uidstring

operationstring

modulestring

resultstring

tsstring

remark1string

remark2string

remark3string

****************ods_mbportal_201407*****************

data_time_threadstring

data_modulestring

data_operationstring

data_resultstring

data_ipaddessstring

daystring

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

#!/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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值