HBase创建表和列出表

编程入门 行业动态 更新时间:2024-10-25 22:26:38

<a href=https://www.elefans.com/category/jswz/34/1763617.html style=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创建表和列出表

本文发布于:2024-02-12 20:15:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1689255.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:HBase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!