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' };
可以顯示錶創建腳本,因爲http://stackoverflow.com/questions/24949676/difference-between-partition-key-composite-key-and-clustering-key-in-cassandra描述了這個問題,但還描述了A3,A4和A5不是分區鍵的一部分 –
另外,擺脫'allowFiltering()'。如果您的查詢*需要*允許過濾器正常工作,那麼您已經錯誤地構建了您的模型。另外,將讀取超時設置爲100秒是翻轉節點的好方法。 – Aaron
@Aaron在我擺脫了allowFiltering()後,我得到了同樣的錯誤。在命令行中,我直接運行了cql語句,並且也遇到了同樣的錯誤。 – niaomingjian