我试图使用hazelcast聚合来执行计数操作。
例子:-
在这里,我希望计算json中存在的salary1字段的数量。
String json1 = "{\r\n" + " \"salary\": 200\r\n" + "}";
String json2 = "{\r\n" + " \"salary\": 300\r\n" + "}";
String json5 = "{\r\n" + " \"salary1\": 300\r\n" + "}";
map.put(1, new HazelcastJsonValue(json1));
map.put(2, new HazelcastJsonValue(json2));
map.put(3, new HazelcastJsonValue(json5));
Long count = map.aggregate(Aggregators.count("salary1"));
System.out.println("count is " + count);我只有一个salary1字段,但它仍然给出了完整的计数。
有什么问题吗?
发布于 2020-09-08 08:06:46
我认为您需要使用Predicate首先对计数的条目进行筛选。试试看以下几点。
Predicate p = Predicates.notEqual("salary1", null);
Long count = map.aggregate(Aggregators.count(), p);https://stackoverflow.com/questions/63786490
复制相似问题