SELECT count(*) FROM device_stats
WHERE orgid = 'XYZ'
AND regionid = 'NY'
AND campusid = 'C1'
AND buildingid = 'C1'
AND floorid = '2'
AND year = 2017;
以上CQL查询在CQL Shell中返回正确结果 - 32032
但是当我使用QueryBuilder Java API运行相同的查询时,我看到计数为0
BuiltStatement summaryQuery = QueryBuilder.select()
.countAll()
.from("device_stats")
.where(eq("orgid", "XYZ"))
.and(eq("regionid", "NY"))
.and(eq("campusid", "C1"))
.and(eq("buildingid", "C1"))
.and(eq("floorid", "2"))
.and(eq("year", "2017"));
try {
ResultSetFuture tagSummaryResults = session.executeAsync(tagSummaryQuery);
tagSummaryResults.getUninterruptibly().all().stream().forEach(result -> {
System.out.println(" totalCount > "+result.getLong(0));
});
我每个分区只有20个分区和32032行。
QueryBuilder没有正确执行查询的原因是什么?
架构:
CREATE TABLE device_stats (
orgid text,
regionid text,
campusid text,
buildingid text,
floorid text,
year int,
endofwindow timestamp,
categoryid timeuuid,
devicestats map<text,bigint>,
PRIMARY KEY ((orgid, regionid, campusid, buildingid, floorid,year),endofwindow,categoryid)
) WITH CLUSTERING ORDER BY (endofwindow DESC,categoryid ASC);
// Using the keys function to index the map keys
CREATE INDEX ON device_stats (keys(devicestats));
我正在使用 cassandra 3.10和com.datastax.cassandra:cassandra-driver-core:3.1.4
答案 0 :(得分:1)
将我的评论移至答案,因为这似乎解决了原始问题:
将.and(eq("year", "2017"))
更改为.and(eq("year", 2017))
解决了问题,因为year
是int
而不是text
。