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.

Apache Phoenix Primary Key and Query

Apache Phoenix Primary Key and Query

New Contributor

I have existing HBase tables for which I build Phoenix Views.

CREATE VIEW "MDS" (pk VARCHAR PRIMARY KEY, "auth_group"."id" VARCHAR, "auth_group"."name" CHAR(10));

where MDS is my hbase table, auth_group is one of the column families with columns id, name.

I have the below questions:

1. Can I use one of the columns in my column family as a PRIMARY KEY? Or should it something outside of the columns in the column family? How do I build a PRIMARY KEY in such a scenario.

2. When I did the below it gave me the below error. How do I choose the length of CHAR?

select * from MDS;
Error: ERROR 201 (22000): Illegal data. Expected length of at least 12 bytes, but had 10 (state=22000,code=201)

3. If I picked the min of the CHAR to some minimum number, I get the below result where the characters are cut off(based on the number I gave) and the id column is blank . (It doesn't reflect the same values as in hbase.)

PKidname
1resource_u
2adminid_id
3systems_id
4usersystem
5uaccess_id
6numofusers
7idofusersac
1 REPLY 1
Highlighted

Re: Apache Phoenix Primary Key and Query

if you have existing data in your HBase, it's possible that is not serialized in the way Phoenix deserializes it for reading and hence the Illegal data exception, so it is recommended that you try declaring all your fields Varchar for string types or Unsigned_int for integer types.

If you want to use other data types, it is better you insert data and read through Phoenix only.