I can convert DataFrame to Dataset in Scala very easy:
case class Person(name:String, age:Long)
val df = ctx.read.json("/tmp/persons.json")
val ds = df.as[Person]
ds.printSchema
but in Java version I don't know how to convert Dataframe to Dataset? Any Idea?
my effort is:
DataFrame df = ctx.read().json(logFile);
Encoder<Person> encoder = new Encoder<>();
Dataset<Person> ds = new Dataset<Person>(ctx,df.logicalPlan(),encoder);
ds.printSchema();
but the compiler say:
Error:(23, 27) java: org.apache.spark.sql.Encoder is abstract; cannot be instantiated
Edited(Solution):
solution based on @Leet-Falcon answers:
DataFrame df = ctx.read().json(logFile);
Encoder<Person> encoder = Encoders.bean(Person.class);
Dataset<Person> ds = new Dataset<Person>(ctx, df.logicalPlan(), encoder);