在gelly中,我试图创建一个特殊的边,称为时间边,为了使这更容易,我创建了一个类,称为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>'less。。。
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>
也许我只是不知道如何使用泛型类型
1条答案
按热度按时间guz6ccqo1#
你不需要延长时间
Edge
类型。你可以简单地使用Tuple3
或自定义边值类型。您的图形声明
Graph<Long, NullValue, Tuple3<Double,Integer,Integer>>
期望DataSet<Edge<Long, Tuple3<Double,Integer,Integer>>>
作为边输入。所以你的temporalgraph2
申报有效,但temporalgraph
不。