HBase创建表和列出表"/>
HBase创建表和列出表
在Hbase Shell中使用命令创建一个表,基本语法:
create ‘
使用命令创建emp表:
Row key personal data professional data
1 在hbase shell 中输入命令:
create ‘emp’,’personal data’,’professional data’
通过list命令查看table列表,如图所示:
2 通过API接口来生成一个表,代码如下:
# coding=utf-8from thrift.transport.TSocket import TSocketfrom thrift.transport.TTransport import TBufferedTransportfrom thrift.protocol import TBinaryProtocolfrom hbase import Hbasefrom hbase.ttypes import ColumnDescriptor# 主机地址及端口号,端口号默认为9090host = 'localhost'port = 9090# 初始化链接transport = TBufferedTransport(TSocket(host, port))transport.open()protocol = TBinaryProtocol.TBinaryProtocol(transport)# 创建客户端client = Hbase.Client(protocol)# 显示当前hbase中的表print client.getTableNames()# 创建empbypy表column1 = ColumnDescriptor(name='personal data:')column2 = ColumnDescriptor(name='professional data:')client.createTable("empbypy",[column1,column2])print client.getTableNames()transport.close()
运行结果如下:
更多推荐
HBase创建表和列出表
发布评论