phoenix开启schema对应hbase中的namespace

开启schema与namespace的对应关系

如果使用了hbase中的自定义namespace,不仅仅使用default,那么在phoenix中与之对应的是schema的概念,但是默认并没有开启,需要在hbase-site.xml中增加以下配置项:

    <property>
      <name>phoenix.schema.isNamespaceMappingEnabled</name>
      <value>true</value>
    </property>
    <property>
      <name>phoenix.schema.mapSystemTablesToNamespace</name>
      <value>true</value>
    </property>

客户端使用schema

我们在java 客户端通过phoenix 的jar包进行访问phoenix时,如果使用的是通过phoenix自带的jar包的话,会不断的报错。pom.xml配置如下:

      <dependency>
            <groupId>org.apache.phoenix</groupId>
            <artifactId>phoenix-core</artifactId>
            <version>4.7.0-HBase-1.1</version>
        </dependency>

因此,必须和服务端(hbase下的jar包)版本一致,正确做法是拷贝服务端jar包,配置如下:

      <dependency>
            <groupId>org.apache.phoenix</groupId>
            <artifactId>phoenix-core</artifactId>
            <version>4.7.0.2.5.0.0-1245</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/phoenix-server.jar</systemPath>
        </dependency>

创建view对应到已经存在的hbase表报错

目前发现如果开启namespace和schema的对应关系后,创建view对应到已经存在的hbase表报错:

Error: ERROR 505 (42000): Table is read only. (state=42000,code=505)
org.apache.phoenix.schema.ReadOnlyTableException: ERROR 505 (42000): Table is read only.
    at org.apache.phoenix.query.ConnectionQueryServicesImpl.ensureTableCreated(ConnectionQueryServicesImpl.java:1032)
    at org.apache.phoenix.query.ConnectionQueryServicesImpl.createTable(ConnectionQueryServicesImpl.java:1415)
    at org.apache.phoenix.schema.MetaDataClient.createTableInternal(MetaDataClient.java:2180)
    at org.apache.phoenix.schema.MetaDataClient.createTable(MetaDataClient.java:865)
    at org.apache.phoenix.compile.CreateTableCompiler$2.execute(CreateTableCompiler.java:194)
    at org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:343)
    at org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:331)
    at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53)
    at org.apache.phoenix.jdbc.PhoenixStatement.executeMutation(PhoenixStatement.java:329)
    at org.apache.phoenix.jdbc.PhoenixStatement.execute(PhoenixStatement.java:1440)
    at sqlline.Commands.execute(Commands.java:822)
    at sqlline.Commands.sql(Commands.java:732)
    at sqlline.SqlLine.dispatch(SqlLine.java:808)
    at sqlline.SqlLine.begin(SqlLine.java:681)
    at sqlline.SqlLine.start(SqlLine.java:398)
    at sqlline.SqlLine.main(SqlLine.java:292)

起初,我以为是哪里配置有问题,经过调试确实在创建view后又进行了一次create view操作,导致了namespace.table转换不成hbase中需要的namespace:table格式。所以报以上错误,应该是phoenix的一个bug。
各种搜索后,找到以下网页,可以佐证我的想法:
最有含金量的参考
https://community.hortonworks.com/questions/65172/views-on-existing-hbase-namespace-tables.html?childToView=65180#answer-65180
https://community.hortonworks.com/questions/97154/map-phoenix-view-to-existing-hbase-namespace-table.html
https://stackoverflow.com/questions/39974877/create-view-in-apache-phoenix-error-505

对于开启权限管理的hbase,设置访问phoenix的用户权限

需要在hbase中做如下处理

grant 'user','C' 创建权限
grant 'user','XCRW','@SYSTEM'
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • HBase那些事 @(大数据工程学院)[HBase, Hadoop, 优化, HadoopChen, hbase]...
    分痴阅读 9,417评论 3 17
  • Phoenix安装配置 1.简介 Phoenix最早是saleforce的一个开源项目,后来成为Apache基金的...
    Jeffbond阅读 11,034评论 0 5
  • 前言 我们通过业务系统将爬虫的数据写入了HBase,这篇文章说说HBase的表结构,及在HBase上利用Phoen...
    IIGEOywq阅读 11,542评论 0 5
  • 文/沐叁 每日写作第46天。 最近写东西有点随意,除了认真思索的几篇文章,似乎和当初的计划偏离的渐远。 所以,我想...
    沐叁阅读 2,187评论 2 0
  • 上世纪九十年代,我在福建电子厂结识了几位十八九岁聪明丽质的南方女孩,她们是宁化的黄莉华、建宁的叶丽萱、将乐的马晓红...
    湖西忆语阅读 1,625评论 0 0