Happybase的基本使用

Happybase是Python通过Thrift访问HBase的库,方便快捷。

基本使用

 
 
  1. import happybase
  2. connection = happybase.Connection('hostname')
  3. table = connection.table('table-name')
  4. table.put('row-key', {'family:qual1': 'value1', 'family:qual2': 'value2'})
  5. row = table.row('row-key')
  6. print row['family:qual1'] # prints 'value1'
  7. for key, data in table.rows(['row-key-1', 'row-key-2']):
  8. print key, data # prints row key and data for each row
  9. for key, data in table.scan(row_prefix='row'):
  10. print key, data # prints 'value1' and 'value2'
  11. row = table.delete('row-key')

链接

 
 
  1. # lazy connection
  2. connection = happybase.Connection('somehost', autoconnect=False)
  3. # and before first use:
  4. connection.open()
  5. # show all tables
  6. print connection.tables()
  7. # Using table namespace
  8. connection = happybase.Connection('somehost', table_prefix='myproject')

 
 
  1. connection.create_table(
  2. 'mytable',
  3. {'cf1': dict(max_versions=10),
  4. 'cf2': dict(max_versions=1, block_cache_enabled=False),
  5. 'cf3': dict(), # use defaults
  6. }
  7. )
  8. table = connection.table('mytable')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值