Flink序列化错误



我正试图在我的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:对象org.apache.frink.graph.graph$ApplyCoGroupToVertexValues@4dde0543不可序列化网址: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.Datat.clean(DataSet.java:186)在org.apache.flink.api.java.operators.CoGroupOperator$CoGroupOperatorSetsCoGroupOperatorsSetsPredicate$CoGroupOperator WithoutFunction.with(CoGroupOperaer.java:619)网址:org.apache.flink.graph。graph。joinWithVertices(graph。java:587)位于tu.master.ConseptDetection.TextProcessor.clustering(TextProcessor.java:405)在tu.master.ConseptDetection.TextProcessor$4.actionPerformed(TextProcessor.java:210)

感谢您的帮助:)

我猜包含图形代码的类不是Serializable。Java中的匿名类实际上是非静态的内部类,这意味着它们引用了包含类的this(请参阅此答案)。如果包含类不是Serializable,则this引用不会序列化,匿名类也不会序列化。

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

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

相关内容

  • 没有找到相关文章

最新更新