hbase php mutaterow,HBase中的mutateRow()通过Thrift需要未记录的第四个参数

没问题 . 而且,我实际上转储了修改列的最后三个版本,而不仅仅是转储已创建列的值,只是因为它很酷 .

为了完整起见,我粗略地做了以下工作以使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')]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Python使用Thrift连接HBase,您需要按照以下步骤进行设置: 1. 安装所需的依赖项: 您需要安装`thrift`和`happybase`这两个Python库。可以使用以下命令进行安装: ```bash pip install thrift happybase ``` 2. 生成HBaseThrift代码: 使用Thrift工具生成HBaseThrift代码。您可以使用以下命令: ```bash thrift -r --gen py hbase.thrift ``` 这将生成Python的Thrift代码文件。 3. 创建HBase连接: 在Python脚本,您需要首先创建一个HBase连接。示例代码如下: ```python import happybase connection = happybase.Connection(host='localhost', port=9090) ``` 4. 执行HBase操作: 在创建了HBase连接之后,您可以使用`connection`对象执行各种HBase操作,例如创建表、插入数据、获取数据等。以下是一些示例代码: - 创建表: ```python connection.create_table( 'mytable', { 'cf': dict(max_versions=10), } ) ``` - 插入数据: ```python table = connection.table('mytable') table.put( b'row1', { b'cf:col1': b'value1', b'cf:col2': b'value2', } ) ``` - 获取数据: ```python table = connection.table('mytable') row = table.row(b'row1') print(row) ``` - 删除数据: ```python table = connection.table('mytable') table.delete(b'row1') ``` 这只是一些示例代码,您可以根据需要使用其他HappyBase方法来执行更多操作。 5. 关闭连接: 当您完成HBase操作后,记得关闭连接以释放资源: ```python connection.close() ``` 请注意,为了成功执行这些操作,您需要确保HBase正在运行并且在指定的主机和端口上进行监听。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值