HBASE-18291 Regenerate thrift2 python examples
Change thrift python example to version 0.9.3 Update instructions in DemoClient.py Change-Id: I5d2c2698c7f1c848b2c8bfaa761a6e1376811be3 Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
parent
0f39f08740
commit
9b9fd708b7
|
@ -18,12 +18,12 @@
|
||||||
"""
|
"""
|
||||||
# Instructions:
|
# Instructions:
|
||||||
# 1. Run Thrift to generate the python module hbase
|
# 1. Run Thrift to generate the python module hbase
|
||||||
# thrift --gen py ../../../../../hbase-server/src/main/resources/org/apache/hadoop \
|
# thrift --gen py ../../../../../hbase-thrift/src/main/resources/org/apache/hadoop \
|
||||||
# /hbase/thrift2/hbase.thrift
|
# /hbase/thrift2/hbase.thrift
|
||||||
# 2. Create a directory of your choosing that contains:
|
# 2. Create a directory of your choosing that contains:
|
||||||
# a. This file (DemoClient.py).
|
# a. This file (DemoClient.py).
|
||||||
# b. The directory gen-py/hbase (generated by instruction step 1).
|
# b. The directory gen-py/hbase (generated by instruction step 1).
|
||||||
# 3. pip install thrift==0.9.0
|
# 3. pip install thrift==0.9.3
|
||||||
# 4. Create a table call "example", with a family called "family1" using the hbase shell.
|
# 4. Create a table call "example", with a family called "family1" using the hbase shell.
|
||||||
# 5. Start the hbase thrift2 server
|
# 5. Start the hbase thrift2 server
|
||||||
# bin/hbase thrift2 start
|
# bin/hbase thrift2 start
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
#
|
#
|
||||||
# Autogenerated by Thrift Compiler (0.9.0)
|
# Autogenerated by Thrift Compiler (0.9.3)
|
||||||
#
|
#
|
||||||
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
||||||
#
|
#
|
||||||
|
@ -12,31 +12,39 @@ import pprint
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
from thrift.transport import TTransport
|
from thrift.transport import TTransport
|
||||||
from thrift.transport import TSocket
|
from thrift.transport import TSocket
|
||||||
|
from thrift.transport import TSSLSocket
|
||||||
from thrift.transport import THttpClient
|
from thrift.transport import THttpClient
|
||||||
from thrift.protocol import TBinaryProtocol
|
from thrift.protocol import TBinaryProtocol
|
||||||
|
|
||||||
import THBaseService
|
from hbase import THBaseService
|
||||||
from ttypes import *
|
from hbase.ttypes import *
|
||||||
|
|
||||||
if len(sys.argv) <= 1 or sys.argv[1] == '--help':
|
if len(sys.argv) <= 1 or sys.argv[1] == '--help':
|
||||||
print ''
|
print('')
|
||||||
print 'Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
|
print('Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] [-s[sl]] function [arg1 [arg2...]]')
|
||||||
print ''
|
print('')
|
||||||
print 'Functions:'
|
print('Functions:')
|
||||||
print ' bool exists(string table, TGet get)'
|
print(' bool exists(string table, TGet tget)')
|
||||||
print ' TResult get(string table, TGet get)'
|
print(' existsAll(string table, tgets)')
|
||||||
print ' getMultiple(string table, gets)'
|
print(' TResult get(string table, TGet tget)')
|
||||||
print ' void put(string table, TPut put)'
|
print(' getMultiple(string table, tgets)')
|
||||||
print ' bool checkAndPut(string table, string row, string family, string qualifier, string value, TPut put)'
|
print(' void put(string table, TPut tput)')
|
||||||
print ' void putMultiple(string table, puts)'
|
print(' bool checkAndPut(string table, string row, string family, string qualifier, string value, TPut tput)')
|
||||||
print ' void deleteSingle(string table, TDelete deleteSingle)'
|
print(' void putMultiple(string table, tputs)')
|
||||||
print ' deleteMultiple(string table, deletes)'
|
print(' void deleteSingle(string table, TDelete tdelete)')
|
||||||
print ' bool checkAndDelete(string table, string row, string family, string qualifier, string value, TDelete deleteSingle)'
|
print(' deleteMultiple(string table, tdeletes)')
|
||||||
print ' TResult increment(string table, TIncrement increment)'
|
print(' bool checkAndDelete(string table, string row, string family, string qualifier, string value, TDelete tdelete)')
|
||||||
print ' i32 openScanner(string table, TScan scan)'
|
print(' TResult increment(string table, TIncrement tincrement)')
|
||||||
print ' getScannerRows(i32 scannerId, i32 numRows)'
|
print(' TResult append(string table, TAppend tappend)')
|
||||||
print ' void closeScanner(i32 scannerId)'
|
print(' i32 openScanner(string table, TScan tscan)')
|
||||||
print ''
|
print(' getScannerRows(i32 scannerId, i32 numRows)')
|
||||||
|
print(' void closeScanner(i32 scannerId)')
|
||||||
|
print(' void mutateRow(string table, TRowMutations trowMutations)')
|
||||||
|
print(' getScannerResults(string table, TScan tscan, i32 numRows)')
|
||||||
|
print(' THRegionLocation getRegionLocation(string table, string row, bool reload)')
|
||||||
|
print(' getAllRegionLocations(string table)')
|
||||||
|
print(' bool checkAndMutate(string table, string row, string family, string qualifier, TCompareOp compareOp, string value, TRowMutations rowMutations)')
|
||||||
|
print('')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
pp = pprint.PrettyPrinter(indent = 2)
|
pp = pprint.PrettyPrinter(indent = 2)
|
||||||
|
@ -44,6 +52,7 @@ host = 'localhost'
|
||||||
port = 9090
|
port = 9090
|
||||||
uri = ''
|
uri = ''
|
||||||
framed = False
|
framed = False
|
||||||
|
ssl = False
|
||||||
http = False
|
http = False
|
||||||
argi = 1
|
argi = 1
|
||||||
|
|
||||||
|
@ -72,13 +81,17 @@ if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
|
||||||
framed = True
|
framed = True
|
||||||
argi += 1
|
argi += 1
|
||||||
|
|
||||||
|
if sys.argv[argi] == '-s' or sys.argv[argi] == '-ssl':
|
||||||
|
ssl = True
|
||||||
|
argi += 1
|
||||||
|
|
||||||
cmd = sys.argv[argi]
|
cmd = sys.argv[argi]
|
||||||
args = sys.argv[argi+1:]
|
args = sys.argv[argi+1:]
|
||||||
|
|
||||||
if http:
|
if http:
|
||||||
transport = THttpClient.THttpClient(host, port, uri)
|
transport = THttpClient.THttpClient(host, port, uri)
|
||||||
else:
|
else:
|
||||||
socket = TSocket.TSocket(host, port)
|
socket = TSSLSocket.TSSLSocket(host, port, validate=False) if ssl else TSocket.TSocket(host, port)
|
||||||
if framed:
|
if framed:
|
||||||
transport = TTransport.TFramedTransport(socket)
|
transport = TTransport.TFramedTransport(socket)
|
||||||
else:
|
else:
|
||||||
|
@ -89,84 +102,126 @@ transport.open()
|
||||||
|
|
||||||
if cmd == 'exists':
|
if cmd == 'exists':
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
print 'exists requires 2 args'
|
print('exists requires 2 args')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
pp.pprint(client.exists(args[0],eval(args[1]),))
|
pp.pprint(client.exists(args[0],eval(args[1]),))
|
||||||
|
|
||||||
|
elif cmd == 'existsAll':
|
||||||
|
if len(args) != 2:
|
||||||
|
print('existsAll requires 2 args')
|
||||||
|
sys.exit(1)
|
||||||
|
pp.pprint(client.existsAll(args[0],eval(args[1]),))
|
||||||
|
|
||||||
elif cmd == 'get':
|
elif cmd == 'get':
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
print 'get requires 2 args'
|
print('get requires 2 args')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
pp.pprint(client.get(args[0],eval(args[1]),))
|
pp.pprint(client.get(args[0],eval(args[1]),))
|
||||||
|
|
||||||
elif cmd == 'getMultiple':
|
elif cmd == 'getMultiple':
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
print 'getMultiple requires 2 args'
|
print('getMultiple requires 2 args')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
pp.pprint(client.getMultiple(args[0],eval(args[1]),))
|
pp.pprint(client.getMultiple(args[0],eval(args[1]),))
|
||||||
|
|
||||||
elif cmd == 'put':
|
elif cmd == 'put':
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
print 'put requires 2 args'
|
print('put requires 2 args')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
pp.pprint(client.put(args[0],eval(args[1]),))
|
pp.pprint(client.put(args[0],eval(args[1]),))
|
||||||
|
|
||||||
elif cmd == 'checkAndPut':
|
elif cmd == 'checkAndPut':
|
||||||
if len(args) != 6:
|
if len(args) != 6:
|
||||||
print 'checkAndPut requires 6 args'
|
print('checkAndPut requires 6 args')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
pp.pprint(client.checkAndPut(args[0],args[1],args[2],args[3],args[4],eval(args[5]),))
|
pp.pprint(client.checkAndPut(args[0],args[1],args[2],args[3],args[4],eval(args[5]),))
|
||||||
|
|
||||||
elif cmd == 'putMultiple':
|
elif cmd == 'putMultiple':
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
print 'putMultiple requires 2 args'
|
print('putMultiple requires 2 args')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
pp.pprint(client.putMultiple(args[0],eval(args[1]),))
|
pp.pprint(client.putMultiple(args[0],eval(args[1]),))
|
||||||
|
|
||||||
elif cmd == 'deleteSingle':
|
elif cmd == 'deleteSingle':
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
print 'deleteSingle requires 2 args'
|
print('deleteSingle requires 2 args')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
pp.pprint(client.deleteSingle(args[0],eval(args[1]),))
|
pp.pprint(client.deleteSingle(args[0],eval(args[1]),))
|
||||||
|
|
||||||
elif cmd == 'deleteMultiple':
|
elif cmd == 'deleteMultiple':
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
print 'deleteMultiple requires 2 args'
|
print('deleteMultiple requires 2 args')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
pp.pprint(client.deleteMultiple(args[0],eval(args[1]),))
|
pp.pprint(client.deleteMultiple(args[0],eval(args[1]),))
|
||||||
|
|
||||||
elif cmd == 'checkAndDelete':
|
elif cmd == 'checkAndDelete':
|
||||||
if len(args) != 6:
|
if len(args) != 6:
|
||||||
print 'checkAndDelete requires 6 args'
|
print('checkAndDelete requires 6 args')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
pp.pprint(client.checkAndDelete(args[0],args[1],args[2],args[3],args[4],eval(args[5]),))
|
pp.pprint(client.checkAndDelete(args[0],args[1],args[2],args[3],args[4],eval(args[5]),))
|
||||||
|
|
||||||
elif cmd == 'increment':
|
elif cmd == 'increment':
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
print 'increment requires 2 args'
|
print('increment requires 2 args')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
pp.pprint(client.increment(args[0],eval(args[1]),))
|
pp.pprint(client.increment(args[0],eval(args[1]),))
|
||||||
|
|
||||||
|
elif cmd == 'append':
|
||||||
|
if len(args) != 2:
|
||||||
|
print('append requires 2 args')
|
||||||
|
sys.exit(1)
|
||||||
|
pp.pprint(client.append(args[0],eval(args[1]),))
|
||||||
|
|
||||||
elif cmd == 'openScanner':
|
elif cmd == 'openScanner':
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
print 'openScanner requires 2 args'
|
print('openScanner requires 2 args')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
pp.pprint(client.openScanner(args[0],eval(args[1]),))
|
pp.pprint(client.openScanner(args[0],eval(args[1]),))
|
||||||
|
|
||||||
elif cmd == 'getScannerRows':
|
elif cmd == 'getScannerRows':
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
print 'getScannerRows requires 2 args'
|
print('getScannerRows requires 2 args')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
pp.pprint(client.getScannerRows(eval(args[0]),eval(args[1]),))
|
pp.pprint(client.getScannerRows(eval(args[0]),eval(args[1]),))
|
||||||
|
|
||||||
elif cmd == 'closeScanner':
|
elif cmd == 'closeScanner':
|
||||||
if len(args) != 1:
|
if len(args) != 1:
|
||||||
print 'closeScanner requires 1 args'
|
print('closeScanner requires 1 args')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
pp.pprint(client.closeScanner(eval(args[0]),))
|
pp.pprint(client.closeScanner(eval(args[0]),))
|
||||||
|
|
||||||
|
elif cmd == 'mutateRow':
|
||||||
|
if len(args) != 2:
|
||||||
|
print('mutateRow requires 2 args')
|
||||||
|
sys.exit(1)
|
||||||
|
pp.pprint(client.mutateRow(args[0],eval(args[1]),))
|
||||||
|
|
||||||
|
elif cmd == 'getScannerResults':
|
||||||
|
if len(args) != 3:
|
||||||
|
print('getScannerResults requires 3 args')
|
||||||
|
sys.exit(1)
|
||||||
|
pp.pprint(client.getScannerResults(args[0],eval(args[1]),eval(args[2]),))
|
||||||
|
|
||||||
|
elif cmd == 'getRegionLocation':
|
||||||
|
if len(args) != 3:
|
||||||
|
print('getRegionLocation requires 3 args')
|
||||||
|
sys.exit(1)
|
||||||
|
pp.pprint(client.getRegionLocation(args[0],args[1],eval(args[2]),))
|
||||||
|
|
||||||
|
elif cmd == 'getAllRegionLocations':
|
||||||
|
if len(args) != 1:
|
||||||
|
print('getAllRegionLocations requires 1 args')
|
||||||
|
sys.exit(1)
|
||||||
|
pp.pprint(client.getAllRegionLocations(args[0],))
|
||||||
|
|
||||||
|
elif cmd == 'checkAndMutate':
|
||||||
|
if len(args) != 7:
|
||||||
|
print('checkAndMutate requires 7 args')
|
||||||
|
sys.exit(1)
|
||||||
|
pp.pprint(client.checkAndMutate(args[0],args[1],args[2],args[3],eval(args[4]),args[5],eval(args[6]),))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print 'Unrecognized method %s' % cmd
|
print('Unrecognized method %s' % cmd)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
transport.close()
|
transport.close()
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Autogenerated by Thrift Compiler (0.9.0)
|
# Autogenerated by Thrift Compiler (0.9.3)
|
||||||
#
|
#
|
||||||
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
||||||
#
|
#
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue