NoSQL的。卡桑德拉。建模外部ID

时间:2016-03-12 13:55:09

标签: python database-design cassandra nosql

我们有类似的产品:

if Product.filter(wikimart_id=external_id):
   p = Product.get(shop_id=shop_id, wikimart_id=external_id)
   d['product_id'] = p.product_id # Setting key in dict from which model will be updated

我们会定期(每天一次)从列表中更新产品。

目前我们必须使用像

这样的结构
class ProductWikimart(Model):
    """
    Wikimart Product Model
    """
    shop_id = columns.UUID(primary_key=True, required=True)
    wikimart_id = columns.Integer(primary_key=True)
    product_id = columns.UUID(index=True)

class ProductYandex(Model):
    """
    Yandex Product Model
    """
    shop_id = columns.UUID(primary_key=True, required=True)
    yandex_id = columns.Integer(primary_key=True)
    product_id = columns.UUID(index=True)

Cassandra是否可以,或者我们应该考虑如何创建将external_id作为更新产品主键的模型?

喜欢:

BanksController

哪种方式更可取?

UPD 这个问题是关于NoSQL的通用建模。不仅仅是关于cassandra:)

1 个答案:

答案 0 :(得分:1)

也许这article会对你有所帮助。

由于相对频繁的更改,我认为product_id不是群集密钥的理想选择。所以,我认为产品模型的第二个版本(使用ProductWikimart和ProductYandex)会更好。但是,您可以遇到新问题:例如,如何匹配ProductWikimart和ProductYandex产品ID?

谈到Cassandra的数据建模,一般有Model Around Your Queries规则。所以,要告诉哪种表格结构更好,我们应该知道如何请求它。

相关问题