Python编程happybase读写HBase数据库

网友投稿 935 2022-05-30

happybase文档:

https://happybase.readthedocs.io/en/latest/

安装

pip install happybase

1

表操作

import happybase # 连接数据库 connection = happybase.Connection(host='hostname', port=9090) # 查询所有表 table_name_list = connection.tables() # 建表 families = { 'user_info': dict(), 'history': dict() } connection.create_table('table_name', families) # 删除表 connection.delete_table(name, disable=False)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

数据操作

table = connection.table('table-name') # 获取列族信息 info_dict = table.families() # 添加数据 data = { 'family:key1': 'value1', 'family:key2': 'value2' } table.put(b'row-key', data) # 查询数据 row = table.row(b'row-key') # 删除数据 row = table.delete(b'row-key')

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

批量数据操作

# 批量添加 bat = table.batch() bat.put('row-key1', {'family:key1': 'value1', 'family:key2': 'value2'}) bat.put('row-key2', {'family:key1': 'value1', 'family:key2': 'value2'}) bat.send() # 批量查询 rows_list = table.rows(['row-key1', 'row-key2']) # 返回list rows_dict = dict(table.rows(['row-key1', 'row-key2']))# 返回dict

1

2

3

4

5

6

7

8

9

Python编程:happybase读写HBase数据库

10

参考

Python操作HBase之happybase

HBase Python 数据库

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Graphviz使用
下一篇:Python编程:trio模块异步/等待本地I/O库
相关文章