社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
<property>
<name>hbase.rootdir</name>
<value>/root/zhutong/hbase_data</value>
</property>
#!/usr/bin/python
#-*- coding:utf-8 -*-
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.protocol import TCompactProtocol
from hbase import Hbase
from hbase.ttypes import *
#192.168.110.78:8020
transport1 = TSocket.TSocket('localhost',9090 )
transport = TTransport.TBufferedTransport(transport1)
protocol = TCompactProtocol.TCompactProtocol(transport);
client = Hbase.Client(protocol)
transport.open()
contents=ColumnDescriptor(name='cf:',maxVersions=1)
tablename='ta'
client.createTable(tablename,[contents])
print client.getTableNames()
#!/usr/bin/python
#insert data
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
from hbase.ttypes import *
transport = TSocket.TSocket('localhost', 9090)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = Hbase.Client(protocol)
transport.open()
for i in range(10):
row = 'row-key1'+str(i)
mutations = [Mutation(column="cf:a", value=str(i))]
client.mutateRow('ta', row, mutations, None)
#!/usr/bin/python
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
from hbase.ttypes import *
transport = TSocket.TSocket('localhost', 9090)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = Hbase.Client(protocol)
transport.open()
tableName = 'ta'
rowKey = 'row-key1'
result = client.getRow(tableName, rowKey, None)
print result
print type(result)
for r in result:
print 'the row is ' , r.row
print 'the values is ' , r.columns.get('cf:a').value
#!/usr/bin/python
# get some data
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
from hbase.ttypes import *
transport = TSocket.TSocket('localhost', 9090)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = Hbase.Client(protocol)
transport.open()
scan = TScan()
tableName = 'ta'
id = client.scannerOpenWithScan(tableName, scan, None)
result2 = client.scannerGetList(id, 10)
print result2
print type(result2)
for i in result2:
print i.row
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!