Cassandra中的数据建模

时间:2013-05-06 14:49:54

标签: cassandra data-modeling

我正在尝试Cassandra,并研究如何在其中建模数据。我已经描述了我们的数据存储要求以及我对如何在Cassandra中建模的想法。请告诉我这是否有意义并建议更改。

在网上进行了相当多的搜索,但没有清楚地了解如何对多值列要求进行建模并对其进行索引,这是一个非常常见的要求。

非常感谢任何帮助。

我们每条记录的当前数据:

{
  ‘id’ : <some uuid>,
  ‘title’ : text,
  ‘description’ text,
  ‘images’ : [{id : id1, ‘caption’: cap1}, {id : id2, ‘caption’: cap2}, ... ],
  ‘videos’ : [‘video id1’, video id2’, …],
  ‘keywords’ [‘keyword1’, ‘keyword2’,...]
  updated_at: <timestamp>
}

查询我们需要

  • 按ID
  • 查找
  • 通过images.id查找。
  • 按关键字查找
  • 所有记录,其中up​​dated_at&gt;

我们当前的模式

  1. 专栏系列:文章 id:uuid title:varchar 描述:varchar 图片: 视频: 关键字: 的updated_at: updated_date:[例如:'2013-05-06:02']

  2. 列族:图像文章索引

    {
      ‘id’ : <image id>, 
      ‘article1 uuid’ : null, 
      ‘article2 uuid’ : null,
      ...
    }
    
  3. 列族:关键字 - 文章索引

    {
      ‘id’ : <keyword>, 
      ‘article1 uuid’ : null, 
      ‘article2 uuid’ : null,
      ...
    }
    
  4. 示例查询:

    1. 通过id =&gt;查找直截了当

    2. 通过images.id =&gt;

      查找
      ids = select * from ‘Image-Article Index’ where id=<image id>
      select * from Article where id in (ids)
      
    3. 通过keyword =&gt;

      查找
      ids = select * from ‘Keyword-Article Index’ where id=<image id>
      select * from Article where id in (ids)
      
    4. 所有updated_at > <some timestamp>

      的记录

      Cassandra不支持范围查询,除非其中一个索引列上存在一个相等条件。

      从给定时间戳中提取日期和小时;

      for each date:hour in start to current time
          ids = select * from Article where update_date=date:hour and timestamp > <some timestamp>
          select * from Article where id in (ids)
      

0 个答案:

没有答案
相关问题