Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to get values from hbase table for a row-key which is generated from phoenix primary key for the table

How to get values from hbase table for a row-key which is generated from phoenix primary key for the table

New Contributor

I created a table through phoenix as:

CREATE TABLE MyTab (

Feature varchar(10),

ts DATE NOT NULL,

val INTEGER,

avg varchar(10)

CONSTRAINT pk PRIMARY KEY (tag, ts)

)COLUMN_ENCODED_BYTES=0;

Inserted 100 row to it.

The Hbase scan for MyTab shows this( Just copied only 1 row-key data):

Temp\x00\x80\x00\x01]\x9Fh@\xE2 column=0:VAL, timestamp=1501598196006, value=\x80\x00\x00\x16 Temp\x00\x80\x00\x01]\x9Fh@\xE2 column=0:_0, timestamp=1501598196006, value=x


this means Temp\x00\x80\x00\x01]\x9Fh@\xE2 is the row- key,

So, when I do a get like : get 'MyTab', 'Temp\x00\x80\x00\x01]\x9Fh@\xE2', '0:VAL'

I get no results. How would I get the value of column VAL

TS value inserted to Phoenix is 2017-08-01 20:06:35.998 and Feature is Temp.


3 REPLIES 3
Highlighted

Re: How to get values from hbase table for a row-key which is generated from phoenix primary key for the table

You can't execute "get" on a non-string row key from a shell. You need to do it through HBase Java API.

Get get = new Get(toBytes("row1"));

In Phoenix case, it would be difficult you to form an exact row key from the primary key values as it involves the usage of low level APIs( PTable.newKey(),PDataType.toBytes(value, column.getSortOrder) etc).

However , if you are really looking for look ups, you can still do it from sql.

SELECT * FROM MyTab WHERE feature='Temp' and TS=to_time('<ts_value>')

Re: How to get values from hbase table for a row-key which is generated from phoenix primary key for the table

New Contributor

Thanks, but actually, I want to do scanning in hbase coprocessor for which I require the row-key.

The scan should be for a specific feature and time stamp to do some aggregations. So I need to use scan.setStartRow() and scan.setStoprow() with appropriate row-keys formed by feature and TS.

Re: How to get values from hbase table for a row-key which is generated from phoenix primary key for the table

You would still use the HBase Java API within a coprocessor. Ankit was saying that it did not work because you did not specify the binary data correctly in the HBase shell.

Don't have an account?
Coming from Hortonworks? Activate your account here