You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@phoenix.apache.org by Sanooj Padmakumar <p....@gmail.com> on 2016/02/22 17:43:42 UTC

Phoenix rowkey

Hi,

I have a HBase table created using Phoenix and the primary key is a
combination of 7 columns out of which one is of type UNSIGNED_LONG and the
rest are varchar.

I want to perform select and upsert operation on this table using direct
HBase api's. How do I construct the rowkey in this case ? I read that the
separator used is *(byte) 0 *for varchar columns. But in my table there is
an UNSIGNED_LONG and hence the question.

Any suggestions will be of great help. Thanks

PS : I cannot use direct phoenix here because Phoenix on Spark within a
kerberised cluster is not working

-- 
Thanks,
Sanooj Padmakumar

Re: Phoenix rowkey

Posted by Sanooj Padmakumar <p....@gmail.com>.
Thanks Sergey. I tried as per the suggestion and by having a look at the
Phoenix code base. But still dont get the expected result. I have pasted
the java code, *valueStr * is always coming as null for me. Also tried
appending 0x00 that didnt give me result as well.

*Primary Column Values : *






*sr_srAttach602962481_2016-0218-T-0094srAttach-->null92233705807343520172016-0218-T-00940004714997*


*Java code querying HBase*
























*import org.apache.hadoop.hbase.util.Bytes;import
org.apache.phoenix.query.QueryConstants;import
org.apache.phoenix.schema.types.PLong;import
org.apache.phoenix.schema.types.PVarchar;import
org.apache.phoenix.util.ByteUtil;byte[] startRow = ByteUtil.concat(
PVarchar.INSTANCE.toBytes("sr_srAttach"),
QueryConstants.SEPARATOR_BYTE_ARRAY,
PVarchar.INSTANCE.toBytes("602962481_2016-0218-T-0094"),
QueryConstants.SEPARATOR_BYTE_ARRAY,
PVarchar.INSTANCE.toBytes("srAttach"),
QueryConstants.SEPARATOR_BYTE_ARRAY,
PVarchar.INSTANCE.toBytes("-->"),
QueryConstants.SEPARATOR_BYTE_ARRAY,    // i have a null value primary key
column here and hence two separators are added
QueryConstants.SEPARATOR_BYTE_ARRAY,
PLong.INSTANCE.toBytes(9223370580734352017L), // long value
PVarchar.INSTANCE.toBytes("2016-0218-T-00940004714997"));Get g = new
Get(startRow);Result r = table.get(g);byte[] value =
r.getValue(Bytes.toBytes("p"),Bytes.toBytes("attyp"));String valueStr =
Bytes.toString(value);*


On Tue, Feb 23, 2016 at 12:55 AM, Sergey Soldatov <se...@gmail.com>
wrote:

> You do it exactly the way you described. Separate varchars by zero and
> use fixed 8 bytes for the long.  So, for example if you have (varchar,
> u_long, varchar) primary key, the rowkey for values like 'X',1,'Y'
> will be :
> ('X', 0x00) (0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01), ('Y')
>
>
> Thanks,
> Sergey
>
> On Mon, Feb 22, 2016 at 8:43 AM, Sanooj Padmakumar <p....@gmail.com>
> wrote:
> > Hi,
> >
> > I have a HBase table created using Phoenix and the primary key is a
> > combination of 7 columns out of which one is of type UNSIGNED_LONG and
> the
> > rest are varchar.
> >
> > I want to perform select and upsert operation on this table using direct
> > HBase api's. How do I construct the rowkey in this case ? I read that the
> > separator used is (byte) 0 for varchar columns. But in my table there is
> an
> > UNSIGNED_LONG and hence the question.
> >
> > Any suggestions will be of great help. Thanks
> >
> > PS : I cannot use direct phoenix here because Phoenix on Spark within a
> > kerberised cluster is not working
> >
> > --
> > Thanks,
> > Sanooj Padmakumar
>



-- 
Thanks,
Sanooj Padmakumar

Re: Phoenix rowkey

Posted by Sergey Soldatov <se...@gmail.com>.
You do it exactly the way you described. Separate varchars by zero and
use fixed 8 bytes for the long.  So, for example if you have (varchar,
u_long, varchar) primary key, the rowkey for values like 'X',1,'Y'
will be :
('X', 0x00) (0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01), ('Y')


Thanks,
Sergey

On Mon, Feb 22, 2016 at 8:43 AM, Sanooj Padmakumar <p....@gmail.com> wrote:
> Hi,
>
> I have a HBase table created using Phoenix and the primary key is a
> combination of 7 columns out of which one is of type UNSIGNED_LONG and the
> rest are varchar.
>
> I want to perform select and upsert operation on this table using direct
> HBase api's. How do I construct the rowkey in this case ? I read that the
> separator used is (byte) 0 for varchar columns. But in my table there is an
> UNSIGNED_LONG and hence the question.
>
> Any suggestions will be of great help. Thanks
>
> PS : I cannot use direct phoenix here because Phoenix on Spark within a
> kerberised cluster is not working
>
> --
> Thanks,
> Sanooj Padmakumar