forked from eljefe6a/HBaseThrift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.py
executable file
·58 lines (43 loc) · 1.92 KB
/
get.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python
from common import *
from thrift.transport import TSocket
from thrift.protocol import TBinaryProtocol
from thrift.transport import TTransport
from hbase import Hbase
# Connect to HBase Thrift server
transport = TTransport.TBufferedTransport(TSocket.TSocket(host, port))
protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
# Create and open the client connection
client = Hbase.Client(protocol)
transport.open()
rows = client.getRow(tablename, "shakespeare-comedies-000001")
# Do a pull on a single row
for row in rows:
# Pull out values in cell
message = row.columns.get(messagecolumncf).value
username = row.columns.get(usernamecolumncf).value
linenumber = decode(row.columns.get(linenumbercolumncf).value)
rowKey = row.row
print("Got row: " + rowKey + ":" + str(linenumber) + ":" + username + ":" + message);
# Open a scan over all comedy rows in Shakespeare
scan = Hbase.TScan(startRow="shakespeare-comedies-000001", stopRow="shakespeare-comedies-999999")
scannerId = client.scannerOpenWithScan(tablename, scan)
# Go through every row passed back by scanner
row = client.scannerGet(scannerId)
# Go through every row passed back by scanner
rowList = client.scannerGetList(scannerId,numRows)
while rowList:
for row in rowList:
# Pull out values in columns
message = row.columns.get(messagecolumncf).value
username = row.columns.get(usernamecolumncf).value
linenumber = decode(row.columns.get(linenumbercolumncf).value)
rowKey = row.row
if linenumber % 10 == 0 and message.find("again") != -1:
print(rowKey + ":" + str(linenumber) + ":" + username + ":" + message);
# Get the next row result
rowList = client.scannerGetList(scannerId,numRows)
# Close scanner now that we're done with it
client.scannerClose(scannerId)
# Close the client connection
transport.close()