CQL3每行有它自己的模式 [英] CQL3 Each row to have its own schema

查看:169
本文介绍了CQL3每行有它自己的模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在.NET应用程序中使用卡桑德拉。我的目标是一些数据存储在列的家庭,但数据的每一行都会有不同的模式。

I want to use Cassandra in a .Net application. My objective is to store some data in a column family, but each row of data will have varying schema.

例(一个非常简单的)我想有一个玩具列族来存储下列对象,(注意:他们怎么比的ID属性其他非常不同的属性)

Example (A very simple one) I want to have a 'Toys' column family to store the following objects, (Notice how they have very different properties other than the ID property)

玩具对象1
{ID:1
    名:汽车,
    number_of_doors:4,
    喜欢:3}

Toy object 1 { "id":"1", "name":"Car", "number_of_doors":4, "likes":3}

玩具对象2
{ID:2
    类型:平面,
    flying_range:百米}

Toy object 2 { "id":"2", "type":"Plane", "flying_range":"100m"}

玩具对象3
{ID:3
    类别:列车,
    number_of_carriages:10}

Toy object 3 { "id":"3", "category":"Train", "number_of_carriages":10}

这是我最初的理解和运用Datastax CSHARP司机我要永远改变表(列家人)不正确的坐我的。我想每一行都有自己的模式。节俭API或许能解决这一点,但它似乎HectorSharp几乎是死了。

From my initial understanding and using of Datastax CSharp driver I have to always alter the table (Column family) which does not sit right with me. I would like each row to have its own schema. Thrift API might be able to solve this but it seems HectorSharp is all but dead.

类似于我要求一个问题,但它并没有我想要的答案

A question similar to my requirement but it doesn't have the answer I want

<一个href=\"http://stackoverflow.com/questions/11847064/cassandra-for-a-schemaless-db-10s-of-millions-order-tables-and-millions-of-que\">Cassandra一个无模式分贝,数以百万计10的订购表和每天数百万的查询

我是被期待的每一行都有自己的模式,或者找错了树是有办法做到这一点使用卡桑德拉+ Csharp的?

Am I barking up the wrong tree by expecting each row to have its own schema or is there a way to do this using Cassandra+Csharp ?

在此先感谢您的回答。

推荐答案

卡桑德拉的旧版本是无模式的,这意味着你没有任何地方有一个什么样的行可能包含一个定义。你现在需要的可能是什么部分地图上卡桑德拉2.1完成

Older versions of Cassandra were Schema-less, meaning that you didn't have anywhere a definition of what a row could contain. What you need now could be partially done with a Map on Cassandra 2.1

CREATE TABLE toys (
    id text PRIMARY KEY,
    toy map<text, text>
)

把一些数据...

Put some data ...

INSERT INTO toys (id, toy) VALUES ( '1', {'name':'Car', 'number_of_doors':'4', 'likes':'3'});
INSERT INTO toys (id, toy) VALUES ( '2', {'type':'Plane', 'flying_range':'100m'});
INSERT INTO toys (id, toy) VALUES ( '3', {'category':'Train', 'number_of_carriages':'10'});

表的内容...

Table content ...

 id | toy
----+-------------------------------------------------------
  3 |    {'category': 'Train', 'number_of_carriages': '10'}
  2 |             {'flying_range': '100m', 'type': 'Plane'}
  1 | {'likes': '3', 'name': 'Car', 'number_of_doors': '4'}

我们现在可以创建密钥的指数...

We can now create an index on keys ...

CREATE INDEX toy_idx ON toys (KEYS(toy));

...并在地图上的按键查询...

... and perform queries on Map keys ...

SELECT * FROM toys WHERE toy CONTAINS KEY 'name';

 id | toy
----+-------------------------------------------------------
  1 | {'likes': '3', 'name': 'Car', 'number_of_doors': '4'}

现在,您可以更新或写之前删除映射条目就像你会与正常列做,没有读

Now you can update or delete map entries like you would do with normal columns, without reading before writing

DELETE toy['name'] FROM toys WHERE id='1';
UPDATE toys set toy = toy + {'name': 'anewcar'} WHERE id = '1';
SELECT * FROM toys;

 id | toy
----+-----------------------------------------------------------
  3 |        {'category': 'Train', 'number_of_carriages': '10'}
  2 |                 {'flying_range': '100m', 'type': 'Plane'}
  1 | {'likes': '3', 'name': 'anewcar', 'number_of_doors': '4'}

一些限制


  1. 您不能检索集合的一部分:即使内部每个地图的条目存储为一列,你只能检索整个集合

  2. 您必须选择是否对键或值上创建索引,两者同时进行
    不支持。

  3. ,因为地图是输入你不能把混合值 - 在我的例子所有整数现在都是字符串

我个人认为这种方法的广泛使用反模式。

I personally consider an extensive usage of this approach an anti-pattern.

HTH,
卡罗

HTH, Carlo

这篇关于CQL3每行有它自己的模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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