I am trying to create Dataset<Row> object from JavaRDD<Tuple2<Row, Row>> object.
I am following the below steps,
- Convert
Java<Tuple2<Row,Row>>toJavaRDD<Row> - Use
toDataset()function ofsqlContextwith schema to convert into Dataset.
But, in first step I am not able to use Row.fromTuple() function like scala in code.
In second step, I am not able to convert using rowTag.
It's showing me below runtime error.
Error: java: cannot find symbol
symbol: method fromTuple(scala.Tuple2<org.apache.spark.sql.Row,org.apache.spark.sql.Row>)
location: interface org.apache.spark.sql.Row
I have tried to convert like below
ClassTag<Row> rowTag = scala.reflect.ClassTag$.MODULE$.apply(Row.class);
private Dataset<Row> joinResults(SparkSession session, RDD<Tuple2<Row, Row>> resultRDD) {
JavaRDD<Tuple2<Row, Row>> results = resultRDD.toJavaRDD();
JavaRDD<Row> ds = results.map(new Function<Tuple2<Row, Row>, Row>() {
@Override
public Row call(Tuple2<Row, Row> rowRowTuple2) throws Exception {
return Row.fromTuple(rowRowTuple2); // run time error
}
});
return session.sqlContext().createDataset(ds, rowTag); //gives error
}
Any help will be appreciated. I am using LuceneRDD Record Linkage, which gives me RDD back so I don't have the option to do operations directly on Dataset. I don't want to create schema/encoder every time because that will limit the use of linkage function. I am using Scala 2.11 and Spark 2.4.3 libs.