1

I created a table and its primary key is ((A1, A2), A3, A4, A5).
I'd like to use cassandraTemplate.select(select, MyClass.class); to select some records.

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);

I got the following error: 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;

Creation script:

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' };
niaomingjian
  • 3,472
  • 8
  • 43
  • 78
  • 2
    can you show the table creation script, because http://stackoverflow.com/questions/24949676/difference-between-partition-key-composite-key-and-clustering-key-in-cassandra describes the problem, but also describes that A3, A4 and A5 are NOT part of the partition key – Jens Schauder Jan 03 '17 at 10:46
  • Additionally, get rid of `allowFiltering()`. If your queries *need* ALLOW FILTERING to work, then you've built your model incorrectly. Also, setting your read timeout to 100 seconds is a good way to tip over a node. – Aaron Jan 03 '17 at 13:19
  • @Aaron After I got rid of allowFiltering(), I got the same error. In the command line, I ran the cql statement directly and I also got the same error. – niaomingjian Jan 04 '17 at 03:26
  • @JensSchauder I have added my creation script. – niaomingjian Jan 04 '17 at 03:31
  • Thank you very much. I made a mistake. Actually, my primary key is ((A1, A2, A3, A4), A5). I know where I was wrong. – niaomingjian Jan 04 '17 at 03:37
  • 1
    Please add your solution as an answer and accept it, so others can find it. – Jens Schauder Jan 04 '17 at 06:39

1 Answers1

2
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' };

I made a mistake. Actually, PRIMARY KEY of my table are ((A1, A2,A3, A4),A5).

niaomingjian
  • 3,472
  • 8
  • 43
  • 78