python 调用hive查询实现类似存储过程
需求:数据仓库中所有表的定义结构保存到新的文件中,保存后类似下面数据,重复的数据只保留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查询实现类似存储过程的更多相关文章
- hive查询语句入门(hive DDL)
hive DDL 启动hadoop /apps/hadoop/sbin/start-all.sh 开启MySQL库,用于存放hive的元数据 sudo service mysql start 启动hi ...
- python 调用mysql存储过程返回结果集
存储过程: delimiter | ),)) begin select * from tb_test where mid = imid and user = iuser; end; | delimit ...
- python调用oracle存储过程
oracle 存储过程 python调用oracle存储过程 -- 通过cx_Oracle连接 import cx_Oracle # 连接数据库 orcl_engine = 'scott/s123@x ...
- python调用存储过程失败返回1787错误
(1787, 'When @@GLOBAL.ENFORCE_GTID_CONSISTENCY = 1, the statements CREATE TEMPORARY TABLE and DROP T ...
- python调用数据库并查询
http://blog.csdn.net/pipisorry/article/details/48024795 python调用数据库命令 conn = sqlite3.connect(". ...
- 精通 Oracle+Python,第 5 部分:存储过程、Python 编程
调用数据库存储过程及其他感兴趣的高级 Python 编程功能. 2010 年 3 月发布 对于涉及数据库的软件开发来说,有两种主流开发方法:一种是在应用程序中(对于三层体系结构,也可以是在中间件中)实 ...
- python调用c\c++
前言 python 这门语言,凭借着其极高的易学易用易读性和丰富的扩展带来的学习友好性和项目友好性,近年来迅速成为了越来越多的人们的首选.然而一旦拿python与传统的编程语言(C/C++)如来比较的 ...
- Python 散列表查询_进入<哈希函数>为结界的世界
1. 前言 哈希表或称为散列表,是一种常见的.使用频率非常高的数据存储方案. 哈希表属于抽象数据结构,需要开发者按哈希表数据结构的存储要求进行 API 定制,对于大部分高级语言而言,都会提供已经实现好 ...
- python调用py中rar的路径问题。
1.python调用py,在py中的os.getcwd()获取的不是py的路径,可以通过os.path.split(os.path.realpath(__file__))[0]来获取py的路径. 2. ...
随机推荐
- #include <fstream>
1 fstream 2 ifstream 3 ofstream 4 seekg 5 seekp 6 tellg 7 tellp 1 fstream 打开输入输出文件流 #include <ios ...
- MGTemplateEngine 模版引擎简单使用(转)
原文:http://blog.csdn.net/crazy_srufboy/article/details/21748995 要实现的效果 首先上图中间的 标题至内容 都是使用UIWebView显示, ...
- Android SoundPool 的使用以及原理分析
好吧,我们今天来聊聊SoundPool这东西. 据说这个东西是冰激凌(Android4.0)里才引入的一个新东西.按照官方的意思大多数情况下是给游戏开发用的,比如一个游戏10关,它能在游戏开始前一次加 ...
- 【巧妙思维】【4-6】Problem F
题意:有n个正方体,边长为A[i] 当A[k]-A[p]<=lim 时 k可以放在p上面, 问有多少种放法: 一开始被数据范围吓到了 ,以为是n^3算法,答案是nlogn 从小到大排序,一个一个 ...
- Zoom属性的使用介绍(IE私有属性)
其实Zoom属性是IE浏览器的专有属性,Firefox等浏览器不支持.它可以设置或检索对象的缩放比例.除此之外,它还有其他一些小作用,比如触发ie的hasLayout属性,清除浮动.清除margi ...
- CRM Entity 之Money转string int类型等
Money转string 左右都是string //服务站地址 vehicleDetail["yt_servicestation_address"]=serviceStationC ...
- 微信sdk (1)
<?php /** * wechat php test */ //define your token define("TOKEN", "weixin"); ...
- 编程实现任意长度整数的加法(整数可以长度超出C++中int范围)
#include <iostream> #include<string> using namespace std; string add(string s1,string s2 ...
- leetcode Letter Combinations of a Phone Number python
class Solution(object): def letterCombinations(self, digits): """ :type digits: str : ...
- Linux学习之route
Linux系统的route命令用于显示和操作IP路由表(show / manipulate the IP routing table).要实现两个不同的子网之间的通信,需要一台连接两个网络的路由器,或 ...