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
Cassandra:Error:code=2200[无效查询]消息=";主键列不能像前一列那样受到限制_Cassandra_Cassandra 3.0_Spring Data Cassandra - Fatal编程技术网

Cassandra:Error:code=2200[无效查询]消息=";主键列不能像前一列那样受到限制

Cassandra:Error:code=2200[无效查询]消息=";主键列不能像前一列那样受到限制,cassandra,cassandra-3.0,spring-data-cassandra,Cassandra,Cassandra 3.0,Spring Data Cassandra,表架构: CREATE TABLE com ( receiverid text, senderid text, commatriid text, comtype tinyint, comid text, displaystatus tinyint, comdate timestamp, cominfoid bigint, comstatus tinyint, dateactioned timestamp, d

表架构:

CREATE TABLE com (
    receiverid text,
    senderid text,
    commatriid text,
    comtype tinyint,
    comid text,
    displaystatus tinyint,
    comdate timestamp,
    cominfoid bigint,
    comstatus tinyint,
    dateactioned timestamp,
    datedeleted timestamp,
    dateread timestamp,
    dateupdated timestamp,
    disclosedmatriid tinyint,
    filteredmsg tinyint,
    message text,
    recentstatus tinyint,
    regionallang tinyint,
    transmsg text,
    PRIMARY KEY (receiverid, senderid, commatriid, comtype, comid, displaystatus, comdate)
) WITH CLUSTERING ORDER BY (senderid ASC, commatriid ASC, comtype ASC, comid ASC, displaystatus ASC, comdate ASC);
选择带有where子句的查询:

SELECT ComInfoId,ComId,ComType,SenderId,ReceiverId,ComMatriId,ComDate,ComStatus FROM com WHERE ComMatriId='M1'AND SenderId='M79984222' and ReceiverId='M2' and ComDate <= '2017-11-14 09:20:05+0000';

从com中选择ComInfoId、ComId、ComType、SenderId、ReceiverId、COMMATRID、ComDate、ComStatus,其中COMMATRID='M1'和SenderId='M79984222'以及ReceiverId='M2'和ComDate的顺序与主键列的顺序有关,并且数据存储在磁盘中的方式仅允许在还指定了之前的键时选择数据

PRIMARY KEY (receiverid, senderid, commatriid,
             comtype, comid, displaystatus, comdate)
您收到的错误意味着,如果您想通过
comdate
进行查询,则还需要通过前面的所有键进行查询:
receiverid、senderid、commatrid、comtype、comid、displaystatus

如果要按
comtype
进行查询,则需要指定`receiverid、senderid、commatiid、comtype`

为什么我必须指定其他键? 这可以归结为卡桑德拉的设计方式,表现也是如此。所有内容都存储在分区中,并按顺序存储在磁盘上,因此数据库只需做最少的工作。缺点是,您需要知道在设计模式时要运行哪些查询

将磁盘上的数据可视化为一个数组(请原谅所有等于整数的列):

以下面的查询和我像Cassandra一样访问数据的示例为例

  • 在(1,2)中的接收人位置

    result=(数据[1],数据[2])

  • 其中(1)中的接收方ID和发送方ID=1

    result=data[1][1]

  • 其中接收方ID在(1)中,发送方ID=1,通信类型=1

    result=data[1][1][??][1]

    这就是它变得有趣的地方。我故意遗漏了where子句中的
    commatiid
    字段。现在C*可以将结果缩小到
    data[1][1]
    ,但是它应该查找哪个
    commatiid
    索引来返回数据?它不知道,因为我没有指定它

  • 其中(1)中的receiverid和senderid=1,comtype=1和commatiid=1

    result=数据[1][1][1][1]

    现在我们已经包括了
    commatiid
    ,我们知道数据要访问哪个索引


  • 从select查询中的where子句中删除COMMATRID,然后检查一次输出。。 我想,这样的查询不应该在查询搜索键中有多个集群键的情况下发生。如果我错了,请纠正我

    这可能会帮助您:

    data =
    receiverid(1)
        senderid(1)
            commatriid(1)
                comtype(1)
                    comid(1)
                        displaystatus(1)
                            comdate(1)
                            comdate(2)
                            comdate(3)
        senderid(2)
            commatriid(1)
                comtype(1)
                    comid(1)
                        displaystatus(1)
                            comdate(1)
                            comdate(2)
                            comdate(3)