从理性风格建模转向NoSql / Cassandra风格

时间:2015-07-18 06:15:05

标签: database-design cassandra nosql

我正在尝试将我的理性建模更改为Cassandra建模,我需要建模以下结构: 我有商店,促销和价格。 价格表包括特定商店中的所有商品及其价格。 促销清单包括促销细节(例如折扣)以及促销中包含的项目和相关的消费者俱乐部(例如vip等) stores id包含chain id,sub chain id,store id 这就是列表的样子 物品(每家商店):

<root>
  <ChainId>7290027600007</ChainId>
  <SubChainId>001</SubChainId>
  <StoreId>001</StoreId>
  <Items Count="2">
    <Item>
      <ItemCode>11210000094</ItemCode>
      <ItemPrice>12.80</ItemPrice>     
    </Item>
    <Item>
      <ItemCode>11210000216</ItemCode>
      <ItemPrice>29.40</ItemPrice>
    </Item>
    </Items>
</root>

这是项目列表的样子 促销:

<root>
  <ChainId>7290027600007</ChainId>
  <SubChainId>001</SubChainId>
  <StoreId>001</StoreId>
  <BikoretNo>9</BikoretNo>
  <DllVerNo>8.0.0.0</DllVerNo>
  <Promotions Count="1381">
    <Promotion>
      <PromotionId>168144</PromotionId>
      <DiscountRate>10000</DiscountRate>
      <PromotionItems Count="3">
        <Item>
          <ItemCode>11210000094</ItemCode>
        </Item>
        <Item>
          <ItemCode>7290011078806</ItemCode>

        </Item>
        <Item>
          <ItemCode>7290011078807</ItemCode>
        </Item>
      </PromotionItems>
      <Clubs>
        <ClubId>0</ClubId>
        <ClubId>3</ClubId>
      </Clubs>
    <PromotionStartDate>2015-01-31</PromotionStartDate>
    <PromotionEndDate>2015-12-31</PromotionEndDate>
    </Promotion>
</Promotions>
</root>

非常频繁的查询可以是:

  

用于给定商店和消费者的给定物品代码列表   俱乐部然后获取所有相关的项目价格和所有相关的   促销

(即促销中包含来自给定列表和消费者俱乐部的至少一个项目以及startDate和endDate之间的当前日期)

因此,对于每个项目,我将获得价格和可选的相关促销(项目可以包含在多个促销中或没有,促销包括至少一个项目) 我该如何建模呢? 一个选项是为每个单独的表和连接表(理性样式)创建:

CREATE TABLE IF NOT EXISTS promos_with_items(
                               promotionId varchar,
                               promotion_item varchar,
                               PRIMARY KEY(promotion_item,promotionId)
) WITH comment='Promotions with items';

CREATE TABLE IF NOT EXISTS promos(
                               chainid varchar,
                               subchainid varchar,
                               storeid varchar,
                               promotionId varchar,
                               start timestamp,
                               end timestamp,
                               discountRate double,
                               discountType int,
                               clubs set<int>

) WITH comment='Promotions';

CREATE TABLE IF NOT EXISTS Item(
                chainid varchar,
                subchainid varchar,
                storeid varchar,
                itemid varchar,
                itemPrice double);

另一种选择更多Cassandra风格(但感觉不对)是一张表:

CREATE TABLE IF NOT EXISTS items_with_promos(
                               chainid varchar,
                               subchainid varchar,
                               storeid varchar,
                               itemid varchar,
                               itemPrice double
                               promotionId varchar,
                               start timestamp,
                               end timestamp,
                               discountRate double,
                               discountType int,
                               clubs set<int>                               
                               ;

但在这种情况下,如果该项目包含在多个促销中,或者如果未包含在任何促销中,会发生什么情况 什么应该是关键/索引?应该是chainid,subchainid,storeid,客户俱乐部,约会?

0 个答案:

没有答案