原标题:用 Phoenix 通过 SQL 语句更新操作 HBase 数据
(点击上方公众号,可快速关注)
作者:伯乐在线 - ixirong
blog.jobbole.com/101003/
HBase 提供很方便的shell脚本,可以对数据表进行 CURD 操作,但是毕竟是有一定的学习成本的,基本上对于开发来讲,sql 语句都是看家本领,那么,有没有一种方法可以把 sql 语句转换成 hbase的原生API呢? 这样就可以通过普通平常的 sql 来对hbase 进行数据的管理,使用成本大大降低。
Apache Phoenix 组件就完成了这种需求,官方注解为 “Phoenix – we put the SQL back in NoSql”,通过官方说明,Phoenix 的性能很高,相对于 hbase 原生的scan 并不会差多少,而对于类似的组件 hive、Impala等,性能有着显著的提升,详细请阅读 https://phoenix.apache.org/performance.html。
Apache Phoenix 官方站点:https://phoenix.apache.org/
Phoenix支持的sql语句: https://phoenix.apache.org/language/index.html
Phoenix 支持的DataTypes:https://phoenix.apache.org/language/datatypes.html
Phoenix 支持的函数:https://phoenix.apache.org/language/functions.html
一、安装使用
Phoenix 安装很简单,下载对应hbase版本的Phoenix,以phoenix-4.4.0-HBase-0.98-bin.tar.gz为例,解压文件,将phoenix-4.4.0-server.jar 拷贝到hbase安装目录的lib下,注意:每台regionserver均需要拷贝,重启hbase server即可,官方如下:
download and expand the latest phoenix-[version]-bin.tar.
Add the phoenix-[version]-server.jar to the classpath of all HBase region server and master and remove any previous version. An easy way to do this is to copy it into the HBase lib directory (use phoenix-core-[version].jar for Phoenix 3.x)
restart the region servers