2017-09-12 33 views
0

我有一个PairRDD像JavaPairRDD<String, Graph>其中Graph是使用调用从PairRDD管(),并传递一个Java对象到它

PairFunction<Row, String, Graph> pairFunction = new PairFunction<Row, String, Graph>() { 
     private static final long serialVersionUID = 1L; 

     public Tuple2<String, Graph> call(Row row) throws Exception { 
       Integer parameter = row.getAs("foo"); 
       String otherParameter = row.getAs("bar"); 
       Graph graph = new Graph(parameter, otherParameter); 

       String key = someKeyGenerator(); 
       return new Tuple2<String, Graph>(key, graph); 
     } 

}; 

现在我需要用myPairRdd.pipe('external.sh')运行外部程序,但Java对象我创建我认为Spark会通过stdin将Graph对象传递给external.sh

我需要访问external.sh中的Graph.parameterGraph.otherParameter

如何管理这种情况?

+0

这是我的外部程序从管道接收():'(62 br.com.cmabreu。图@ 622804e5)'。请注意键(62)以及我所创建的Graph对象:'br.com.cmabreu.Graph @ 622804e5'。 –

回答

0

发现它!

只需要重写我的POJO(Graph)的toString()方法以显示期望的属性!

在这种情况下:

@Override 
public String toString() { 
    return this.parameter + "," + this.otherParameter; 
} 

现在输出的是:

(62,foo,bar)

相关问题