您可以使用hive库从python访问hive,因为要从hive导入ThriveHive导入hive类
下面的例子
import sysfrom hive import ThriftHivefrom hive.ttypes import HiveServerExceptionfrom thrift import Thriftfrom thrift.transport import TSocketfrom thrift.transport import TTransportfrom thrift.protocol import TBinaryProtocoltry: 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)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)