2017-01-03 81 views
0

我创建了一个表,其主键是((A1,A2),A3,A4,A5)。
我想使用cassandraTemplate.select(select,MyClass.class);选择一些记录。什么是'分区关键部分:XXXX必须限制为其他部分是'意思是

select.setConsistencyLevel(com.datastax.driver.core.ConsistencyLevel.ONE); 
select.where(QueryBuilder.eq("A1", A1)) 
     .and(QueryBuilder.eq("A2", A2)) 
     .and(QueryBuilder.eq("A3", A3)).limit(100).allowFiltering() 
     .setReadTimeoutMillis(100 * 1000); 

我得到了以下错误: HTTP status 500 - Request processing failed; nested exception is org.springframework.cassandra.support.exception.CassandraInvalidQueryException: Partition key parts: A4 must be restricted as other parts are;

创建脚本:

Create Table TestTable (
    A1 ascii, 
    A2 int, 
    A3 int, 
    A4 ascii, 
    A5 int, 
    A6 bigint, 
    A7 bigint, 
    A8 ascii, 
    PRIMARY KEY ((A1, A2),A3, A4,A5) 
) WITH compression = { 'sstable_compression' : 'DeflateCompressor', 'chunk_length_kb' : 64 } 
    AND compaction = { 'class' : 'LeveledCompactionStrategy' }; 
+2

可以显示表创建脚本,因为http://stackoverflow.com/questions/24949676/difference-between-partition-key-composite-key-and-clustering-key-in-cassandra描述了这个问题,但还描述了A3,A4和A5不是分区键的一部分 –

+0

另外,摆脱'allowFiltering()'。如果您的查询*需要*允许过滤器正常工作,那么您已经错误地构建了您的模型。另外,将读取超时设置为100秒是翻转节点的好方法。 – Aaron

+0

@Aaron在我摆脱了allowFiltering()后,我得到了同样的错误。在命令行中,我直接运行了cql语句,并且也遇到了同样的错误。 – niaomingjian

回答

1
Create Table TestTable (
    A1 ascii, 
    A2 int, 
    A3 int, 
    A4 ascii, 
    A5 int, 
    A6 bigint, 
    A7 bigint, 
    A8 ascii, 
    PRIMARY KEY ((A1, A2,A3, A4),A5) 
) WITH compression = { 'sstable_compression' : 'DeflateCompressor', 'chunk_length_kb' : 64 } 
    AND compaction = { 'class' : 'LeveledCompactionStrategy' }; 

我犯了一个错误。实际上,我的表的PRIMARY KEY是((A1,A2,A3,A4),A5)。

相关问题