这是将在cassandra数据库上创建表的实体类 .
@Table
public class Log {
@PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED)
private LocalDate date; //partition key
@PrimaryKeyColumn(ordinal = 1, type = PrimaryKeyType.PARTITIONED)
private String name; //partition key
@PrimaryKeyColumn(ordinal = 2, type = PrimaryKeyType.PARTITIONED)
private String catagory; //partition key
@PrimaryKeyColumn(ordinal = 3, type = PrimaryKeyType.CLUSTERED)
private String timeStamp; //clustering column
private String type;
private String description;
}
主键是((日期,名称,类别),时间戳)其中(日期,名称,类别)是分区键,时间戳是聚类列 .
这是执行插入时的预期数据
Date | name | category| timestamp | type | description |
------------------------------------------------------------------
2017-10-11 | 201 | General | 19:51:18.732 | short | desc1 |
-------------------------------------------------------------------
2017-10-11 | 201 | General | 19:51:18.735 | long | desc2 |
-------------------------------------------------------------------
2017-10-11 | 201 | General | 19:51:18.736 | short | desc3 |
-------------------------------------------------------------------
2017-10-11 | 201 | General | 19:51:18.738 | long | desc4 |
-------------------------------------------------------------------
2017-10-11 | 201 | General | 19:51:18.740 | short | desc5 |
-------------------------------------------------------------------
2017-10-11 | 201 | General | 19:51:18.741 | short | desc6 |
-------------------------------------------------------------------
2017-10-11 | 201 | General | 19:51:18.743 | long | desc7 |
-------------------------------------------------------------------
2017-10-11 | 201 | General | 19:51:18.745 | short | desc8 |
-------------------------------------------------------------------
当使用CrudRepository的save方法执行插入时,下面的数据存储在Cassandra中 . 有些行是upserted . 缺少描述desc3,desc5的行 .
Date | name | category| timestamp | type | description |
------------------------------------------------------------------
2017-10-11 | 201 | General | 19:51:18.732 | short | desc1 |
-------------------------------------------------------------------
2017-10-11 | 201 | General | 19:51:18.735 | long | desc2 |
-------------------------------------------------------------------
2017-10-11 | 201 | General | 19:51:18.738 | long | desc4 |
-------------------------------------------------------------------
2017-10-11 | 201 | General | 19:51:18.741 | short | desc6 |
-------------------------------------------------------------------
2017-10-11 | 201 | General | 19:51:18.743 | long | desc7 |
-------------------------------------------------------------------
2017-10-11 | 201 | General | 19:51:18.745 | short | desc8 |
-------------------------------------------------------------------
正在使用的Repo是一个扩展CrudRepository的接口,如下所示:
public interface LogRepo extends CrudRepository<Log , LocalDate>
{
...
}
执行的插入代码如下:
for(...){
..
logRepo.save(log); //each object is saved
..
}
由于群集列是时间戳,并且在这种情况下是唯一的,因此理想情况下不应该对行进行插值 . 请告知是否有任何遗漏,以避免记录 .