如何訪問hbase
⑴ Hbase怎麼連接報錯reflect.invocationtargetexception
InvocationTargetException異常由Method.invoke(obj, args...)方法拋出。當被調用的方法的內部拋出了異常而沒有被捕獲時,將由此異常接收。
至於具體原因,就要看代碼和詳細的錯誤信息了。
⑵ 在hbase三層結構下客戶端怎麼樣訪問到數據的
首先訪問Zookeeper,獲取-ROOT表的位置信息,然後訪問-ROOT表,獲得.MATA.表的信息,接著訪問.MATA.表,找到所需的Region具體位於哪個伺服器,最後才找到該Region伺服器讀取數據。
⑶ 如何在python中訪問HBase的數據
python訪問hbase數據
#!/usr/bin/python
import getopt,sys,time
from thrift.transport.TSocket import TSocket
from thrift.transport.TTransport import TBufferedTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
def usage():
print '''Usage :
-h: Show help information;
-l: Show all table in hbase;
-t {table} Show table descriptors;
-t {table} -k {key} : show cell;
-t {table} -k {key} -c {coulmn} : Show the coulmn;
-t {table} -k {key} -c {coulmn} -v {versions} : Show more version;
(write by [email protected])
'''
class geilihbase:
def __init__(self):
self.transport = TBufferedTransport(TSocket("127.0.0.1", "9090"))
self.transport.open()
self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
self.client = Hbase.Client(self.protocol)
def __del__(self):
self.transport.close()
def glisttable(self):
for table in self.client.getTableNames():
print table
def ggetColumnDescriptors(self,table):
rarr=self.client.getColumnDescriptors(table)
if rarr:
for (k,v) in rarr.items():
print "%-20s %s" % (k,v)
def gget(self,table,key,coulmn):
rarr=self.client.get(table,key,coulmn)
if rarr:
print "%-15s %-20s %s" % (rarr[0].timestamp,time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(rarr[0].timestamp/1000)),rarr[0].value)
def ggetrow(self,table,key):
rarr=self.client.getRow(table, key)
if rarr:
for (k,v) in rarr[0].columns.items():
print "%-20s %-15s %-20s %s" % (k,v.timestamp,time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(v.timestamp/1000)),v.value)
def ggetver(self, table, key, coulmn, versions):
rarr=self.client.getVer(table,key,coulmn, versions);
if rarr:
for row in rarr:
print "%-15s %-20s %s" % (row.timestamp,time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(row.timestamp/1000)),row.value)
def main(argv):
tablename=""
key=""
coulmn=""
versions=""
try:
opts, args = getopt.getopt(argv, "lht:k:c:v:", ["help","list"])
except getopt.GetoptError:
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit(0)
elif opt in ("-l", "--list"):
ghbase=geilihbase()
ghbase.glisttable()
sys.exit(0)
elif opt == '-t':
tablename = arg
elif opt == '-k':
key = arg
elif opt == '-c':
coulmn = arg
elif opt == '-v':
versions = int(arg)
if ( tablename and key and coulmn and versions ):
ghbase=geilihbase()
ghbase.ggetver(tablename, key, coulmn, versions)
sys.exit(0)
if (tablename and key and coulmn ):
ghbase=geilihbase()
ghbase.gget(tablename, key, coulmn)
sys.exit(0)
if (tablename and key ):
ghbase=geilihbase()
ghbase.ggetrow(tablename, key)
sys.exit(0)
if (tablename ):
ghbase=geilihbase()
ghbase.ggetColumnDescriptors(tablename)
sys.exit(0)
usage()
sys.exit(1)
if __name__ == "__main__":
main(sys.argv[1:])