0
votes

I am trying to convert a JavaRDD<PageRankCase> class to a DataFrame so that I can later save it into a parquet file but the code execution stops at the createDataFrame function call, it gives null when I handle the exception. Here's my class.

public static class PageRanksCase implements Serializable{

    private String node;
    private Double importance; 


    public void setNode(String node) { this.node = node; }
    public void setImportance(Double importance) { this.importance = importance; }

    public String getNode(String node) { return this.node; }
    public Double getImportance(String node) { return this.importance; }
}

And this the code I am trying to run to convert the class into DataFrame.

try{
    JavaRDD<PageRanksCase> finalData = GetTopNNodes(pairedrdd);
    System.out.println("coming here");
    DataFrame finalFrame = Service.sqlCtx().createDataFrame(finalData,PageRanksCase.class);
    System.out.println("coming here too");
    finalFrame.write().parquet(rdfanalyzer.spark.Configuration.storage() + "sib200PageRank.parquet");
}
catch(Exception e)
{ 
  System.out.println(e.getMessage());  // gives null here.
}

It does print coming here but it's not printing coming here too and also not giving any errors. Here's how I convert my JavaPairRDD to JavaRDD.

public static JavaRDD<PageRanksCase> GetTopNNodes(JavaPairRDD<String,Double> pairedrdd){

    return pairedrdd.map(new Function<Tuple2<String,Double>, PageRanksCase>() {

        @Override
        public PageRanksCase call(Tuple2<String, Double> line) throws Exception {
            PageRanksCase pgrank  = new PageRanksCase();
            pgrank.setImportance(line._2);
            pgrank.setNode(line._1());
            return pgrank;
        }
    });
}

Anybody has any idea whats going on here ?

1

1 Answers

0
votes

I ended up re-implementing the code, using the example mentioned on Spark website.