首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flink Gelly扩展edge类及其在DataSet中的应用

Flink Gelly扩展edge类及其在DataSet中的应用
EN

Stack Overflow用户
提问于 2016-10-13 04:00:40
回答 1查看 102关注 0票数 1

在Gelly中,我试图创建一个特殊的边缘,称为时间边缘,为了更容易实现,我创建了一个名为Temporaledgev3的类:

代码语言:javascript
复制
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类时,它可以正常工作。

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

代码语言:javascript
复制
// 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>‘较少...

代码语言:javascript
复制
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>

也许我只是不了解如何使用泛型类型

EN

回答 1

Stack Overflow用户

发布于 2016-10-16 02:29:52

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

您的图声明Graph<Long, NullValue, Tuple3<Double,Integer,Integer>>需要一个DataSet<Edge<Long, Tuple3<Double,Integer,Integer>>>作为边输入。这就是为什么您的temporalgraph2声明可以工作,而temporalgraph不能。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40007325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档