Database Reference
In-Depth Information
Then, we realize that this is not all that bad. In our case, the username is unique and
fulfills the role of the primary key perfectly. You might ask how can one generate a
username that is unique? It can also happen that two users are creating their profiles
simultaneously and are trying to create the same username. In this case, while
checking whether the username exists, both users will first get an answer in the
negative and consequently proceed to create the same username at the same time!
The answer to this question is given by the checkAndPut function in the Table
interface. This call allows you to put a new row in while checking for the existence
of certain columns. The operation is atomic, and one of the users will get the name
already exists error.
Thus, the need for generating a unique key in this case is solved. In later chapters,
we will discuss more techniques that will tell you how to generate primary keys
by yourself without relying on the database to do this for you. You will learn to
appreciate this new habit.
For the lists of values, use the SQL ARRAY construct.
But wait! Users usually have one username, but they might very well have multiple
e-mail addresses. So, what we want is list of e-mails. Execute the following query to
get a list of e-mails:
CREATE TABLE my_schema.users (
...
email list varchar,
...
);
While there is no list in HBase, Phoenix introduces a SQL array. Here is your table
definition:
CREATE TABLE my_schema.users (
username varchar primary key,
firstname varchar,
lastname varchar,
email varchar[],
password varchar,
created_date timestamp
);
 
Search WWH ::




Custom Search