如何通过HBase REST服务获取Phoenix table数据
How to obtain Phoenix table data via HBase REST service
我在以下代码片段中使用 Phoenix JDBC 驱动程序创建了一个 HBase table:
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));
}
table 已创建,table 循环工作正常。
现在我也尝试通过 HBase REST 服务获取 table 数据,正如我从 "native" HBase 编程中了解到的那样。
url http://server-url:12345/PHOENIXTEST/schema
工作正常并返回请求的 table 信息。
但是当我尝试例如http://server-url:12345/PHOENIXTEST/5
(5 是第一个插入行的键,见上面的代码),我收到一条 Not found
消息。
如何通过HBase REST服务获取数据?
您可能对 Phoenix 如何对其存储在 HBase table 中的数据进行编码以及本机 REST API 将如何尝试查找密钥存在疑问。
查看关于 data types BIGINT 的 Phoenix 文档,它说:
The binary representation is an 8 byte long with the sign bit flipped
(so that negative values sorts before positive values).
所以您可能应该看一下实际插入到 table 中的内容。 HBase REST API 可能正在寻找使用不同编码的密钥,因此找不到它。
您真的应该使用 phoenix 而不是 HBase 从 phoenix table 获取数据。 Phoenix 使用的是自定义编码,因为它是 Integer and BigInt also salting(如果你使用一个)。
Phoenix 也主要使用 byte 来存储数据,使用 StringBinary 来编码。因此,您的密钥很可能不是 5 而是 \x80\x00\x00\x05(Integer)
我在以下代码片段中使用 Phoenix JDBC 驱动程序创建了一个 HBase table:
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));
}
table 已创建,table 循环工作正常。
现在我也尝试通过 HBase REST 服务获取 table 数据,正如我从 "native" HBase 编程中了解到的那样。
url http://server-url:12345/PHOENIXTEST/schema
工作正常并返回请求的 table 信息。
但是当我尝试例如http://server-url:12345/PHOENIXTEST/5
(5 是第一个插入行的键,见上面的代码),我收到一条 Not found
消息。
如何通过HBase REST服务获取数据?
您可能对 Phoenix 如何对其存储在 HBase table 中的数据进行编码以及本机 REST API 将如何尝试查找密钥存在疑问。
查看关于 data types BIGINT 的 Phoenix 文档,它说:
The binary representation is an 8 byte long with the sign bit flipped (so that negative values sorts before positive values).
所以您可能应该看一下实际插入到 table 中的内容。 HBase REST API 可能正在寻找使用不同编码的密钥,因此找不到它。
您真的应该使用 phoenix 而不是 HBase 从 phoenix table 获取数据。 Phoenix 使用的是自定义编码,因为它是 Integer and BigInt also salting(如果你使用一个)。
Phoenix 也主要使用 byte 来存储数据,使用 StringBinary 来编码。因此,您的密钥很可能不是 5 而是 \x80\x00\x00\x05(Integer)