Cassandra QueryBuilder没有返回任何结果,而相同的查询在CQL shell中工作正常

时间:2017-06-23 16:37:37

标签: cassandra cql3 cassandra-3.0

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

1 个答案:

答案 0 :(得分:1)

将我的评论移至答案,因为这似乎解决了原始问题:

.and(eq("year", "2017"))更改为.and(eq("year", 2017))解决了问题,因为yearint而不是text