Search code examples
resthadoopjdbchbaseapache-phoenix

How to obtain Phoenix table data via HBase REST service


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?


Solution

  • 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.