gpt4 book ai didi

java - Flink Gelly 扩展边缘类并在 DataSet 中使用它

转载 作者:行者123 更新时间:2023-11-30 07:06:38 25 4
gpt4 key购买 nike

在 Gelly 中,我正在尝试创建一个称为 Temporal Edge 的特殊边缘,为了使这更容易,我创建了一个名为 Temporaledgev3 的类:

public class TemporalEdgev3<K, V> extends Edge<K, Tuple3<V,Integer,Integer>> {

/*
Creates new temporaledge with only null values
*/
public TemporalEdgev3() {}

/*
* Constructor to make a temporal edge version 2, has 5 input values but makes a
* typle 3 which is compatible with Gelly
* */
public TemporalEdgev3(K src, K trg, V val, Integer start, Integer end) {
this.f0 = src;
this.f1 = trg;
this.f2 = new Tuple3<V,Integer,Integer>(val,start,end);
}

现在我正在尝试将这些边添加到 Flink 数据集中,以便可以在图中使用它,但我似乎无法弄清楚如何使用。但是,当我使用具有相同构造函数的 Edge 类时,它可以工作。

这是代码,最后一行出现错误

// a temporal set created with Flink, now we need to make it into a temporal set into gelly
DataSet<Tuple5<Long,Long, Double,Integer, Integer>> temporalset = env.readCsvFile("./datasets/testdata")
.fieldDelimiter(",") // node IDs are separated by spaces
.ignoreComments("%") // comments start with "%"
.types(Long.class,Long.class,Double.class,Integer.class,Integer.class); // read the node IDs as Longs

DataSet<TemporalEdgev3<Long,Double>> edgeset3 = temporalset.map(new MapFunction<Tuple5<Long, Long, Double, Integer, Integer>, TemporalEdgev3<Long, Double>>() {
@Override
public TemporalEdgev3<Long, Double> map(Tuple5<Long, Long, Double, Integer, Integer> value) throws Exception {

return new TemporalEdgev3<Long, Double>(value.f0,value.f1,value.f2,value.f3,value.f4);
}
});

DataSet<Edge<Long,Tuple3<Double,Integer,Integer>>> edgeset4 = temporalset.map(new MapFunction<Tuple5<Long, Long, Double, Integer, Integer>, Edge<Long, Tuple3<Double, Integer, Integer>>>() {
@Override
public Edge<Long, Tuple3<Double, Integer, Integer>> map(Tuple5<Long, Long, Double, Integer, Integer> value) throws Exception {
return new Edge<Long, Tuple3<Double, Integer, Integer>>(value.f0,value.f1, new Tuple3<Double, Integer, Integer>(value.f2,value.f3,value.f4));
}
});

Graph<Long, NullValue, Tuple3<Double,Integer,Integer>> temporalgraph = Graph.fromDataSet(edgeset4,env);

Graph<Long,NullValue, Tuple3<Double,Integer,Integer>> temporalgraph2 = Graph.fromDataSet(edgeset3,env);

错误: 第一个参数类型错误。找到:'org.apache.flink.api.java.DataSet>',必需:'org.apache.flink.api.java.DataSet>'少...

fromDataSet
(org.apache.flink.api.java.DataSet<org.apache.flink.graph.Edge<K,EV>>,
ExecutionEnvironment)
in Graph cannot be applied
to
(org.apache.flink.api.java.DataSet<flink.gelly.school.TemporalEdgev3<java.lang.Long,java.lang.Double>>,
ExecutionEnvironment)
 
reason: no instance(s) of type variable(s) EV, K exist so that TemporalEdgev3<Long, Double> conforms to Edge<K, EV>

也许我根本不知道如何使用泛型类型

最佳答案

您不需要扩展Edge类型。您可以简单地使用 Tuple3或自定义边缘值类型。

您的图表声明Graph<Long, NullValue, Tuple3<Double,Integer,Integer>>预计 DataSet<Edge<Long, Tuple3<Double,Integer,Integer>>>作为边缘输入。这就是为什么你的 temporalgraph2声明有效,但是 temporalgraph没有。

关于java - Flink Gelly 扩展边缘类并在 DataSet 中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40007325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com