【发布时间】:2012-04-10 20:01:27
【问题描述】:
我一直在试用 Cassandra,需要一些帮助来理解一些问题。我是 cassandra 的新手,我不确定将 MySQL 数据库转换为 Cassandra 会导致我陷入陷阱,这是由于缺乏经验或对 cassandra 的了解有限。所以我希望我能从有经验的 cassandra 用户/开发者那里得到有用的信息。
以下是我创建的示例键空间。如果有经验的人可以指出,我想知道设计中的任何缺陷。
create keyspace Students with placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' and strategy_options = {replication_factor:1};
use Students;
create column family StudentID with column_type = 'Super' and comparator = 'UTF8Type' and subcomparator = 'UTF8Type' and default_validation_class = 'UTF8Type' and column_metadata =
[{column_name : 'First Name', validation_class : UTF8Type},
{column_name : 'Last Name', validation_class : UTF8Type},
{column_name : 'Subjects', validation_class : UTF8Type},
{column_name : 'Class', validation_class : UTF8Type}];
set StudentID[utf8('1968')]['00001']['First Name'] = 'Mark';
set StudentID[utf8('1968')]['00001']['Last Name'] = 'Myers';
set StudentID[utf8('1968')]['00001']['Subjects'] = 'Maths, Chemistry';
set StudentID[utf8('1968')]['00001']['Class'] = '10th grade';
create keyspace Teachers with placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' and strategy_options = {replication_factor:1};
use Teachers;
create column family TeacherID with column_type = 'Super' and comparator = 'UTF8Type' and subcomparator = 'UTF8Type' and default_validation_class = 'UTF8Type' and column_metadata =
[{column_name : 'First Name', validation_class : UTF8Type},
{column_name : 'Last Name', validation_class : UTF8Type},
{column_name : 'Subjects', validation_class : UTF8Type},
{column_name : 'Class', validation_class : UTF8Type}];
set TeacherID[utf8('777')]['234-333']['First Name'] = 'Mark';
set TeacherID[utf8('777')]['234-333']['Last Name'] = 'Myers';
set TeacherID[utf8('777')]['234-333']['Subjects'] = 'Maths, Chemistry,physics';
set TeacherID[utf8('777')]['234-333']['Class'] = '10th grade, 11th grade, 9th grade';
create keyspace Subjects with placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' and strategy_options = {replication_factor:1};
use Subjects;
create column family SubjectNames with default_validation_class = 'UTF8Type' and comparator = 'UTF8Type' and column_metadata =
[{column_name : 'Names1', validation_class : UTF8Type}];
set SubjectNames[utf8('Current')]['Name1']= 'maths';
set SubjectNames[utf8('Current')]['Name2']= 'physics';
set SubjectNames[utf8('Current')]['Name3']= 'chemistry';
set SubjectNames[utf8('Current')]['Name4']= 'CS';
三个键空间 - 学生、教师和科目。 我肯定需要这些键空间之间的某种关系,并且还需要查询数据。 例如
- 我会查询具有特定学科和/或班级的学生
- 某班的老师
- 列出某个班级的某个学生所修读的所有科目。
据我所知,我肯定需要创建二级索引才能使查询正常工作。也就是说,检索某些子句的数据。
我知道我是否正确
- 我们在 cassandra 中没有“like”子句
- 对于一列的每个值(最后一个键值对),该值必须被分解。那是个别的话。比如说,我想获得一个主题列表,因此每个主题都必须位于与其关联的不同列中。我无法查询类似于“subjectA,subjectB”的列值,而是将其分解为 SubjectA 和 SubjectB 并将它们放在不同的列中。
以下是键空间。
【问题讨论】: