Java 将RDD转换为映射列表

Java 将RDD转换为映射列表,java,lambda,spark-streaming,anonymous-function,rdd,Java,Lambda,Spark Streaming,Anonymous Function,Rdd,我需要将每个RDD转换为NavigableMap,并以匿名函数的形式存储在列表中。我正在做一个JavaPairDStream-put的工作 到目前为止,我所拥有的: puts.foreachRDD(r -> List<NavigableMap<byte[], List<Cell>>> l = r.map(t -> t._2().getFamilyCellMap()).collect(); return null; }

我需要将每个RDD转换为NavigableMap,并以匿名函数的形式存储在
列表中。我正在做一个
JavaPairDStream-put
的工作

到目前为止,我所拥有的:

puts.foreachRDD(r ->
    List<NavigableMap<byte[], List<Cell>>> l = r.map(t ->
        t._2().getFamilyCellMap()).collect();
    return null;
});
put.foreachRDD(r->
列表l=r.map(t->
t、 _2().getFamilyCellMap()).collect();
返回null;
});
这会在
.collect()
处引发NotSerializableException,因为
单元格
不可序列化


所以我需要以某种方式将
单元格
转换为
映射这就是我最终如何进行的。在收集
之前,我需要
原语
。我试图收集
.getFamilyCellMap()
的返回值,它是一个
映射
,不可
序列化

然后我将其转换回
断言之前的
映射

以下是
Java
代码:

puts.foreachRDD(r -> {
        List<String> l = r.flatMap(t -> {
                    Collection<List<Cell>> collection = t._2().getFamilyCellMap().values();
            return collection.stream()
                    .flatMap(Collection::stream)
                    .map(CellUtil::cloneValue))
                    .collect(Collectors.toList());
                }).collect();

        //Mapping for testing
        ObjectMapper objectMapper = new ObjectMapper();
        Map<String, Object> map1 = objectMapper.readValue(l.get(1), new TypeReference<Map<String, Object>>(){});
        Map<String, Object> map2 = objectMapper.readValue(l.get(2), new TypeReference<Map<String, Object>>(){});

        System.out.println(map1);
        Assert.assertEquals(map1.get("attribute1").toString(), expected1);
        //etc
        System.out.println(map2);
        Assert.assertEquals(map2.get("attribute2").toString(), expected2);
        //etc
    }
    return null;
});
put.foreachRDD(r->{
列表l=r.flatMap(t->{
集合集合=t._2().getFamilyCellMap().values();
return collection.stream()
.flatMap(集合::流)
.map(CellUtil::cloneValue))
.collect(Collectors.toList());
}).收集();
//用于测试的映射
ObjectMapper ObjectMapper=新的ObjectMapper();
MapMap1=objectMapper.readValue(l.get(1),newTypeReference(){});
Map map2=objectMapper.readValue(l.get(2),new TypeReference(){});
System.out.println(map1);
Assert.assertEquals(map1.get(“attribute1”).toString(),expected1);
//等
System.out.println(map2);
Assert.assertEquals(map2.get(“attribute2”).toString(),expected2);
//等
}
返回null;
});

希望这能帮助有需要的人。

这就是我最终如何去做的。在收集
之前,我需要
原语
。我试图收集
.getFamilyCellMap()
的返回值,它是一个
映射
,不可
序列化

然后我将其转换回
断言之前的
映射

以下是
Java
代码:

puts.foreachRDD(r -> {
        List<String> l = r.flatMap(t -> {
                    Collection<List<Cell>> collection = t._2().getFamilyCellMap().values();
            return collection.stream()
                    .flatMap(Collection::stream)
                    .map(CellUtil::cloneValue))
                    .collect(Collectors.toList());
                }).collect();

        //Mapping for testing
        ObjectMapper objectMapper = new ObjectMapper();
        Map<String, Object> map1 = objectMapper.readValue(l.get(1), new TypeReference<Map<String, Object>>(){});
        Map<String, Object> map2 = objectMapper.readValue(l.get(2), new TypeReference<Map<String, Object>>(){});

        System.out.println(map1);
        Assert.assertEquals(map1.get("attribute1").toString(), expected1);
        //etc
        System.out.println(map2);
        Assert.assertEquals(map2.get("attribute2").toString(), expected2);
        //etc
    }
    return null;
});
put.foreachRDD(r->{
列表l=r.flatMap(t->{
集合集合=t._2().getFamilyCellMap().values();
return collection.stream()
.flatMap(集合::流)
.map(CellUtil::cloneValue))
.collect(Collectors.toList());
}).收集();
//用于测试的映射
ObjectMapper ObjectMapper=新的ObjectMapper();
MapMap1=objectMapper.readValue(l.get(1),newTypeReference(){});
Map map2=objectMapper.readValue(l.get(2),new TypeReference(){});
System.out.println(map1);
Assert.assertEquals(map1.get(“attribute1”).toString(),expected1);
//等
System.out.println(map2);
Assert.assertEquals(map2.get(“attribute2”).toString(),expected2);
//等
}
返回null;
});
希望这能帮助有需要的人