Apache Cassandra模式设计 [英] Apache Cassandra schema design

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

问题描述

我有以下设置:

有CF项目和CF关键字。

每个项目都有零个,一个或多个关键字,存储在列中。

每个关键字都有一个或多个项目,存储在列中。

它看起来像这样:

 

项目{
dl {name => DELL6400,关键字:1 =>电脑,关键字:2 => DELL,关键字:3 => topseller}
hp {name => HP12345,关键字:1 =电脑,关键字:2 => HP}
no {name => Nokia8210,关键字:1 =>手机,关键字:2 => NOKIA}
}

//这里我只存储项目的键,
//在现实中我已经反规范化了大多数项目列

关键字{
computer {webpage => www.domain.com / computer,item:dl => dl,item:hp => hp}
DELL {webpage => www.domain.com/dell,item:dl => dl}
topseller {webpage = www.domain.com/top,item:dl => dl}
HP {webpage => www.domain.com/hp,item:hp => hp}
NOKIA {webpage = domain.com/nokia,item:no => no}
phone {webpage => www.domain.com/phone,item:no => no}
}



当我添加新项目时,如果有必要,我在关键字中添加网页列。

当我删除项目时,我也删除列item:xx



问题是如何避免空关键字,如果我删除nokia项否:

 

关键字{
...
NOKIA {webpage => www.domain.com/nokia}
phone {webpage => www.domain.com/phone}
}

我可以

解决方案

这很有趣,但我想知道其他方式 - 将网页事物反规范化,例如:



[code]

 code>关键字{
computer {webpage:dl => www.domain.com/computer,item:dl => dl,
网页:dl => www.domain.com/computer,item:hp => hp}
DELL {webpage:dl => www.domain.com/dell,item:dl => dl}
topseller {webpage:dl => www.domain.com/top,item:dl => dl}
HP {webpage:hp => www.domain.com/hp,item:hp => hp}
NOKIA {webpage:no => www.domain.com/nokia,item:no => no}
phone {webpage:no => www.domain.com/phone,item:no => no}
}

[/ code]



在这种情况下,当我删除项:xx,我删除网页:xx以及行是自动删除(鬼)如果没有字段。但是我仍然不确定这是一个如此明智的想法。


I have following setup:
Have CF items and CF keywords.
Each item have zero, one or more keywords, stored in columns.
Each keyword have one or more items, stored in columns.
It looks like this:


    items {
        dl { name => DELL6400,  keyword:1 => computer, keyword:2 => DELL, keyword:3 => topseller  }
        hp { name => HP12345,   keyword:1 => computer, keyword:2 => HP    }
        no { name => Nokia8210, keyword:1 => phone,    keyword:2 => NOKIA }
    }

    // here I store keys of the items only,
    // in reality I have denormalized most of items columns
    keywords{
        computer  { webpage => www.domain.com/computer , item:dl => dl , item:hp => hp }
        DELL      { webpage => www.domain.com/dell ,     item:dl => dl }
        topseller { webpage => www.domain.com/top ,      item:dl => dl }
        HP        { webpage => www.domain.com/hp ,       item:hp => hp }
        NOKIA     { webpage => www.domain.com/nokia ,    item:no => no }
        phone     { webpage => www.domain.com/phone ,    item:no => no }
    }

when I add new item, I am adding "webpage" column in keywords if neccessary.
when I am removing an item, I am removing column "item:xx" as well

question is how to avoid "empty" keywords such if I remove nokia item "no":


    keywords{
        ...
        NOKIA     { webpage => www.domain.com/nokia }
        phone     { webpage => www.domain.com/phone }
    }

I can count slice item:*, but because of eventual consistency this will be probably wrong aproach.

解决方案

this is interesting, but I though about other way - to denormalize the "webpage" thing, e.g.:

[code]

keywords{
    computer  { webpage:dl => www.domain.com/computer , item:dl => dl ,
            webpage:dl => www.domain.com/computer ,  item:hp => hp }
    DELL      { webpage:dl => www.domain.com/dell ,     item:dl => dl }
    topseller { webpage:dl => www.domain.com/top ,      item:dl => dl }
    HP        { webpage:hp => www.domain.com/hp ,       item:hp => hp }
    NOKIA     { webpage:no => www.domain.com/nokia ,    item:no => no }
    phone     { webpage:no => www.domain.com/phone ,    item:no => no }
}

[/code]

in such case when i delete item:xx, i delete webpage:xx as well, and row is auto-removed (ghost) if there is no fields there. However I am still not sure if this is such a bright idea.

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

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