Flink序列化错误

时间:2016-07-26 19:35:16

标签: serialization apache-flink gelly

我试图在Apache Flink Gelly Graph上运行Label传播协议 这是我的代码:

        Graph<String, Long, String> ugraph = Graph.fromDataSet(vertex, edgeSet, env).getUndirected();
        DataSet<Tuple2<String, Long>> idsWithInitialLabels = DataSetUtils
            .zipWithUniqueId(graph.getVertexIds())
            .map(new MapFunction<Tuple2<Long, String>, Tuple2<String, Long>>() {
                public Tuple2<String, Long> map(Tuple2<Long, String> tuple2) throws Exception {
                    return new Tuple2<String, Long>(tuple2.f1, tuple2.f0);
                }
            }); 
        DataSet<Vertex<String, Long>> verticesWithCommunity = graph.joinWithVertices(idsWithInitialLabels,
            new VertexJoinFunction<Long, Long>() {
            public Long vertexJoin(Long vertexValue, Long inputValue) {
            return inputValue;
        }})
    .run(new LabelPropagation<String, Long, String>(10)); 

我收到以下错误消息:

org.apache.flink.api.common.InvalidProgramException:Object org.apache.flink.graph.Graph$ApplyCoGroupToVertexValues@4dde0543 not serializable     在org.apache.flink.api.java.ClosureCleaner.ensureSerializable(ClosureCleaner.java:99)     在org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:61)     在org.apache.flink.api.java.DataSet.clean(DataSet.java:186)     at org.apache.flink.api.java.operators.CoGroupOperator $ CoGroupOperatorSets $ CoGroupOperatorSetsPredicate $ CoGroupOperatorWithoutFunction.with(CoGroupOperator.java:619)     在org.apache.flink.graph.Graph.joinWithVertices(Graph.java:587)     在tu.master.ConceptDetection.TextProcessor.clustering(TextProcessor.java:405)     在tu.master.ConceptDetection.TextProcessor $ 4.actionPerformed(TextProcessor.java:210)

感谢您的帮助:)

1 个答案:

答案 0 :(得分:0)

我猜测包含您的图形代码的类不是Serializable。 Java中的匿名类实际上是非静态内部类,这意味着它们具有对包含类的this的引用(请参见this answer)。如果包含的类不是Serializable,则this引用将不会序列化,匿名类也不会序列化。

这将解释为什么切换到lambda表达式会使它序列化。 Lambda表达式不是匿名类,因此它们不会自动捕获隐式this引用。

没有解释的是为什么将MapFunction声明为匿名类仍然有效。如果您仍然有@Nesrine这样的代码,我很好奇整个类的样子。