问题
Someone please help me understand how the Hbase works internally.
Can the value of a column refer to a key of another table?
For example:
Suppose i have a Student table with subjectId as a foreign key and the Subject table has the id as a primay key, then how would the representation be? How can we map the Student and Subject together?
回答1:
Someone please help me understand how the HBase works internally.
This is something really big which can't be explained here completely. Please refer this link for more detail.
Can the value of a column refer to a key of another table?
A column can definitely store the key of another row in the same or another table. You have to read this value from the first table and then go to the second table in order to fetch the row(if both the rows are in different tables).
For example: Suppose i have a Student table with subjectId as a foreign key and the Subject table has the id as a primary key, then how would the representation be? How can we map the Student and Subject together?
Looks like you have misunderstood HBase. It doesn't work like traditional RDBMSs. There is no notion of Primary key, Composite key or Foreign key when you work with HBase. You can treat the rowkey as the primary key though. Rows are lexicographically sorted based on these rowkeys.
Coming back to your question. You could have 2 column families in your table, 1 for student and another for subject. In this manner you could access anything without having to move from one table to another.
HTH
In response to your comments :
You can either have a table with just 1 column family which will contain all the columns together. Something like this :
Or, if you want a separation between these 2 kinds of data, you can have 1 table with 2 column families, 1 for student related data and 1 for subject related data, like this :
Use studentID as the rowkey since it'll be unique for each student. Now if you want to fetch :
1. Get all the students who have applied for the subject data science : Use columnvalue filter to achieve this.
1. List all the subjects for a particular student : This is simple. Just a get on that particular row.
Keep on adding columns for each subject as a student applies for.
来源:https://stackoverflow.com/questions/18057285/how-to-denote-the-foreign-key-mapping-in-hbase