Python Remote Access Hive

Source: Internet
Author: User

#!/usr/bin/python
Import Sys
Sys.path.append ('/home/zhoujie/downloads/hive-0.7.0-cdh3u0/lib/py ')
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


hive_server_ip= ' 127.0.0.1 '
hive_server_port=10000
#hive_sql = ' SELECT count (*) from Ssp_factbids '
Hive_sql= "SELECT COUNT (*) from ssp_factbids where logdate_id= ' 20121101 '"


def hiveexe (SQL):
Try
Transport = Tsocket.tsocket (HIVE_SERVER_IP, Hive_server_port)
Transport = Ttransport.tbufferedtransport (transport)
protocol = Tbinaryprotocol.tbinaryprotocol (transport)
Client = thrifthive.client (protocol)
Transport.open ()

Client.execute (SQL)

Print "The return value is:"
Print Client.fetchall ()
Print "......"
Transport.close ()
Except Thrift.texception, TX:
print '%s '% (tx.message)

if __name__ = = ' __main__ ':
Hiveexe (Hive_sql)

Python Remote Access Hive

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.