需求:数据仓库中所有表的定义结构保存到新的文件中,保存后类似下面数据,重复的数据只保留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查询实现类似存储过程的更多相关文章

  1. hive查询语句入门(hive DDL)

    hive DDL 启动hadoop /apps/hadoop/sbin/start-all.sh 开启MySQL库,用于存放hive的元数据 sudo service mysql start 启动hi ...

  2. python 调用mysql存储过程返回结果集

    存储过程: delimiter | ),)) begin select * from tb_test where mid = imid and user = iuser; end; | delimit ...

  3. python调用oracle存储过程

    oracle 存储过程 python调用oracle存储过程 -- 通过cx_Oracle连接 import cx_Oracle # 连接数据库 orcl_engine = 'scott/s123@x ...

  4. python调用存储过程失败返回1787错误

    (1787, 'When @@GLOBAL.ENFORCE_GTID_CONSISTENCY = 1, the statements CREATE TEMPORARY TABLE and DROP T ...

  5. python调用数据库并查询

    http://blog.csdn.net/pipisorry/article/details/48024795 python调用数据库命令 conn = sqlite3.connect(". ...

  6. 精通 Oracle+Python,第 5 部分:存储过程、Python 编程

    调用数据库存储过程及其他感兴趣的高级 Python 编程功能. 2010 年 3 月发布 对于涉及数据库的软件开发来说,有两种主流开发方法:一种是在应用程序中(对于三层体系结构,也可以是在中间件中)实 ...

  7. python调用c\c++

    前言 python 这门语言,凭借着其极高的易学易用易读性和丰富的扩展带来的学习友好性和项目友好性,近年来迅速成为了越来越多的人们的首选.然而一旦拿python与传统的编程语言(C/C++)如来比较的 ...

  8. Python 散列表查询_进入<哈希函数>为结界的世界

    1. 前言 哈希表或称为散列表,是一种常见的.使用频率非常高的数据存储方案. 哈希表属于抽象数据结构,需要开发者按哈希表数据结构的存储要求进行 API 定制,对于大部分高级语言而言,都会提供已经实现好 ...

  9. python调用py中rar的路径问题。

    1.python调用py,在py中的os.getcwd()获取的不是py的路径,可以通过os.path.split(os.path.realpath(__file__))[0]来获取py的路径. 2. ...

随机推荐

  1. 全国计算机等级考试二级教程-C语言程序设计_第9章_数组

    四维数组,可用于航天卫星,三维+时间 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> ...

  2. 弱类型语言中的0和空字符串(''或"")以及字符串'0'

    在弱类型语言(js/PHP)中, 当我们用==判断0和'0'以及空字符串(''或"")是否相等的时候, 返回的是true. 而且在PHP中, 当我们用==判断0和null是否相等的 ...

  3. cf-公式专场

    A. Again Twenty Five! time limit per test 0.5 seconds memory limit per test 64 megabytes input stand ...

  4. 创建SDE表空间

    创建空间数据存储类型为ST_Geometry的要素类有2种方法:1)使用SDE创建要素类从9.3 开始,默认创建的要素类都使用ST_Geometry存储空间数据,9.3 版本之前,可以通过配置dbtu ...

  5. 为什么getline()后要两次回车????(将输入的字符串按单词倒序输出)

    #include<iostream>#include<string>#include<algorithm>using namespace std;int main( ...

  6. 使用jQuery出现the function undefined

    出现function undefined往往是相关的JS文件没有导入导致,在相关文件都导入的情况下,使用jQuery提供的方法还会出现function undefined错误,或许就是jQuery对象 ...

  7. MYSQL中的普通索引,主健,唯一,全文索引区别

    MYSQL索引用来快速地寻找那些具有特定值的记录,所有MySQL索引都以B-树的形式保存.如果没有索引,执行查询时MySQL必须从第一个记录开始扫描整个表的所有记录,直至找到符合要求的记录.表里面的记 ...

  8. Matlab插值计算各时刻磁法勘探日变观测值

    Matlab插值计算各时刻磁法勘探日变观测值 在磁法勘探中,消日变影响的改正称为日变改正.进行日变改正时必须设立日变站,观测日变情况.根据日变数据和测点观测时间,对观测数据进行改正. 在本次磁法实习中 ...

  9. [原创]linux简单之美(三)

    原文链接:linux简单之美(三) 在linux简单之美(二)中我们尝试使用了C库的函数完成功能,那么能不能用syscall方式来搞呢?显然可以! section .data ft db sectio ...

  10. “Options模式”下的配置是如何绑定为Options对象

    “Options模式”下的配置是如何绑定为Options对象 配置的原子结构就是单纯的键值对,并且键和值都是字符串,但是在真正的项目开发中我们一般不会单纯地以键值对的形式来使用配置.值得推荐的做法就是 ...