0

我正在使用 hazelcast 3.6.1 并使用自定义 mapreduce 实现不同的聚合功能以获得 solr facet 类型的结果。

public class DistinctMapper implements Mapper<String, Employee, String, Long>{

    private transient SimpleEntry<String, Employee> entry = new SimpleEntry<String, Employee>();

    private static final Long ONE = Long.valueOf(1L);

    private Supplier<String, Employee, String> supplier;

    public DistinctMapper(Supplier<String, Employee, String> supplier) {
        this.supplier = supplier;
    }

    @Override
    public void map(String key, Employee value, Context<String, Long> context) {
        System.out.println("Object "+ entry + " and key "+key);
        entry.setKey(key);
        entry.setValue(value);
        String fieldValue = (String) supplier.apply(entry);
        //getValue(value, fieldName);
        if (null != fieldValue){
            context.emit(fieldValue, ONE);
        }
    }
}

并且映射器因 NullPointerException 而失败。并且 sysout 语句说条目对象为空。

简单条目:https ://github.com/hazelcast/hazelcast/blob/v3.7-EA/hazelcast/src/main/java/com/hazelcast/mapreduce/aggregation/impl/SimpleEntry.java

你能指出我上面代码中的问题吗?谢谢。

4

1 回答 1

1

entry场是瞬态的。这意味着它没有被序列化,所以当DistinctMapper对象在 hazecalst 节点上反序列化时,它的值为 null。删除瞬态将解决NullPointerException.

旁注:为什么需要这个输入字段?它似乎没有任何用处。

于 2016-08-02T19:20:25.543 回答