After I load a json file with:
df = sqlContext.read().json(path);
I will get my DataFrame in Java Spark. I have for example the next DF:
id item1 item2 item3 ....
id1 0 3 4
id2 1 0 2
id3 3 3 0
...
I want to transform it in the most easy way to (probably of Object of the class Rating, id and item then to Integer by .hashCode())
id item ranking
id1 item1 0
id1 item2 3
id1 item3 4
....
id2 item1 1
id2 item2 0
id1 item1 2
...
PS Some first attempt to create the flatMap function:
void transformTracks() {
JavaRDD<Rating> = df.flatMap(new Function<Row, Rating>(){
public Rating call(Row r) {
for (String i : r) {
return Rating(1, 1, r.apply(Double.parseDouble(i)));
}
}
})
}
flatMapwill do the trick?