Created
May 19, 2015 00:30
-
-
Save thrasibule/d78410a7ee0779c4625e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment