[英]Flink Gelly extending edge class and using it in DataSet
在 Gelly 中,我正在嘗試制作一個稱為 Temporal Edge 的特殊 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 DataSet 中,以便它可以在圖形中使用,但我似乎無法弄清楚如何使用。 但是,當我使用具有相同構造函數的 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
無效的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.