了解Cassandra数据模型 [英] Understanding Cassandra Data Model

查看:81
本文介绍了了解Cassandra数据模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始通过

作者还提供了以下列系列示例:

The author also gives the below column family example:

Book {

 key: 9352130677{ name: "Hadoop The Definitive Guide", author:" Tom White", publisher:"Oreilly", priceInr;650, category: "hadoop", edition:4},

 key: 8177228137{ name"" Hadoop in Action", author: "Chuck Lam", publisher:"manning", priceInr;590, category: "hadoop"},

 key: 8177228137{ name:" Cassandra: The Definitive Guide", author: "Eben Hewitt", publisher:" Oreilly", priceInr:600, category: "cassandra"},

 }

但是在该教程和我经历的所有其他教程中,最后还是在cassandra中创建了常规表。我无法将Cassandar模型与正在创建的模型联系起来。

But in that tutorial and every other tutorial I have gone through, then end up creating regular tables in cassandra. I am unable to connect the Cassandar model with what I am creating.

例如,我创建了一个名为Employee的列族,如下所示:

For example, I created a column family called Employee as below:

create columnfamily Employee(empid int primary key,empName text,age int);

现在我插入了一些数据,列族如下:

Now I inserted some data and my column family looks as this:

对我来说,这看起来像一个常规的关系表,而不像作者解释的数据模型。如何创建雇员列族,其中每一行代表具有不同属性的雇员?像这样的东西:

For me this looks like a regular relational table and not like the data model the author has explained. How do I create a Employee column family where each row represents an employee with different attributes? Something like:

Employee{
101:{name:Emp1,age:20}
102:{name:Emp2,salary:1000}
102:{manager_name:Emp3,age:45}
}

}

推荐答案


  1. 您需要了解使用cql的表示可能看起来像常规关系表,但是Cassandra中的行的内部结构完全不同。它为每个员工保存了不同的属性集,使用cql查询时看到的空值仅表示空单元格/不存在的单元格。

  1. You need to understand that in the representation using cql, is may look like regular relational table, but the internal structure of the rows in Cassandra is completely different. It is saving different set of attributes for each employee, and the nulls you can see while querying with cql is just a representation of empty/nonexistent cells.

您尝试实现的是非结构化数据模型。 Cassandra从此模型开始,并且按照您已阅读的教程中的描述进行了所有工作,但是有一种观点认为,非结构化数据设计不利于开发,并且会带来更多无法解决的问题。因此,过了一段时间,Cassandra移到了结构化数据结构(从节俭到cql)。这并不意味着您必须存储所有键/行的所有属性,这并不意味着所有行都具有相同数量的属性,仅意味着您必须在使用它们之前声明属性。

What you trying to achieve, is unstructured data model. Cassandra started with this model, and all was working as described in the tutorial you've read, but there is an opinion that unstructured data design is unhealthy to development and makes more problems than it solves. So, after sometime, Cassandra moved to the "structured" data structure (and from thrift to cql). It doesn't mean that you have to store all attributes for all keys/rows, it doesn't mean that all the rows are have same number of attributes, it just means that you have to declare attributes before you use them.

您可以使用Map,List,Set等数据类型,UDT(用户定义类型)来实现某种非结构化数据建模,也可以将数据另存为json字符串并在应用程序端进行解析。

You can achieve some kind of unstructured data modeling using Map, List, Set, etc. data types, UDT (User defined types) or just saving your data as json string and parsing it on the application side.

这篇关于了解Cassandra数据模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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