榛子地图计数机制

huangapple go评论185阅读模式
英文:

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);

huangapple
  • 本文由 发表于 2020年9月8日 10:52:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/63786490.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定