1、使用hbase shell读取数据使用get命令,格式如下:
get 'tablename','row'
读取emp表中第一行数据:
get 'emp','1'
读取指定的列命令如下:
get 'tablename','row',{COLUMN=>'column family:column name'}
读取emp表中personal data:name列:
get 'emp','1',{COLUMN=>'personal data:name'}
2、使用python thrift API读取数据,代码如下:
# coding=utf-8
from thrift.transport.TSocket import TSocket
from thrift.transport.TTransport import TBufferedTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
from hbase.ttypes import *
# 主机地址及端口号,端口号默认为9090
host = '192.168.83.135'
port = 9090
# 初始化链接
transport = TBufferedTransport(TSocket(host, port))
transport.open()
protocol = TBinaryProtocol.TBinaryProtocol(transport)
# 创建客户端
client = Hbase.Client(protocol)
# 读取数据
print client.getRow('empbypy','1')
print client.getRowWithColumns('empbypy','1',['personal data:name'])
transport.close()
程序运行结果如下: