动态列时的Cassandra数据建模 [英] Cassandra data modeling when columns are dynamic

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

问题描述

我在cassandra的数据建模方面苦苦挣扎,因为我对不同的组织有不同的属性.由于将有任意数量的属性,因此我无法在架构中为动态数量的列建模.其次,当我为此使用map时,我无法查询这些属性或为它们建立索引等.我是否缺少某些东西,或者这是cassandra中的限制?

I am struggling with data modeling in cassandra where i have different attributes for different organizations. As there would be any number of attributes i am unable to model a dynamic number of columns in schema. Secondly, when i use map for this, i am unable to query against those attributes or index them etc. Am i missing something or this is a limitation in cassandra?

一个组织选择特定的属性来收集数据,他们可以随时更改这些属性.当它们更改时,属性数量和属性名称也会更改.如果以前我们正在收集 att1,attr2,attr3 的数据,现在我们正在收集 attr4,attr5,attr6,attr7,attr8,attr9 .而且,任何组织都可以随时更改此设置.此外,组织将在这些属性上进行大量搜索.

one organization selects specific attributes to collect data for and they can change those attributes anytime. When they change, number of attributes and name of attributes changes. If previously we were collecting data for att1,attr2,attr3, now we are collecting attr4,attr5,attr6,attr7,attr8,attr9. And this can be changed at anytime for any organization. Furthermore, organization will be searching massively on those attributes.

  1. 我们如何在cassandra中模拟这种情况.
  2. 如果有限制,我们已经读/写的cassandra可能是什么?(主要是,经常.不是更新/删除)熟练程度.
  3. 我们是否必须将任何其他框架与cassandra结合使用?像lucene等
  1. How can we model such scenario in cassandra.
  2. if it's a limitation, what could be the alternatives of cassandra where we have read/write (mostly write and often read. Not update/delete) proficiency.
  3. Do we have to combine any other framework with cassandra? like lucene etc

谢谢.

推荐答案

这种情况确实需要有关已执行查询的更多信息,等等.

This case really requires more information about queries that are executed, etc.

在最简单的情况下,只需将属性名称作为现有列的一个聚类列,就像这样:

in simplest case, just put the attribute name as a clustering column in addition to existing, like this:

create table tbl (
  id int,
  collected timestamp,
  attr_name text,
  attr_value int,
  primary key(id, collected, attr_name);

在这种情况下,您可以选择任何一个单独的属性

in this case you can select either individual attribute if you do

select * from tbl where id = ... and collected = ... and attr_name = 'attrX';

或者您可以通过省略 attr_name 来选择所有属性:

or you can select all attributes by just omitting the attr_name:

select * from tbl where id = ... and collected = ...;

,但是仅当所有属性值具有相同的数据类型时,它才起作用.如果它们可能不同,则可能需要为每种数据类型添加更多字段.

but it will work only when all attribute values have the same data type. If they could be different, then you may need to add more fields for every data type.

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

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