没问题 . 而且,我实际上转储了修改列的最后三个版本,而不仅仅是转储已创建列的值,只是因为它很酷 .
为了完整起见,我粗略地做了以下工作以使Thrift工作:
下载并构建Thrift(使用SVN .. 2012-11-15 / 1429368) .
Ran "thrift -gen py "来自我想要创建Python接口文件的路径 .
通过PIP安装"thrift"包 .
我从生成的文件的根目录运行以下代码 .
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
from hbase.ttypes import *
from random import randrange
from pprint import pprint
socket = TSocket.TSocket('localhost', 9090)
transport = TTransport.TBufferedTransport(socket)
transport.open()
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = Hbase.Client(protocol)
table_name = 'test_table'
row_key = 'test_row1'
colfamily1 = 'test_colfamily1'
column1 = 'test_col1'
fullcol1 = ('%s:%s' % (colfamily1, column1))
value = ('%d' % randrange(1000, 9999))
num_versions = 3
try:
desc = ColumnDescriptor(colfamily1)
client.createTable(table_name, [desc])
except AlreadyExists:
pass
client.mutateRow(table_name, row_key, [Mutation(column=fullcol1, value=value)], {})
results = client.getVer(table_name, row_key, fullcol1, num_versions, {})
pprint(results)
输出:
$ python test.py
[TCell(timestamp=1357463438825L, value='9842')]
$ python test.py
[TCell(timestamp=1357463439700L, value='9166'),
TCell(timestamp=1357463438825L, value='9842')]
$ python test.py
[TCell(timestamp=1357463440359L, value='2978'),
TCell(timestamp=1357463439700L, value='9166'),
TCell(timestamp=1357463438825L, value='9842')]