python如何使用phoenixdb操作hbase

  介绍

这篇文章主要介绍python如何使用phoenixdb操作hbase,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

安装phoenixdb库

pip  install  phoenixdb

例子

首先启动queryserver服务

cd  apache -凤凰4.14.1 hbase - 1.4 - bin/bin/queryserver。py

然后使用下面代码来建立连接,创建/删除并查询表。代码比较简单,和我们通常查询关系型数据库比较类似,这里就不多说了哈。

import  phoenixdb   import  phoenixdb.cursor      时间=url  & # 39; http://localhost: 8765/& # 39;   conn =, phoenixdb.connect (url, autocommit=True)      时间=cursor  conn.cursor ()   #,cursor.execute (“DROP  TABLE  users")   cursor.execute (“CREATE  TABLE  users  (id  INTEGER  PRIMARY 关键,,username  VARCHAR、, password  VARCHAR)“)   cursor.execute (“UPSERT  INTO  users  VALUES (?, ?, ?)“,,(1, & # 39;行政与# 39;,,& # 39;Letmein& # 39;))   cursor.execute (“UPSERT  INTO  users  VALUES  (?, ?, ?)“,, (2), & # 39; kongxx& # 39;,, & # 39; Letmein& # 39;))   cursor.execute (“SELECT  *,得到users")   print  cursor.fetchall ()      时间=cursor  conn.cursor (cursor_factory=phoenixdb.cursor.DictCursor)   cursor.execute (“SELECT  *,得到users  WHERE  id=1“)   时间=user  cursor.fetchone ()   print 用户[& # 39;用户名# 39;】   print 用户[& # 39;密码# 39;]

最后运行这个程序看一下效果吧。

以上是“python如何使用phoenixdb操作hbase”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!

python如何使用phoenixdb操作hbase