Dataset<Row> ratings = mlsc.sql("SELECT user,movie,rating FROM data");
JavaRDD<Row> rowJavaRDD = ratings.javaRDD();
JavaRDD<String[]> stringJavaRDD = rowJavaRDD.map(new Function<Row, String[]>() {
@Override
public String[] call(Row row) throws Exception {
String[] st = new String[3];
st[0] = row.getString(0);
st[1] = row.getString(1);
st[2] = row.getString(2);
return st;
}
});
JavaRDD<Rating> ratingJavaRDD = stringJavaRDD.map(new Function<String[], Rating>() {
@Override
public Rating call(String[] s) throws Exception {
int user = Integer.parseInt(s[0]);
int movie = Integer.parseInt(s[1]);
Double rating = Double.parseDouble(s[2]);
return new Rating(user,movie,rating);
}
});