Loading

Cassandra Key

单独primary key

Cassandra :

CREATE TABLE student (firstName text , lastName text, score int, PRIMARY KEY (firstName))

Java :

@PartitionKey
private String firstName;

@Column(name = "lastName")
private String lastName;

@Column(name = "score")
private int score;

2个Primary Key

Cassandra :

CREATE TABLE student (firstName text , lastName text, score int, PRIMARY KEY (firstName, lastName))

Java :

@PartitionKey(0)
private String firstName;

@PartitionKey(1)
private String lastName;

@Column(name = "score")
private int score;

查询:

select * from student where firstName = "*"; ✘
select * from student where lastName = "*"; ✖︎
select * from student where firstName ="*" and lastName ="*";  ✔︎
@PartitionKey
private String firstName;

@ClusteringColumn
private String lastName;

@Column(name = "score")
private int score;

查询:

select * from student where firstName = "*"; ✔︎
select * from student where lastName = "*"; ✖︎
select * from student where firstName ="*" and lastName ="*";  ✔︎
posted @ 2020-08-10 21:28  亡灵族  阅读(117)  评论(0编辑  收藏  举报