英文:
Hazelcast Count mechanism
问题
我正在尝试使用Hazelcast聚合来执行计数操作。
示例:
在这里,我想要计算JSON中存在的salary1字段的数量。
String json1 = "{\"salary\": 200}";
String json2 = "{\"salary\": 300}";
String json5 = "{\"salary1\": 300}";
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字段,但它仍然给出了完整的计数。
问题是什么?
英文:
I was trying to use hazelcast aggregation to perform the count operations.
Example:-
Here I'm looking to count number of salary1 fields present in the json.
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);
I have only one salary1 field but its still giving the full count.
what is the issue?
答案1
得分: 2
我认为你需要使用“Predicate”来首先筛选要计数的条目。尝试以下操作。
Predicate p = Predicates.notEqual("salary1", null);
Long count = map.aggregate(Aggregators.count(), p);
英文:
I think you need to use Predicate
to filter first the entries you count. Try the following.
Predicate p = Predicates.notEqual("salary1", null);
Long count = map.aggregate(Aggregators.count(), p);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论