You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@phoenix.apache.org by Shawn Li <sh...@gmail.com> on 2019/01/14 20:47:01 UTC

How to decode composite rowkey back to original primary keys

Hi,

Phoenix encodes composite key to hbase rowkey. We want to check if there
any documentation or example to show how to manually decode Hbase rowkey
back to original values for those primary keys. Or is there any phoenix
source code we can directly use to do this?

Thanks,
Shawn

Re: How to decode composite rowkey back to original primary keys

Posted by Shawn Li <sh...@gmail.com>.
Thanks, James. Will try it.

Shawn

On Mon, Jan 14, 2019 at 8:52 PM James Taylor <ja...@apache.org> wrote:

> You can do something similar to PhoenixRuntime.decodeColumnValues() to do
> that. It'd be something like this:
>
>     public static Object[] decodeColumnValues(Connection conn, String
> fullTableName, byte[] value) throws SQLException {
>         PTable table = getTable(conn, fullTableName);
>         RowKeySchema schema = table.getRowKeySchema();
>         ImmutableBytesWritable ptr = new ImmutableBytesWritable(value);
>         schema.iterator(ptr);
>         int i = 0;
>         List<Object> values = new ArrayList<Object>();
>         while(schema.next(ptr, i, maxOffset) != null) {
>             values.add(schema.getField(i).getDataType().toObject(ptr));
>             i++;
>         }
>         return values.toArray();
>     }
>
>
>
>
> On Mon, Jan 14, 2019 at 12:47 PM Shawn Li <sh...@gmail.com> wrote:
>
>> Hi,
>>
>> Phoenix encodes composite key to hbase rowkey. We want to check if there
>> any documentation or example to show how to manually decode Hbase rowkey
>> back to original values for those primary keys. Or is there any phoenix
>> source code we can directly use to do this?
>>
>> Thanks,
>> Shawn
>>
>

Re: How to decode composite rowkey back to original primary keys

Posted by James Taylor <ja...@apache.org>.
You can do something similar to PhoenixRuntime.decodeColumnValues() to do
that. It'd be something like this:

    public static Object[] decodeColumnValues(Connection conn, String
fullTableName, byte[] value) throws SQLException {
        PTable table = getTable(conn, fullTableName);
        RowKeySchema schema = table.getRowKeySchema();
        ImmutableBytesWritable ptr = new ImmutableBytesWritable(value);
        schema.iterator(ptr);
        int i = 0;
        List<Object> values = new ArrayList<Object>();
        while(schema.next(ptr, i, maxOffset) != null) {
            values.add(schema.getField(i).getDataType().toObject(ptr));
            i++;
        }
        return values.toArray();
    }




On Mon, Jan 14, 2019 at 12:47 PM Shawn Li <sh...@gmail.com> wrote:

> Hi,
>
> Phoenix encodes composite key to hbase rowkey. We want to check if there
> any documentation or example to show how to manually decode Hbase rowkey
> back to original values for those primary keys. Or is there any phoenix
> source code we can directly use to do this?
>
> Thanks,
> Shawn
>