如何在hbase中表示外键映射 [英] How to denote the foreign key mapping in hbase

查看:540
本文介绍了如何在hbase中表示外键映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人请帮我理解Hbase是如何在内部工作的。



列的值是否可以指向另一个表的键?



例如:

假设我有一个学生表,其subjectId作为外键,而Subject表的id为一个主键,那么表示如何呢?
我们如何映射Student和Subject在一起?

解决方案

有人请帮我理解HBase内部工作。



这是一个非常大的东西,在这里无法完全解释。请参阅链接了解更多详情。



列的值是否可以指向另一个表的键?



列可以存储另一个表的键排在同一个或另一个表中。您必须从第一个表中读取此值,然后转到第二个表以获取行(如果两行都在不同的表中)。



例如:
假设我有一个学生表,其中subjectId作为外键,而Subject表的ID为主键,那么表示如何呢?我们如何将学生和主题映射在一起?


看起来您误解了HBase。它不像传统的RDBMS那样工作。在使用HBase时,没有主键,复合键或外键的概念。尽管你可以将rowkey作为主键。行按照这些行键按字典顺序排序。



回到你的问题。你可以在你的桌子上有两列家庭,一个是学生,另一个是主题。以这种方式,您可以访问任何内容而无需从一个表格移动到另一个表格。



HTH






回应你的意见:

你可以有一个只有1个列族的表格,它将包含所有的列。像这样:





或者,如果您希望将这两种数据分开,您可以有1个表格,包含2个列族,1个用于学生相关数据,1个用于主题相关数据,像这样:





使用 studentID 作为rowkey,因为它对每个学生都是唯一的。现在,如果你想抓取:



1。获取所有申请主题数据科学的学生:
使用columnvalue过滤器实现此功能。



1。列出特定学生的所有科目:这很简单。



继续为学生申请的每个科目添加列。


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?

解决方案

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.

这篇关于如何在hbase中表示外键映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆