NoSQL公司。卡桑德拉。外部ID建模

2024-10-03 15:24:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我们有如下产品:

class Product(Model):
    """
    Base Product Model
    """
    shop_id = columns.UUID(primary_key=True, required=True)
    product_id = columns.UUID(primary_key=True, required=True, default=uuid.uuid4)    
    wikimart_id = columns.Integer(index=True) # Convert to user defined type?
    yandex_id = columns.Integer(index=True)

我们定期(每天一次)更新列表中的产品。你知道吗

现在我们必须使用这样的结构

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

对Cassandra来说可以吗,或者我们应该考虑如何创建将外部\u id作为更新产品主键的模型?你知道吗

比如:

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)

哪种方式更可取?你知道吗

UPD这个问题是关于NoSQL的通用建模。不仅仅是关于卡桑德拉:)


Tags: columnskeyidtrueindexmodeluuid产品
1条回答
网友
1楼 · 发布于 2024-10-03 15:24:42

也许这个article会对你有帮助。你知道吗

我不认为产品id是一个很好的候选集群密钥,因为它相对频繁的变化。因此,我认为产品模型的第二个版本(使用ProductWikimart和ProductYandex)会更好。但接下来会出现新的问题:例如,如何匹配ProductWikimart和ProductYandex产品id?你知道吗

谈到Cassandra的数据建模,通常有Model Around Your Queries规则。因此,要判断哪种表结构更好,我们应该知道如何请求它。你知道吗

相关问题 更多 >