使用python连接到Hive(cloudera)

时间:2018-07-10 14:53:25

标签: python hadoop hive pyhive

我使用此代码通过python连接到蜂巢

总是存在图书馆问题

#!/usr/bin/env python

import sys

from hive import ThriftHive
from hive.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()

    client.execute("CREATE TABLE r(a STRING, b INT, c DOUBLE)")
    client.execute("LOAD TABLE LOCAL INPATH '/path' INTO TABLE r")
    client.execute("SELECT * FROM r")
    while (1):
      row = client.fetchOne()
      if (row == None):
        break
      print row
    client.execute("SELECT * FROM r")
    print client.fetchAll()

    transport.close()

except Thrift.TException, tx:
    print '%s' % (tx.message)

错误:

 File "C:\Users\H001\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pyhive\hive.py", line 337
    def execute(self, operation, parameters=None, async=False):
                                                      ^
SyntaxError: invalid syntax

我已经安装了pyhive来导入hive,但是在pycharm中,他们不认识hive,我在anaconda中尝试过,这次他们问abouat

  

没有名为sasl的模块

0 个答案:

没有答案