如何通过HBase REST服务获取Phoenix表格数据 [英] How to obtain Phoenix table data via HBase REST service

查看:308
本文介绍了如何通过HBase REST服务获取Phoenix表格数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Phoenix JDBC Driver在以下代码片段中创建了一个HBase表:

  Class.forName(org。 apache.phoenix.jdbc.PhoenixDriver); 
连接conn = DriverManager.getConnection(jdbc:phoenix:serverurl:/ hbase-unsecure);
System.out.println(got connection);

conn.createStatement()。execute(CREATE TABLE IF NOT EXISTS phoenixtest(id BIGINT not null primary key,test VARCHAR));

int inserted = conn.createStatement()。executeUpdate(UPSERT INTO phoenixtest VALUES(5,'13%'));
conn.commit();

System.out.println(插入或更新+插入+行);

ResultSet rst = conn.createStatement()。executeQuery(select * from phoenixtest); (rst.next()){
System.out.println(rst.getString(1)++ rst.getString(2));


}

创建表并且表循环工作正常。

现在我试图通过HBase REST服务获取表格数据,因为我知道它来自本地HBase编程。
$ b $ http:// server-url:12345 / PHOENIXTEST / schema 可以正常工作,并返回请求表格信息。



但是当我尝试例如 http:// server-url:12345 / PHOENIXTEST / 5 (5是第一个插入行的关键字,见上面的代码),我得到一个未找到回复信息。

如何通过HBase REST服务获取数据?

解决方案

<对于Phoenix如何对其存储在HBase表中的数据进行编码,以及本机REST API如何尝试并找到密钥,您可能遇到了一个问题。

关于BIGINT的数据类型的凤凰文档说:


二进制表示形式为8字节长,符号位翻转
(因此负值在正值之前排序)。

所以你应该看看实际插入到表中的内容。 HBase REST API可能正在寻找使用不同编码的密钥,因此无法找到它。


I created a HBase table using the Phoenix JDBC Driver in the following code snippet:

    Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
    Connection conn =  DriverManager.getConnection("jdbc:phoenix:serverurl:/hbase-unsecure");
    System.out.println("got connection");

    conn.createStatement().execute("CREATE TABLE IF NOT EXISTS phoenixtest (id BIGINT not null primary key, test VARCHAR)");

    int inserted = conn.createStatement().executeUpdate("UPSERT INTO phoenixtest VALUES (5, '13%')");
    conn.commit();

    System.out.println("Inserted or updated " + inserted + " rows");

    ResultSet rst = conn.createStatement().executeQuery("select * from phoenixtest");

    while (rst.next()) {
      System.out.println(rst.getString(1) + " " + rst.getString(2));
    }

The table is created and the table-looping works fine.

Now I tried to obtain the table data also via HBase REST services as I know it from "native" HBase programming.

The url http://server-url:12345/PHOENIXTEST/schema works fine and gives back the requested table info.

But when I try e.g. http://server-url:12345/PHOENIXTEST/5 (5 was the key of the first inserted row, see code above), I get a Not found message back.

How can I obtain the data via the HBase REST service?

解决方案

You probably have an issue with how Phoenix encodes data it stores in an HBase table, vs how the native REST API will try and find a key.

Looking at the Phoenix documentation on data types for BIGINT it says:

The binary representation is an 8 byte long with the sign bit flipped (so that negative values sorts before positive values).

So you should probably take a look at what has actually been inserted into your table. The HBase REST API is probably looking for a key using a different encoding and thus can't find it.

这篇关于如何通过HBase REST服务获取Phoenix表格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆