問題ない。また、作成された列の値をダンプするだけでなく、変更された列の最後の 3 つのバージョンを実際にダンプします。
完全を期すために、Thrift を機能させるために大まかに次のことを行いました。
- Thrift をダウンロードしてビルドしました (SVN を使用.. 2012-11-15/1429368)。
- Pythonインターフェースファイルを作成したいパスから「thrift -gen py <thrift file>」を実行しました。
- 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')]