【发布时间】:2019-05-11 01:40:24
【问题描述】:
我正在使用 PreparedStatement 和 boundStatment 来执行一些 Cassandra 查询。我正在尝试执行范围查询。这是我要创建的查询:
getAllRecordsOnIndexRange = getSession.prepare(QueryBuilder.select(documentId, documentName, documentIndex)
.from(tableName)
.where(QueryBuilder.eq(documentId,QueryBuilder.bindMarker()))
.and(QueryBuilder.gte(documentIndex, QueryBuilder.bindMarker()))
.and(QueryBuilder.lte(documentIndex, QueryBuilder.bindMarker())));
'documentId' 是分区键,'documentIndex' 是集群键。我想对列 documentIndex 进行范围查询,例如“获取给定 documentId 和 documentIndex >= 3 和 documentIndex
当我想运行查询时,我调用
public Statement buildGetAllRecordsOnIndexRange(int documentId, String documentName, int startDocumentIndex, int endDocumentIndex)
{
BoundStatement boundStatement = getAllRecordsOnIndexRange
.bind()
.setString(DOCUMENT_ID, documentId)
//how to set start and end documentIndex
databaseManager.applyReadStatementsConfiguration(boundStatement);
return boundStatement;
}
如何为上述查询设置 startDocumentIndex 和 endDocumentIndex?
【问题讨论】:
-
您的列“documentIndex”是聚类列吗?
-
是的 'documentIndex' 是聚类列。
标签: java cassandra prepared-statement datastax datastax-java-driver