英文:
Handling null values Hazelcast Projections
问题
处理Hazelcast投影中的空值
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
IMap<Integer, HazelcastJsonValue> map = hz.getMap("myMap");
map.set(0, new HazelcastJsonValue("{\"id\":\"01\",\"name\":\"abc\",\"age\":null}"));
map.set(1, new HazelcastJsonValue("{\"id\":\"02\",\"name\":\"data\",\"age\":37}"));
map.set(2, new HazelcastJsonValue("{\"id\":\"03\",\"name\":\"abc\",\"age\":39}"));
Collection<Object[]> projection = map.project(Projections.multiAttribute("id", "name", "age"));
在上面的代码中,您可以观察到第一个条目的age字段为null,因此Projections会抛出异常。如何在抛出异常之前返回null值...
英文:
How to handle null values in the hazelcast projections
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
IMap<Integer, HazelcastJsonValue> map = hz.getMap("myMap");
map.set(0, new HazelcastJsonValue("{\"id\":\"01\",\"name\":\"abc\",\"age\":null}"));
map.set(1, new HazelcastJsonValue("{\"id\":\"02\",\"name\":\" data\",\"age\":37} "));
map.set(2, new HazelcastJsonValue("{\"id\":\"03\",\"name\":\"abc\",\"age\":39}"));
Collection<Object[]> projection = map.project(Projections.multiAttribute("id", "name","age"));
In the above code you can observe that age field is null for the first entry so Projections is throwing exception.
How to just return the null value inside of throwing exception...
答案1
得分: 0
你使用的是哪个 Hazelcast 版本?
我尝试过 4.0.2 版本。我已经添加了以下代码片段来打印这些元素:
projection.stream()
.flatMap(Stream::of)
.forEach(System.out::println);
它输出如下:
03
abc
39
01
abc
null
02
data
37
英文:
Which Hazelcast version are you using?
I've tried with 4.0.2. I've added the following snippet to print the elements:
projection.stream()
.flatMap(Stream::of)
.forEach(System.out::println);
It outputs the following:
03
abc
39
01
abc
null
02
data
37
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论