Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database design 如何在cassandra中与表本身建立多对多关系_Database Design_Cassandra_Data Modeling_Database_Nosql - Fatal编程技术网

Database design 如何在cassandra中与表本身建立多对多关系

Database design 如何在cassandra中与表本身建立多对多关系,database-design,cassandra,data-modeling,database,nosql,Database Design,Cassandra,Data Modeling,Database,Nosql,实际上,我正在开发一个应用程序,在这个应用程序中,一个用户表可以与其自身有多对多的关系 这是一个应用程序,其中一个特定的用户可以向不同的买家出售物品,也可以从不同的卖家购买物品。 也就是说,一个特定的用户可以有很多买家和卖家 因为一个用户正在向其他用户出售物品。 用户成为该特定用户的卖方&该特定用户成为该用户的买方 我对卡桑德拉很陌生,我不知道卡桑德拉的人际关系如何运作 谁能告诉我,我该怎么建立这种关系 我的用户表如下:- CREATE TABLE IF NOT EXISTS user (

实际上,我正在开发一个应用程序,在这个应用程序中,一个用户表可以与其自身有多对多的关系

这是一个应用程序,其中一个特定的用户可以向不同的买家出售物品,也可以从不同的卖家购买物品。 也就是说,一个特定的用户可以有很多买家和卖家

因为一个用户正在向其他用户出售物品。 用户成为该特定用户的卖方&该特定用户成为该用户的买方

我对卡桑德拉很陌生,我不知道卡桑德拉的人际关系如何运作

谁能告诉我,我该怎么建立这种关系

我的用户表如下:-

CREATE TABLE IF NOT EXISTS user (
    id text,
    login text,
    password text,
    firstName text,
    lastName text,
    gender text,
    mobileNo text,
    aadhar text,
    email text,
    stateCode text,
    district text,
    city text,
    zipCode int,
    address text,
    PRIMARY KEY(id)
);

Cassandra是一个NoSQL数据库,它的一个特殊特性是存储非结构化数据。所以,您不应该考虑表之间的关系,而应该考虑如何获取这些信息(换句话说,您的“select*from”字段是什么)

你应该去看看

之后,您将注意到两件事:

  • 主键在cassandra存储中起着巨大的作用
  • 只能使用主键筛选搜索(where子句)
  • 您要查找的是每个搜索cql都有一个表:

    create table sells_by_user_id (
    user_id text,
    buyer_id text,
    date timestamp,
    item text,
    item_description,
    ..., <this will depend on which info you would like to obtain
    primary key ((user_id), date)); //with this table you will obtain all the things that a user sold and to whom
    
    create table buys_by_user_id (
    user_id text,
    seller_id text,
    date timestamp,
    item text,
    item_description,
    ..., <this will depend on which info you would like to obtain
    primary key ((user_id), date)); //this table will store all things that an user bought 
    
    按用户id创建表(
    用户id文本,
    买方id文本,
    日期时间戳,
    项目案文,
    项目描述,
    
    …,列出您要执行的所有查询类型。在Cassandra中,表是基于select query设计的。我将处理它,并尝试查看它是否适合我的应用程序